From d6f534de062092485a33a1e3865912080e2e4a6c Mon Sep 17 00:00:00 2001 From: Benjamin Sergeant Date: Wed, 18 Mar 2020 00:01:57 -0700 Subject: [PATCH] (ws) ws echo_server gains a new option (-p) to disable responding to pings with pongs --- docs/CHANGELOG.md | 1 + ixwebsocket/IXWebSocketVersion.h | 2 +- ws/ws.cpp | 3 ++- ws/ws.h | 3 ++- ws/ws_echo_server.cpp | 9 ++++++++- 5 files changed, 14 insertions(+), 4 deletions(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 35ccc337..5c83799a 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -4,6 +4,7 @@ All changes to this project will be documented in this file. ## [8.2.7] - 2020-03-17 (ws) ws connect gains a new option to set the interval at which to send pings +(ws) ws echo_server gains a new option (-p) to disable responding to pings with pongs ``` IXWebSocket$ ws connect --ping_interval 2 wss://echo.websocket.org diff --git a/ixwebsocket/IXWebSocketVersion.h b/ixwebsocket/IXWebSocketVersion.h index 1fefa1ba..8b91302f 100644 --- a/ixwebsocket/IXWebSocketVersion.h +++ b/ixwebsocket/IXWebSocketVersion.h @@ -6,4 +6,4 @@ #pragma once -#define IX_WEBSOCKET_VERSION "8.2.6" +#define IX_WEBSOCKET_VERSION "8.2.7" diff --git a/ws/ws.cpp b/ws/ws.cpp index d82cb016..d1825a11 100644 --- a/ws/ws.cpp +++ b/ws/ws.cpp @@ -187,6 +187,7 @@ int main(int argc, char** argv) echoServerApp->add_flag("-g", greetings, "Verbose"); echoServerApp->add_flag("-6", ipv6, "IpV6"); echoServerApp->add_flag("-x", disablePerMessageDeflate, "Disable per message deflate"); + echoServerApp->add_flag("-p", disablePong, "Disable sending PONG in response to PING"); addTLSOptions(echoServerApp); CLI::App* broadcastServerApp = app.add_subcommand("broadcast_server", "Broadcasting server"); @@ -403,7 +404,7 @@ int main(int argc, char** argv) else if (app.got_subcommand("echo_server")) { ret = ix::ws_echo_server_main( - port, greetings, hostname, tlsOptions, ipv6, disablePerMessageDeflate); + port, greetings, hostname, tlsOptions, ipv6, disablePerMessageDeflate, disablePong); } else if (app.got_subcommand("broadcast_server")) { diff --git a/ws/ws.h b/ws/ws.h index 2758783a..2c074ea7 100644 --- a/ws/ws.h +++ b/ws/ws.h @@ -32,7 +32,8 @@ namespace ix const std::string& hostname, const ix::SocketTLSOptions& tlsOptions, bool ipv6, - bool disablePerMessageDeflate); + bool disablePerMessageDeflate, + bool disablePong); int ws_broadcast_server_main(int port, const std::string& hostname, diff --git a/ws/ws_echo_server.cpp b/ws/ws_echo_server.cpp index 37bb87fc..18852fc9 100644 --- a/ws/ws_echo_server.cpp +++ b/ws/ws_echo_server.cpp @@ -16,7 +16,8 @@ namespace ix const std::string& hostname, const ix::SocketTLSOptions& tlsOptions, bool ipv6, - bool disablePerMessageDeflate) + bool disablePerMessageDeflate, + bool disablePong) { spdlog::info("Listening on {}:{}", hostname, port); @@ -35,6 +36,12 @@ namespace ix server.disablePerMessageDeflate(); } + if (disablePong) + { + spdlog::info("Disable responding to PING messages with PONG"); + server.disablePong(); + } + server.setOnConnectionCallback( [greetings](std::shared_ptr webSocket, std::shared_ptr connectionState) {