| 92 | } |
| 93 | |
| 94 | void write_line(const std::string& line, |
| 95 | std::chrono::steady_clock::duration timeout) |
| 96 | { |
| 97 | std::string data = line + "\n"; |
| 98 | |
| 99 | // Start the asynchronous operation itself. The lambda that is used as a |
| 100 | // callback will update the error variable when the operation completes. |
| 101 | // The blocking_udp_client.cpp example shows how you can use std::bind |
| 102 | // rather than a lambda. |
| 103 | boost::system::error_code error; |
| 104 | boost::asio::async_write(socket_, boost::asio::buffer(data), |
| 105 | [&](const boost::system::error_code& result_error, |
| 106 | std::size_t /*result_n*/) |
| 107 | { |
| 108 | error = result_error; |
| 109 | }); |
| 110 | |
| 111 | // Run the operation until it completes, or until the timeout. |
| 112 | run(timeout); |
| 113 | |
| 114 | // Determine whether the read completed successfully. |
| 115 | if (error) |
| 116 | throw boost::system::system_error(error); |
| 117 | } |
| 118 | |
| 119 | private: |
| 120 | void run(std::chrono::steady_clock::duration timeout) |
no test coverage detected