From 8ec515f2928dac44e8283a4a333eebda3f4d8292 Mon Sep 17 00:00:00 2001 From: Benjamin Sergeant Date: Tue, 17 Mar 2020 23:54:32 -0700 Subject: [PATCH] (ws) ws connect gains a new option to set the interval at which to send pings --- docs/CHANGELOG.md | 33 +++++++++++++++++++++++++++++++++ ws/ws.cpp | 7 ++++++- ws/ws.h | 3 ++- ws/ws_connect.cpp | 13 +++++++++---- 4 files changed, 50 insertions(+), 6 deletions(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index c20f49dd..35ccc337 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -1,6 +1,39 @@ # Changelog 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 + +``` +IXWebSocket$ ws connect --ping_interval 2 wss://echo.websocket.org +Type Ctrl-D to exit prompt... +Connecting to url: wss://echo.websocket.org +> ws_connect: connected +[2020-03-17 23:53:02.726] [info] Uri: / +[2020-03-17 23:53:02.726] [info] Headers: +[2020-03-17 23:53:02.727] [info] Connection: Upgrade +[2020-03-17 23:53:02.727] [info] Date: Wed, 18 Mar 2020 06:45:05 GMT +[2020-03-17 23:53:02.727] [info] Sec-WebSocket-Accept: 0gtqbxW0aVL/QI/ICpLFnRaiKgA= +[2020-03-17 23:53:02.727] [info] sec-websocket-extensions: +[2020-03-17 23:53:02.727] [info] Server: Kaazing Gateway +[2020-03-17 23:53:02.727] [info] Upgrade: websocket +[2020-03-17 23:53:04.894] [info] Received pong +[2020-03-17 23:53:06.859] [info] Received pong +[2020-03-17 23:53:08.881] [info] Received pong +[2020-03-17 23:53:10.848] [info] Received pong +[2020-03-17 23:53:12.898] [info] Received pong +[2020-03-17 23:53:14.865] [info] Received pong +[2020-03-17 23:53:16.890] [info] Received pong +[2020-03-17 23:53:18.853] [info] Received pong + +[2020-03-17 23:53:19.388] [info] +ws_connect: connection closed: code 1000 reason Normal closure + +[2020-03-17 23:53:19.502] [info] Received 208 bytes +[2020-03-17 23:53:19.502] [info] Sent 0 bytes +``` + ## [8.2.6] - 2020-03-16 (cobra to sentry bot + docker) default docker file uses mbedtls + ws cobra_to_sentry pass tls options to sentryClient. diff --git a/ws/ws.cpp b/ws/ws.cpp index 638e714c..d82cb016 100644 --- a/ws/ws.cpp +++ b/ws/ws.cpp @@ -112,6 +112,7 @@ int main(int argc, char** argv) int count = 1; uint32_t maxWaitBetweenReconnectionRetries; size_t maxQueueSize = 100; + int pingIntervalSecs = 30; auto addTLSOptions = [&tlsOptions, &verifyNone](CLI::App* app) { app->add_option( @@ -170,6 +171,9 @@ int main(int argc, char** argv) connectApp->add_option("--max_wait", maxWaitBetweenReconnectionRetries, "Max Wait Time between reconnection retries"); + connectApp->add_option("--ping_interval", + pingIntervalSecs, + "Interval between sending pings"); connectApp->add_option("--subprotocol", subprotocol, "Subprotocol"); addTLSOptions(connectApp); @@ -389,7 +393,8 @@ int main(int argc, char** argv) binaryMode, maxWaitBetweenReconnectionRetries, tlsOptions, - subprotocol); + subprotocol, + pingIntervalSecs); } else if (app.got_subcommand("chat")) { diff --git a/ws/ws.h b/ws/ws.h index 4b84a7c2..2758783a 100644 --- a/ws/ws.h +++ b/ws/ws.h @@ -50,7 +50,8 @@ namespace ix bool binaryMode, uint32_t maxWaitBetweenReconnectionRetries, const ix::SocketTLSOptions& tlsOptions, - const std::string& subprotocol); + const std::string& subprotocol, + int pingIntervalSecs); int ws_receive_main(const std::string& url, bool enablePerMessageDeflate, diff --git a/ws/ws_connect.cpp b/ws/ws_connect.cpp index 7598a669..a8d1caca 100644 --- a/ws/ws_connect.cpp +++ b/ws/ws_connect.cpp @@ -24,7 +24,8 @@ namespace ix bool binaryMode, uint32_t maxWaitBetweenReconnectionRetries, const ix::SocketTLSOptions& tlsOptions, - const std::string& subprotocol); + const std::string& subprotocol, + int pingIntervalSecs); void subscribe(const std::string& channel); void start(); @@ -61,7 +62,8 @@ namespace ix bool binaryMode, uint32_t maxWaitBetweenReconnectionRetries, const ix::SocketTLSOptions& tlsOptions, - const std::string& subprotocol) + const std::string& subprotocol, + int pingIntervalSecs) : _url(url) , _disablePerMessageDeflate(disablePerMessageDeflate) , _binaryMode(binaryMode) @@ -74,6 +76,7 @@ namespace ix } _webSocket.setMaxWaitBetweenReconnectionRetries(maxWaitBetweenReconnectionRetries); _webSocket.setTLSOptions(tlsOptions); + _webSocket.setPingInterval(pingIntervalSecs); _headers = parseHeaders(headers); @@ -223,7 +226,8 @@ namespace ix bool binaryMode, uint32_t maxWaitBetweenReconnectionRetries, const ix::SocketTLSOptions& tlsOptions, - const std::string& subprotocol) + const std::string& subprotocol, + int pingIntervalSecs) { std::cout << "Type Ctrl-D to exit prompt..." << std::endl; WebSocketConnect webSocketChat(url, @@ -233,7 +237,8 @@ namespace ix binaryMode, maxWaitBetweenReconnectionRetries, tlsOptions, - subprotocol); + subprotocol, + pingIntervalSecs); webSocketChat.start(); while (true)