in src/TcpAdapterProxy.cpp [532:567]
void tcp_adapter_proxy::handle_web_socket_control_message(tcp_adapter_context &tac, boost::beast::websocket::frame_type ws_message_type, boost::beast::string_view payload)
{
#ifdef DEBUG
BOOST_LOG_SEV(log, debug) << "Control message recieved enum(close=0, ping=1, pong=2): " << static_cast<std::uint32_t>(ws_message_type);
#endif
boost::beast::websocket::ping_data pd{ payload };
long long now_millis = 0;
long long pong_millis = 0;
switch (ws_message_type)
{
BOOST_LOG_SEV(log, trace) << "handle_web_socket_control_message, message type: " << static_cast<std::uint32_t>(ws_message_type);
case boost::beast::websocket::frame_type::close:
BOOST_LOG_SEV(log, info) << "Web socket close received. Code: " << tac.wss->reason().code << "; Reason: " << tac.wss->reason().reason;
tcp_socket_reset_all(tac, std::bind(&tcp_adapter_proxy::web_socket_close_and_stop, this, std::ref(tac)));
break;
case boost::beast::websocket::frame_type::ping:
#ifdef DEBUG
BOOST_LOG_SEV(log, debug) << "Websocket ping recieved: " << pd;
#endif
tac.wss->async_pong(pd, [&](boost::system::error_code const &ec)
{
if (ec)
{
BOOST_LOG_SEV(log, warning) << "Pong reply failed to send to server " << ec.message();
}
});
break;
case boost::beast::websocket::frame_type::pong:
now_millis = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
pong_millis = boost::lexical_cast<decltype(now_millis)>(pd.data(), pd.length());
BOOST_LOG_SEV(log, trace) << "Pong reply latency: " << (now_millis - pong_millis) << " ms";
break;
default:
BOOST_LOG_SEV(log, warning) << "Received unknown control frame type(close=0, ping, pong): " << static_cast<std::uint32_t>(ws_message_type);
}
}