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

Method server

example/cpp11/serialization/server.cpp:27–61  ·  view source on GitHub ↗

Constructor opens the acceptor and starts waiting for the first incoming connection.

Source from the content-addressed store, hash-verified

25 /// Constructor opens the acceptor and starts waiting for the first incoming
26 /// connection.
27 server(boost::asio::io_context& io_context, unsigned short port)
28 : acceptor_(io_context,
29 boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), port))
30 {
31 // Create the data to be sent to each client.
32 stock s;
33 s.code = "ABC";
34 s.name = "A Big Company";
35 s.open_price = 4.56;
36 s.high_price = 5.12;
37 s.low_price = 4.33;
38 s.last_price = 4.98;
39 s.buy_price = 4.96;
40 s.buy_quantity = 1000;
41 s.sell_price = 4.99;
42 s.sell_quantity = 2000;
43 stocks_.push_back(s);
44 s.code = "DEF";
45 s.name = "Developer Entertainment Firm";
46 s.open_price = 20.24;
47 s.high_price = 22.88;
48 s.low_price = 19.50;
49 s.last_price = 19.76;
50 s.buy_price = 19.72;
51 s.buy_quantity = 34000;
52 s.sell_price = 19.85;
53 s.sell_quantity = 45000;
54 stocks_.push_back(s);
55
56 // Start an accept operation for a new connection.
57 connection_ptr new_conn(new connection(acceptor_.get_executor()));
58 acceptor_.async_accept(new_conn->socket(),
59 std::bind(&server::handle_accept, this,
60 boost::asio::placeholders::error, new_conn));
61 }
62
63 /// Handle completion of a accept operation.
64 void handle_accept(const boost::system::error_code& e, connection_ptr conn)

Callers

nothing calls this directly

Calls 4

endpointClass · 0.50
bindFunction · 0.50
get_executorMethod · 0.45
async_acceptMethod · 0.45

Tested by

no test coverage detected