On Fri, Mar 23, 2018 at 11:42:02AM +0000, Thomas Quarendon via Boost-users wrote:
Yeah, it's a mess compared to Windows CancelSynchronousIO Quite. Yuck!
All I want is to be able to pass a timeout to the poll call that asio makes on my behalf! The operating system gives me what I want, I just can't get at it.
What if you use boost::asio's future support. Your BlockingConnection::start() method then looks like this: void BlockingConnection::start() { std::vector<char> b(1024); std::futurestd::size_t future = socket_.async_read_some( buffer(b), boost::asio::use_future); if (future.wait_for(std::chrono::milliseconds{1000}) == std::future_status::timeout) { std::cout << "BlockingConnection terminating " << std::endl; socket_.close(); } else { // get() may throw std::cout << "read bytes: " << future.get() << std::endl; } } This seems to be the closest to what you need. But it still requires that you not wait_for() from within the same io_service. So what you could do is have two io_services, one for all actual async operations with a thread blocked on run(), and a second io_service with as many threads as connections that you want to handle concurrently with sync reads. You would accept in the first io_service, and then .post(BlockingConnection::start) into the second one. Seems like this could work.