diff --git a/Networking/WebSockets/c4WebSocket.cc b/Networking/WebSockets/c4WebSocket.cc index d9592738d..e61855fe4 100644 --- a/Networking/WebSockets/c4WebSocket.cc +++ b/Networking/WebSockets/c4WebSocket.cc @@ -134,9 +134,10 @@ namespace litecore::repl { catchAndWarn() return false; } - bool C4WebSocket::waitForTLSHandshake() { + bool C4WebSocket::waitForTLSHandshake(unsigned timeoutSecs) { unique_lock lock(_mutex); - _tlsHandshakeCondition.wait(lock, [this] { return _peerCertData != nullslice || _closed; }); + _tlsHandshakeCondition.wait_for(lock, chrono::seconds(timeoutSecs), + [this] { return _peerCertData != nullslice || _closed; }); return _peerCertData != nullslice && !_closed; } diff --git a/Networking/WebSockets/c4WebSocket.hh b/Networking/WebSockets/c4WebSocket.hh index ba99e4709..5651112d7 100644 --- a/Networking/WebSockets/c4WebSocket.hh +++ b/Networking/WebSockets/c4WebSocket.hh @@ -47,7 +47,7 @@ namespace litecore::repl { void closeWithException(); /** Blocks until the TLS handshake completes or the socket closes. Returns true on success. */ - [[nodiscard]] bool waitForTLSHandshake(); + [[nodiscard]] bool waitForTLSHandshake(unsigned timeoutSecs); // WebSocket public API: void connect() override;