--------------------------------------------------------------
typedef boost::shared_ptr<boost::asio::io_service::work> io_work_ptr;
// Main io_service
static boost::asio::io_service io_service;
static boost::scoped_ptr<boost::thread> io_service_thread;
static boost::asio::io_service::work* p_work;
static bool thread_started;
bool CreateMainThread()
{
if (!thread_started) {
try {
// create the work object on the heap
p_work = new boost::asio::io_service::work(io_service);
// run the IO service as a separate thread:
io_service_thread.reset (
new boost::thread (
boost::bind (
&boost::asio::io_service::run, &io_service
)
)
);
thread_started = !thread_started;
return true;
} catch (boost::thread_resource_error e) {
// Failed to create the new thread
return false;
}
}
}
--------------------------------------------------------------
WaveStream::WaveStream() : rx_timer_(io_service)
{
};
WaveStream::Test()
{
//Start a new timer or renew it
rx_timer_.expires_from_now( boost::posix_time::milliseconds(500) );
// We managed to cancel the timer. Start new asynchronous wait.
rx_timer_.async_wait(
boost::bind(&WaveStream::handle_timeout, this, _1)
);
}
void WaveStream::handle_timeout(const boost::system::error_code& error)
{
....
}
--------------------------------------------------------------
The timer callback is never called.
Is there a way to know if the io_service is runing?
Daniele.
_______________________________________________
Boost-users mailing list
Boost...@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users
// We managed to cancel the timer. Start new asynchronous wait.
rx_timer_.async_wait(
boost::bind(&WaveStream::handle_timeout, this, _1)
);
}
void WaveStream::handle_timeout(const boost::system::error_code& error)
{
....
}
--------------------------------------------------------------
The timer callback is never called.
Is there a way to know if the io_service is runing?
Daniele.
_______________________________________________
Boost-users mailing list
Boost...@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users
I've change the code in this way:
> --------------------------------------------------------------
> typedef boost::shared_ptr<boost::asio::io_service::work> io_work_ptr;
>
> // Main io_service
> static boost::asio::io_service io_service;
> static boost::asio::io_service::work* p_work;
The io_service::work now is stored into a shared_ptr:
static io_work_ptr p_work;
so I'm pretty sure it is running.
> bool CreateMainThread()
> {
> if (!thread_started) {
> try {
> // create the work object on the heap
> p_work = new boost::asio::io_service::work(io_service);
p_work.reset( new boost::asio::io_service::work(io_service) );
--------------------------------------------------------------
WaveStream::WaveStream() : rx_timer_(io_service)
{
};
WaveStream::Test()
{
io_service.reset();
//Start a new timer or renew it
rx_timer_.expires_from_now( boost::posix_time::milliseconds(500) );
//Start new asynchronous wait.
rx_timer_.async_wait(
boost::bind(&WaveStream::handle_timeout, this, _1)
);
}
void WaveStream::handle_timeout(const boost::system::error_code& error)
{
....
}
--------------------------------------------------------------
I don't know why the handler is not called!