diff options
author | Thaddeus Crews <repiteo@outlook.com> | 2024-11-12 09:28:15 -0600 |
---|---|---|
committer | Thaddeus Crews <repiteo@outlook.com> | 2024-11-12 09:28:15 -0600 |
commit | caff0ff591ed63234474c46a6fd868661aa8ea01 (patch) | |
tree | 80fc742636ec06b781bb2271410bbb6850456314 /modules | |
parent | ab5a5395496751e09b2bc5100ff6352d0ee5f16c (diff) | |
parent | 6cdfc8c9fe1e785d11c56770004a3d58e4188d21 (diff) | |
download | redot-engine-caff0ff591ed63234474c46a6fd868661aa8ea01.tar.gz |
Merge pull request #97913 from Faless/fix/websocket_closing_transition
[WS] Detect disconnection due to protocol errors
Diffstat (limited to 'modules')
-rw-r--r-- | modules/websocket/wsl_peer.cpp | 37 |
1 files changed, 31 insertions, 6 deletions
diff --git a/modules/websocket/wsl_peer.cpp b/modules/websocket/wsl_peer.cpp index 5d3e8ee017..b624da09e8 100644 --- a/modules/websocket/wsl_peer.cpp +++ b/modules/websocket/wsl_peer.cpp @@ -716,12 +716,37 @@ void WSLPeer::poll() { close(-1); return; } - if (wslay_event_get_close_sent(wsl_ctx) && wslay_event_get_close_received(wsl_ctx)) { - // Clean close. - wslay_event_context_free(wsl_ctx); - wsl_ctx = nullptr; - close(-1); - return; + if (wslay_event_get_close_sent(wsl_ctx)) { + if (wslay_event_get_close_received(wsl_ctx)) { + // Clean close. + wslay_event_context_free(wsl_ctx); + wsl_ctx = nullptr; + close(-1); + return; + } else if (!wslay_event_get_read_enabled(wsl_ctx)) { + // Some protocol error caused wslay to stop processing incoming events, we'll never receive a close from the other peer. + close_code = wslay_event_get_status_code_sent(wsl_ctx); + switch (close_code) { + case WSLAY_CODE_MESSAGE_TOO_BIG: + close_reason = "Message too big"; + break; + case WSLAY_CODE_PROTOCOL_ERROR: + close_reason = "Protocol error"; + break; + case WSLAY_CODE_ABNORMAL_CLOSURE: + close_reason = "Abnormal closure"; + break; + case WSLAY_CODE_INVALID_FRAME_PAYLOAD_DATA: + close_reason = "Invalid frame payload data"; + break; + default: + close_reason = "Unknown"; + } + wslay_event_context_free(wsl_ctx); + wsl_ctx = nullptr; + close(-1); + return; + } } } } |