| 344 | }; |
| 345 | |
| 346 | int main(int argc, char** argv) |
| 347 | { |
| 348 | if(argc != 3) |
| 349 | { |
| 350 | std::cerr |
| 351 | << "Usage: echo-op <address> <port>\n" |
| 352 | << "Example:\n" |
| 353 | << " echo-op 0.0.0.0 8080\n"; |
| 354 | return EXIT_FAILURE; |
| 355 | } |
| 356 | |
| 357 | namespace net = boost::asio; |
| 358 | auto const address = net::ip::make_address(argv[1]); |
| 359 | auto const port = static_cast<unsigned short>(std::atoi(argv[2])); |
| 360 | |
| 361 | using endpoint_type = net::ip::tcp::endpoint; |
| 362 | |
| 363 | // Create a listening socket, accept a connection, perform |
| 364 | // the echo, and then shut everything down and exit. |
| 365 | net::io_context ioc; |
| 366 | net::ip::tcp::acceptor acceptor{ioc}; |
| 367 | endpoint_type ep(address, port); |
| 368 | acceptor.open(ep.protocol()); |
| 369 | acceptor.set_option(net::socket_base::reuse_address(true)); |
| 370 | acceptor.bind(ep); |
| 371 | acceptor.listen(); |
| 372 | auto sock = acceptor.accept(); |
| 373 | beast::flat_buffer buffer; |
| 374 | async_echo(sock, buffer, move_only_handler{}); |
| 375 | ioc.run(); |
| 376 | return EXIT_SUCCESS; |
| 377 | } |
nothing calls this directly
no test coverage detected