| 147 | } |
| 148 | |
| 149 | void 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 |
nothing calls this directly
no test coverage detected