开发者

async_connect blocks io_service::run_one() in boost::asio

I'm trying to run following code:

some_sock.async_conne开发者_高级运维ct(...); // handle_connect() sets the 'condition' flag

boost::asio::deadline_timer t(ios, boost::posix_time::seconds(2));
while (t.expires_from_now() >= boost::posix_time::seconds(0))
{
  ios.run_one();
  if (condition) return;
}

Desirable behavior is return from run_one() after timer t is expired (after 2 seconds). Actually, run_one() blocks until SYN-ACK or RST is received. If the server is not responding, run_one() will block for a much longer timeout than 2 seconds.

What should I do to wait specified amount of time for connect doing some work in background?

Thanks.


use io_service::run and deadline_timer::async_wait as described in the async tcp client example.


Call run_one() for connect() in another thread. On timeout call some_sock.cancel(). (Read its documentation first).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜