A custom completion token that makes asynchronous operations behave as though they are blocking calls with a timeout.
| 35 | // A custom completion token that makes asynchronous operations behave as |
| 36 | // though they are blocking calls with a timeout. |
| 37 | struct close_after |
| 38 | { |
| 39 | close_after(std::chrono::steady_clock::duration t, tcp_socket& s) |
| 40 | : timeout_(t), socket_(s) |
| 41 | { |
| 42 | } |
| 43 | |
| 44 | // The maximum time to wait for an asynchronous operation to complete. |
| 45 | std::chrono::steady_clock::duration timeout_; |
| 46 | |
| 47 | // The socket to be closed if the operation does not complete in time. |
| 48 | tcp_socket& socket_; |
| 49 | }; |
| 50 | |
| 51 | namespace boost { |
| 52 | namespace asio { |