Igor R ha scritto:
Just one last thing..
I've tried to to something like this (where signal_OnData is a signal):
void SerialPort::reading() { .... data available... //signal_OnData(); _io.post( boost::bind(&SerialPort::Post_OnData, this) ); }
void SerialPort::Post_OnData() { signal_OnData(); };
but the SerialPort::Post_OnData is not called, is this my design wrong?
I guess that your io_service is not running, so noone processes its queue. You have to call io_service::run function, it's kindof "message loop" of io_service: http://www.boost.org/doc/libs/1_38_0/doc/html/boost_asio/tutorial/tutdaytime...
Yes, I've called the _io.run() into my SerialPort constructor, but I think it end immediately because it has no work to do!! I'm reading docs and articles but one thing I can't understand... In my SerialPort class the reading method is called in a separate thread when I open the device and it doesn't return until I stop it: _thread.reset( new boost::thread( boost::bind(&SerialPort::reading, this)) ); using asio I think I have to 'bind' it to io_service::run so when I call _io.run() it call SerialPort::reading, but how?! Cheers, Daniele.