88#include < streambuf>
99#include < string>
1010
11+ using websocketpp::lib::placeholders::_1;
12+ using websocketpp::lib::placeholders::_2;
13+ using websocketpp::lib::bind;
14+ using websocketpp::lib::error_code;
15+
1116/* *
1217 * The telemetry server accepts connections and sends a message every second to
1318 * each client containing an integer count. This example can be used as the
@@ -43,8 +48,6 @@ class telemetry_server {
4348 m_endpoint.init_asio ();
4449
4550 // Bind the handlers we are using
46- using websocketpp::lib::placeholders::_1;
47- using websocketpp::lib::bind;
4851 m_endpoint.set_open_handler (bind (&telemetry_server::on_open,this ,_1));
4952 m_endpoint.set_close_handler (bind (&telemetry_server::on_close,this ,_1));
5053 m_endpoint.set_http_handler (bind (&telemetry_server::on_http,this ,_1));
@@ -61,7 +64,7 @@ class telemetry_server {
6164 m_endpoint.listen (port);
6265
6366 // Start the server accept loop
64- m_endpoint.start_accept ();
67+ m_endpoint.start_accept (bind (&telemetry_server::on_end_accept, this ,_1,_2) );
6568
6669 // Set the initial timer to start telemetry
6770 set_timer ();
@@ -85,7 +88,7 @@ class telemetry_server {
8588 );
8689 }
8790
88- void on_timer (websocketpp::lib:: error_code const & ec) {
91+ void on_timer (error_code const & ec) {
8992 if (ec) {
9093 // there was an error, stop telemetry
9194 m_endpoint.get_alog ().write (websocketpp::log::alevel::app,
@@ -149,7 +152,7 @@ class telemetry_server {
149152 response.assign ((std::istreambuf_iterator<char >(file)),
150153 std::istreambuf_iterator<char >());
151154
152- con->set_body (response);
155+ con->set_body (std::move ( response) );
153156 con->set_status (websocketpp::http::status_code::ok);
154157 }
155158
@@ -160,6 +163,11 @@ class telemetry_server {
160163 void on_close (connection_hdl hdl) {
161164 m_connections.erase (hdl);
162165 }
166+
167+ void on_end_accept (error_code lib_ec, error_code trans_ec) {
168+ std::cout << " Accept loop ended "
169+ << lib_ec.message () << " /" << trans_ec.message () << std::endl;
170+ }
163171private:
164172 typedef std::set<connection_hdl,std::owner_less<connection_hdl>> con_list;
165173
0 commit comments