MCPcopy Create free account
hub / github.com/boostorg/asio / read_line

Method read_line

example/cpp11/timeouts/blocking_tcp_client.cpp:65–92  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

63 }
64
65 std::string read_line(std::chrono::steady_clock::duration timeout)
66 {
67 // Start the asynchronous operation. The lambda that is used as a callback
68 // will update the error and n variables when the operation completes. The
69 // blocking_udp_client.cpp example shows how you can use std::bind rather
70 // than a lambda.
71 boost::system::error_code error;
72 std::size_t n = 0;
73 boost::asio::async_read_until(socket_,
74 boost::asio::dynamic_buffer(input_buffer_), '\n',
75 [&](const boost::system::error_code& result_error,
76 std::size_t result_n)
77 {
78 error = result_error;
79 n = result_n;
80 });
81
82 // Run the operation until it completes, or until the timeout.
83 run(timeout);
84
85 // Determine whether the read completed successfully.
86 if (error)
87 throw boost::system::system_error(error);
88
89 std::string line(input_buffer_.substr(0, n - 1));
90 input_buffer_.erase(0, n);
91 return line;
92 }
93
94 void write_line(const std::string& line,
95 std::chrono::steady_clock::duration timeout)

Callers 1

mainFunction · 0.45

Calls 2

async_read_untilFunction · 0.85
eraseMethod · 0.80

Tested by

no test coverage detected