MCPcopy Create free account
hub / github.com/boostorg/beast / main

Function main

example/echo-op/echo_op.cpp:346–377  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

344};
345
346int 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}

Callers

nothing calls this directly

Calls 5

async_echoFunction · 0.85
openMethod · 0.80
set_optionMethod · 0.80
acceptMethod · 0.45
runMethod · 0.45

Tested by

no test coverage detected