From 8754206c4a2da9cd1912d47f33e29d26392b75cd Mon Sep 17 00:00:00 2001 From: Per Larsson Date: Tue, 22 Feb 2022 09:21:33 +0100 Subject: Fixed crashing websocket test. --- zenhttp/websocketasio.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'zenhttp/websocketasio.cpp') diff --git a/zenhttp/websocketasio.cpp b/zenhttp/websocketasio.cpp index e9d065624..12b762b12 100644 --- a/zenhttp/websocketasio.cpp +++ b/zenhttp/websocketasio.cpp @@ -754,11 +754,7 @@ WsServer::CloseConnection(std::shared_ptr Connection, const std::e { if (Ec) { - ZEN_LOG_INFO(LogWebSocket, - "connection '{}' closed, ERROR '{}' error code '{}'", - Connection->Id().Value(), - Ec.message(), - Ec.value()); + ZEN_LOG_INFO(LogWebSocket, "connection '{}' closed, reason '{} ({})'", Connection->Id().Value(), Ec.message(), Ec.value()); } else { @@ -1304,6 +1300,13 @@ WsClient::ReadMessage() m_ReadBuffer, asio::transfer_at_least(1), [Self = AsShared()](const asio::error_code& Ec, std::size_t ByteCount) mutable { + const WebSocketState State = Self->State(); + + if (State == WebSocketState::kDisconnected) + { + return; + } + if (Ec) { ZEN_LOG_WARN(LogWsClient, "read message FAILED, reason '{}'", Ec.message()); @@ -1311,8 +1314,6 @@ WsClient::ReadMessage() return Self->Disconnect(); } - const WebSocketState State = Self->State(); - switch (State) { case WebSocketState::kHandshaking: -- cgit v1.2.3