From f090c7659b10a752d9e6578c7afe7d1857ebf55c Mon Sep 17 00:00:00 2001 From: Benjamin Sergeant Date: Sun, 7 Mar 2021 19:29:28 -0800 Subject: [PATCH] (ixwebsocket) Expose setHandshakeTimeout method --- docs/CHANGELOG.md | 4 ++++ docs/usage.md | 9 ++++++++ ixwebsocket/IXWebSocketServer.cpp | 37 +++++++++++++++---------------- ixwebsocket/IXWebSocketVersion.h | 2 +- test/IXDNSLookupTest.cpp | 12 ++-------- ws/ws.cpp | 6 ++--- 6 files changed, 37 insertions(+), 33 deletions(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index d4f66b5b..d542797c 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -2,6 +2,10 @@ All changes to this project will be documented in this file. +## [11.0.9] - 2021-03-07 + +(ixwebsocket) Expose setHandshakeTimeout method + ## [11.0.8] - 2020-12-25 (ws) trim ws dependencies no more ixcrypto and ixcore deps diff --git a/docs/usage.md b/docs/usage.md index 9c2f38b2..6c3ba7a2 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -263,6 +263,15 @@ webSocket.setMaxWaitBetweenReconnectionRetries(5 * 1000); // 5000ms = 5s uint32_t m = webSocket.getMaxWaitBetweenReconnectionRetries(); ``` +## Handshake timeout + +You can control how long to wait until timing out while waiting for the websocket handshake to be performed. + +``` +int handshakeTimeoutSecs = 1; +setHandshakeTimeout(handshakeTimeoutSecs); +``` + ## WebSocket server API ### Legacy api diff --git a/ixwebsocket/IXWebSocketServer.cpp b/ixwebsocket/IXWebSocketServer.cpp index 0d974547..cc94dadd 100644 --- a/ixwebsocket/IXWebSocketServer.cpp +++ b/ixwebsocket/IXWebSocketServer.cpp @@ -175,30 +175,29 @@ namespace ix // void WebSocketServer::makeBroadcastServer() { - setOnClientMessageCallback( - [this](std::shared_ptr connectionState, - WebSocket& webSocket, - const WebSocketMessagePtr& msg) { - auto remoteIp = connectionState->getRemoteIp(); - if (msg->type == ix::WebSocketMessageType::Message) + setOnClientMessageCallback([this](std::shared_ptr connectionState, + WebSocket& webSocket, + const WebSocketMessagePtr& msg) { + auto remoteIp = connectionState->getRemoteIp(); + if (msg->type == ix::WebSocketMessageType::Message) + { + for (auto&& client : getClients()) { - for (auto&& client : getClients()) + if (client.get() != &webSocket) { - if (client.get() != &webSocket) - { - client->send(msg->str, msg->binary); + client->send(msg->str, msg->binary); - // Make sure the OS send buffer is flushed before moving on - do - { - size_t bufferedAmount = client->bufferedAmount(); - std::chrono::duration duration(500); - std::this_thread::sleep_for(duration); - } while (client->bufferedAmount() != 0); - } + // Make sure the OS send buffer is flushed before moving on + do + { + size_t bufferedAmount = client->bufferedAmount(); + std::chrono::duration duration(500); + std::this_thread::sleep_for(duration); + } while (client->bufferedAmount() != 0); } } - }); + } + }); } int WebSocketServer::listenAndStart() diff --git a/ixwebsocket/IXWebSocketVersion.h b/ixwebsocket/IXWebSocketVersion.h index d7e88dbd..9eca590e 100644 --- a/ixwebsocket/IXWebSocketVersion.h +++ b/ixwebsocket/IXWebSocketVersion.h @@ -6,4 +6,4 @@ #pragma once -#define IX_WEBSOCKET_VERSION "11.0.8" +#define IX_WEBSOCKET_VERSION "11.0.9" diff --git a/test/IXDNSLookupTest.cpp b/test/IXDNSLookupTest.cpp index ca1180ee..a2405042 100644 --- a/test/IXDNSLookupTest.cpp +++ b/test/IXDNSLookupTest.cpp @@ -33,11 +33,7 @@ TEST_CASE("dns", "[net]") auto dnsLookup = std::make_shared("wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww", 80); std::string errMsg; - struct addrinfo* res = dnsLookup->resolve(errMsg, - [] - { - return false; - }); + struct addrinfo* res = dnsLookup->resolve(errMsg, [] { return false; }); std::cerr << "Error message: " << errMsg << std::endl; REQUIRE(res == nullptr); } @@ -48,11 +44,7 @@ TEST_CASE("dns", "[net]") std::string errMsg; // The callback returning true means we are requesting cancellation - struct addrinfo* res = dnsLookup->resolve(errMsg, - [] - { - return true; - }); + struct addrinfo* res = dnsLookup->resolve(errMsg, [] { return true; }); std::cerr << "Error message: " << errMsg << std::endl; REQUIRE(res == nullptr); } diff --git a/ws/ws.cpp b/ws/ws.cpp index d85b14f3..fc64a60c 100644 --- a/ws/ws.cpp +++ b/ws/ws.cpp @@ -2378,9 +2378,9 @@ namespace ix else { std::string readyStateString = - readyState == ReadyState::Connecting - ? "Connecting" - : readyState == ReadyState::Closing ? "Closing" : "Closed"; + readyState == ReadyState::Connecting ? "Connecting" + : readyState == ReadyState::Closing ? "Closing" + : "Closed"; size_t bufferedAmount = client->bufferedAmount(); spdlog::info(