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

Method do_read_input

example/cpp11/chat/posix_chat_client.cpp:105–133  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

103 }
104
105 void do_read_input()
106 {
107 // Read a line of input entered by the user.
108 boost::asio::async_read_until(input_, input_buffer_, '\n',
109 [this](boost::system::error_code ec, std::size_t length)
110 {
111 if (!ec)
112 {
113 // Write the message (minus the newline) to the server.
114 write_msg_.body_length(length - 1);
115 input_buffer_.sgetn(write_msg_.body(), length - 1);
116 input_buffer_.consume(1); // Remove newline from input.
117 write_msg_.encode_header();
118 do_write_message();
119 }
120 else if (ec == boost::asio::error::not_found)
121 {
122 // Didn't get a newline. Send whatever we have.
123 write_msg_.body_length(input_buffer_.size());
124 input_buffer_.sgetn(write_msg_.body(), input_buffer_.size());
125 write_msg_.encode_header();
126 do_write_message();
127 }
128 else
129 {
130 close();
131 }
132 });
133 }
134
135 void do_write_message()
136 {

Callers

nothing calls this directly

Calls 7

async_read_untilFunction · 0.85
body_lengthMethod · 0.80
bodyMethod · 0.80
encode_headerMethod · 0.80
closeFunction · 0.50
consumeMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected