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

I am trying to run the following code:

some_sock.async_connect(...); // 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;
}

The desired behavior is to return from run_one () after timer t expires (after 2 seconds). In fact, run_one () blocks until a SYN-ACK or RST is received. If the server does not respond, run_one () will block a much longer timeout than 2 seconds.

What should I do to wait a certain amount of time for a connection doing some work in the background?

Thank.

+3
source share
2 answers

use io_service::runand deadline_timer::async_waitas described in the async tcp example .

+4

run_one() connect() . - some_sock.cancel(). ( ).

0

Source: https://habr.com/ru/post/1773141/


All Articles