Boost Users :
Subject: Re: [Boost-users] Suggestion about using Signals2
From: Igor R (boost.lists_at_[hidden])
Date: 2009-03-23 05:32:30
> is there a reason to create the io_service outside the class?
> Can I create an instance of it directly into the connection object?
Yes, you can. But usually you don't want to create io_service for
every connection or for every "active object" (you can use a single
io_service for all these objects or use io_service-per-cpu strategy -
see asio examples for details), that's why that you might want to
manage io_service(s) creation outside these objects.
> In your example you use io_.post() into the send method, why you don't use it also in the data_received?
Well, I meant that it's the handler of one of the asio standard async.
read methods, like this:
class connection : ...
// always executed in io_service thread(s)
But if you use some other i/o object to communicate with socket/serial
port, and utilize io_service just to process functors asyncronously,
and you wish to notify connection user from io_service thread - then
you can use the same technique there. It's just matter of your design.
Anyway, I recommend you to look at the asio tutorial and examples, to
find out some common usage scenarios and design proposals.
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net