(ixwebsocket) Expose setHandshakeTimeout method
This commit is contained in:
		@@ -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
 | 
			
		||||
 
 | 
			
		||||
@@ -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
 | 
			
		||||
 
 | 
			
		||||
@@ -175,30 +175,29 @@ namespace ix
 | 
			
		||||
    //
 | 
			
		||||
    void WebSocketServer::makeBroadcastServer()
 | 
			
		||||
    {
 | 
			
		||||
        setOnClientMessageCallback(
 | 
			
		||||
            [this](std::shared_ptr<ConnectionState> connectionState,
 | 
			
		||||
                   WebSocket& webSocket,
 | 
			
		||||
                   const WebSocketMessagePtr& msg) {
 | 
			
		||||
                auto remoteIp = connectionState->getRemoteIp();
 | 
			
		||||
                if (msg->type == ix::WebSocketMessageType::Message)
 | 
			
		||||
        setOnClientMessageCallback([this](std::shared_ptr<ConnectionState> 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<double, std::milli> 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<double, std::milli> duration(500);
 | 
			
		||||
                            std::this_thread::sleep_for(duration);
 | 
			
		||||
                        } while (client->bufferedAmount() != 0);
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            });
 | 
			
		||||
            }
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    int WebSocketServer::listenAndStart()
 | 
			
		||||
 
 | 
			
		||||
@@ -6,4 +6,4 @@
 | 
			
		||||
 | 
			
		||||
#pragma once
 | 
			
		||||
 | 
			
		||||
#define IX_WEBSOCKET_VERSION "11.0.8"
 | 
			
		||||
#define IX_WEBSOCKET_VERSION "11.0.9"
 | 
			
		||||
 
 | 
			
		||||
@@ -33,11 +33,7 @@ TEST_CASE("dns", "[net]")
 | 
			
		||||
        auto dnsLookup = std::make_shared<DNSLookup>("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);
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -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(
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user