(ixwebsocket) Expose setHandshakeTimeout method

This commit is contained in:
Benjamin Sergeant 2021-03-07 19:29:28 -08:00
parent 7c195219cd
commit f090c7659b
6 changed files with 37 additions and 33 deletions

View File

@ -2,6 +2,10 @@
All changes to this project will be documented in this file. 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 ## [11.0.8] - 2020-12-25
(ws) trim ws dependencies no more ixcrypto and ixcore deps (ws) trim ws dependencies no more ixcrypto and ixcore deps

View File

@ -263,6 +263,15 @@ webSocket.setMaxWaitBetweenReconnectionRetries(5 * 1000); // 5000ms = 5s
uint32_t m = webSocket.getMaxWaitBetweenReconnectionRetries(); 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 ## WebSocket server API
### Legacy api ### Legacy api

View File

@ -175,30 +175,29 @@ namespace ix
// //
void WebSocketServer::makeBroadcastServer() void WebSocketServer::makeBroadcastServer()
{ {
setOnClientMessageCallback( setOnClientMessageCallback([this](std::shared_ptr<ConnectionState> connectionState,
[this](std::shared_ptr<ConnectionState> connectionState, WebSocket& webSocket,
WebSocket& webSocket, const WebSocketMessagePtr& msg) {
const WebSocketMessagePtr& msg) { auto remoteIp = connectionState->getRemoteIp();
auto remoteIp = connectionState->getRemoteIp(); if (msg->type == ix::WebSocketMessageType::Message)
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 // Make sure the OS send buffer is flushed before moving on
do do
{ {
size_t bufferedAmount = client->bufferedAmount(); size_t bufferedAmount = client->bufferedAmount();
std::chrono::duration<double, std::milli> duration(500); std::chrono::duration<double, std::milli> duration(500);
std::this_thread::sleep_for(duration); std::this_thread::sleep_for(duration);
} while (client->bufferedAmount() != 0); } while (client->bufferedAmount() != 0);
}
} }
} }
}); }
});
} }
int WebSocketServer::listenAndStart() int WebSocketServer::listenAndStart()

View File

@ -6,4 +6,4 @@
#pragma once #pragma once
#define IX_WEBSOCKET_VERSION "11.0.8" #define IX_WEBSOCKET_VERSION "11.0.9"

View File

@ -33,11 +33,7 @@ TEST_CASE("dns", "[net]")
auto dnsLookup = std::make_shared<DNSLookup>("wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww", 80); auto dnsLookup = std::make_shared<DNSLookup>("wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww", 80);
std::string errMsg; std::string errMsg;
struct addrinfo* res = dnsLookup->resolve(errMsg, struct addrinfo* res = dnsLookup->resolve(errMsg, [] { return false; });
[]
{
return false;
});
std::cerr << "Error message: " << errMsg << std::endl; std::cerr << "Error message: " << errMsg << std::endl;
REQUIRE(res == nullptr); REQUIRE(res == nullptr);
} }
@ -48,11 +44,7 @@ TEST_CASE("dns", "[net]")
std::string errMsg; std::string errMsg;
// The callback returning true means we are requesting cancellation // The callback returning true means we are requesting cancellation
struct addrinfo* res = dnsLookup->resolve(errMsg, struct addrinfo* res = dnsLookup->resolve(errMsg, [] { return true; });
[]
{
return true;
});
std::cerr << "Error message: " << errMsg << std::endl; std::cerr << "Error message: " << errMsg << std::endl;
REQUIRE(res == nullptr); REQUIRE(res == nullptr);
} }

View File

@ -2378,9 +2378,9 @@ namespace ix
else else
{ {
std::string readyStateString = std::string readyStateString =
readyState == ReadyState::Connecting readyState == ReadyState::Connecting ? "Connecting"
? "Connecting" : readyState == ReadyState::Closing ? "Closing"
: readyState == ReadyState::Closing ? "Closing" : "Closed"; : "Closed";
size_t bufferedAmount = client->bufferedAmount(); size_t bufferedAmount = client->bufferedAmount();
spdlog::info( spdlog::info(