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

Function test_sync_operations

test/buffered_stream.cpp:149–220  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

147}
148
149void test_sync_operations()
150{
151 using namespace std; // For memcmp.
152
153 boost::asio::io_context io_context;
154
155 boost::asio::ip::tcp::acceptor acceptor(io_context,
156 boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), 0));
157 boost::asio::ip::tcp::endpoint server_endpoint = acceptor.local_endpoint();
158 server_endpoint.address(boost::asio::ip::address_v4::loopback());
159
160 stream_type client_socket(io_context);
161 client_socket.lowest_layer().connect(server_endpoint);
162
163 stream_type server_socket(io_context);
164 acceptor.accept(server_socket.lowest_layer());
165
166 const char write_data[]
167 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
168 const boost::asio::const_buffer write_buf = boost::asio::buffer(write_data);
169
170 std::size_t bytes_written = 0;
171 while (bytes_written < sizeof(write_data))
172 {
173 bytes_written += client_socket.write_some(
174 boost::asio::buffer(write_buf + bytes_written));
175 client_socket.flush();
176 }
177
178 char read_data[sizeof(write_data)];
179 const boost::asio::mutable_buffer read_buf = boost::asio::buffer(read_data);
180
181 std::size_t bytes_read = 0;
182 while (bytes_read < sizeof(read_data))
183 {
184 bytes_read += server_socket.read_some(
185 boost::asio::buffer(read_buf + bytes_read));
186 }
187
188 BOOST_ASIO_CHECK(bytes_written == sizeof(write_data));
189 BOOST_ASIO_CHECK(bytes_read == sizeof(read_data));
190 BOOST_ASIO_CHECK(memcmp(write_data, read_data, sizeof(write_data)) == 0);
191
192 bytes_written = 0;
193 while (bytes_written < sizeof(write_data))
194 {
195 bytes_written += server_socket.write_some(
196 boost::asio::buffer(write_buf + bytes_written));
197 server_socket.flush();
198 }
199
200 bytes_read = 0;
201 while (bytes_read < sizeof(read_data))
202 {
203 bytes_read += client_socket.read_some(
204 boost::asio::buffer(read_buf + bytes_read));
205 }
206

Callers

nothing calls this directly

Calls 10

bufferFunction · 0.85
flushMethod · 0.80
endpointClass · 0.50
local_endpointMethod · 0.45
addressMethod · 0.45
connectMethod · 0.45
acceptMethod · 0.45
write_someMethod · 0.45
read_someMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected