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

Method server

example/cpp11/http/server3/server.cpp:21–49  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 8

addMethod · 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