Boost logo

Boost Users :

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


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/tutdaytime3.html

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.


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