|
Boost Users : |
Subject: Re: [Boost-users] Suggestion about using Signals2
From: Daniele Barzotti (daniele.barzotti_at_[hidden])
Date: 2009-03-23 03:29:22
Igor R ha scritto:
>
> If you want to see a working code with asio, you can refer to one the
> asio examples, but in general I mean the following scheme
> (pseudo-code!):
>
> // 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)
> {}
> 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
> }
> };
>
> // listens to the connection;
> class data_receiver
> {
> void data_received(data_type data)
> {
> doSomething();
> connection->send(somethingElse);
> }
> };
Thanks a lot for your suggestions, Igor!!
Cheers,
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