|
Boost Users : |
Subject: Re: [Boost-users] Suggestion about using Signals2
From: Igor R (boost.lists_at_[hidden])
Date: 2009-03-21 14:52:20
> You mean using asio::io_service::post instead of signals or using asio::serial_port instead of my serial classes?
No I just mean using asio::io_service as a functor queue processor,
but if you use asio you definitely can benefit from its serial_port
class as well.
> If you have a minimal code snippet I will grateful!
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);
}
};
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