| 70 | |
| 71 | private: |
| 72 | void run(std::chrono::steady_clock::duration timeout) |
| 73 | { |
| 74 | // Restart the io_context, as it may have been left in the "stopped" state |
| 75 | // by a previous operation. |
| 76 | io_context_.restart(); |
| 77 | |
| 78 | // Block until the asynchronous operation has completed, or timed out. If |
| 79 | // the pending asynchronous operation is a composed operation, the deadline |
| 80 | // applies to the entire operation, rather than individual operations on |
| 81 | // the socket. |
| 82 | io_context_.run_for(timeout); |
| 83 | |
| 84 | // If the asynchronous operation completed successfully then the io_context |
| 85 | // would have been stopped due to running out of work. If it was not |
| 86 | // stopped, then the io_context::run_for call must have timed out. |
| 87 | if (!io_context_.stopped()) |
| 88 | { |
| 89 | // Cancel the outstanding asynchronous operation. |
| 90 | socket_.cancel(); |
| 91 | |
| 92 | // Run the io_context again until the operation completes. |
| 93 | io_context_.run(); |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | static void handle_receive( |
| 98 | const boost::system::error_code& error, std::size_t length, |