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

Method handle_control_request_timer

example/cpp11/porthopper/server.cpp:84–116  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

82 }
83
84 void handle_control_request_timer(tcp_socket_ptr socket,
85 control_request_ptr request, timer_ptr /*delay_timer*/)
86 {
87 // Determine what address this client is connected from, since
88 // subscriptions must be stored on the server as a complete endpoint, not
89 // just a port. We use the non-throwing overload of remote_endpoint() since
90 // it may fail if the socket is no longer connected.
91 boost::system::error_code ec;
92 tcp::endpoint remote_endpoint = socket->remote_endpoint(ec);
93 if (!ec)
94 {
95 // Remove old port subscription, if any.
96 if (unsigned short old_port = request->old_port())
97 {
98 udp::endpoint old_endpoint(remote_endpoint.address(), old_port);
99 subscribers_.erase(old_endpoint);
100 std::cout << "Removing subscription " << old_endpoint << std::endl;
101 }
102
103 // Add new port subscription, if any.
104 if (unsigned short new_port = request->new_port())
105 {
106 udp::endpoint new_endpoint(remote_endpoint.address(), new_port);
107 subscribers_.insert(new_endpoint);
108 std::cout << "Adding subscription " << new_endpoint << std::endl;
109 }
110 }
111
112 // Wait for next control request on this connection.
113 boost::asio::async_read(*socket, request->to_buffers(),
114 std::bind(&server::handle_control_request, this,
115 boost::asio::placeholders::error, socket, request));
116 }
117
118 // Every time the timer fires we will generate a new frame and send it to all
119 // subscribers.

Callers

nothing calls this directly

Calls 9

async_readFunction · 0.85
old_portMethod · 0.80
eraseMethod · 0.80
new_portMethod · 0.80
insertMethod · 0.80
bindFunction · 0.50
remote_endpointMethod · 0.45
addressMethod · 0.45
to_buffersMethod · 0.45

Tested by

no test coverage detected