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

Method server

example/cpp11/http/server2/server.cpp:19–47  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

17namespace server2 {
18
19server::server(const std::string& address, const std::string& port,
20 const std::string& doc_root, std::size_t io_context_pool_size)
21 : io_context_pool_(io_context_pool_size),
22 signals_(io_context_pool_.get_io_context()),
23 acceptor_(io_context_pool_.get_io_context()),
24 request_handler_(doc_root)
25{
26 // Register to handle the signals that indicate when the server should exit.
27 // It is safe to register for the same signal multiple times in a program,
28 // provided all registration for the specified signal is made through Asio.
29 signals_.add(SIGINT);
30 signals_.add(SIGTERM);
31#if defined(SIGQUIT)
32 signals_.add(SIGQUIT);
33#endif // defined(SIGQUIT)
34
35 do_await_stop();
36
37 // Open the acceptor with the option to reuse the address (i.e. SO_REUSEADDR).
38 boost::asio::ip::tcp::resolver resolver(acceptor_.get_executor());
39 boost::asio::ip::tcp::endpoint endpoint =
40 *resolver.resolve(address, port).begin();
41 acceptor_.open(endpoint.protocol());
42 acceptor_.set_option(boost::asio::ip::tcp::acceptor::reuse_address(true));
43 acceptor_.bind(endpoint);
44 acceptor_.listen();
45
46 do_accept();
47}
48
49void server::run()
50{

Callers

nothing calls this directly

Calls 9

addMethod · 0.45
get_executorMethod · 0.45
beginMethod · 0.45
resolveMethod · 0.45
openMethod · 0.45
protocolMethod · 0.45
set_optionMethod · 0.45
bindMethod · 0.45
listenMethod · 0.45

Tested by

no test coverage detected