Hello Andrea,
"Andrea Bartoli"
Use an asio::deadline_timer
Example:
asio::io_service m_ioService; asio::deadline_timer * m_timer; m_timer = new asio::deadline_timer(m_ioService);
m_timer->expires_from_now( boost::posix_time::seconds(t) ); m_timer->async_wait( boost::bind(&Foo:handle_timeout, this, asio::placeholders::error) ); asio::async_read( *m_socket, asio::buffer( m_msg.header(), m_msg.header_length() ), boost::bind(&Foo::handle_read_header, this, asio::placeholders::error) );
Thanks for your response. Still, it's not clear to me how to use it. In your example it seems that read operation and timeout are two independent things. How do I make sure only one of these two fires? Is it possile to cancel read operation once timout has been recieved? Thanks, Arkadiy