Boost logo

Boost Users :

Subject: Re: [Boost-users] Suggestion about using Signals2
From: Daniele Barzotti (daniele.barzotti_at_[hidden])
Date: 2009-03-23 04:36:04


Igor R ha scritto:
>
> // encapsulates yours or asio i/o object, like socket, serial_port etc.
> class connection : public boost::enable_shared_from_this<connection>
> {
> public:
> connection(boost::asio::io_service &io) : io_(io)
> {}

Hi Igor,

is there a reason to create the io_service outside the class?
Can I create an instance of it directly into the connection object?

> public:
> void send(data_type data)
> {
> // since send() might be called from a client thread, do not
> process the data here,
> // just post it to the io_ thread(s), where the data will be
> delivered to the socket/port
> io_.post(&connection::do_send, shared_from_this(), data);
> }
> private:
> // this method is always called within io_ thread(s)
> void data_received()
> {
> //issue the signal
> }
> void do_send(data_type data)
> {
> // send the data
> }
> };

In your example you use io_.post() into the send method, why you don't
use it also in the data_received?

Thanks!
Daniele.


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