Skip to content

Commit 8bf0526

Browse files
committed
Implemented _handleEvent copilot review suggestion
1 parent 50f1e28 commit 8bf0526

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

src/AsyncWebSocket.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,6 @@ AsyncWebSocketClient::~AsyncWebSocketClient() {
301301
_messageQueue.clear();
302302
_controlQueue.clear();
303303
}
304-
_server->_handleEvent(this, WS_EVT_DISCONNECT, NULL, NULL, 0);
305304
}
306305

307306
void AsyncWebSocketClient::_clearQueue() {
@@ -996,10 +995,12 @@ AsyncWebSocketClient *AsyncWebSocket::_newClient(AsyncWebServerRequest *request)
996995
}
997996

998997
void AsyncWebSocket::_handleDisconnect(AsyncWebSocketClient *client) {
999-
(void)client;
1000998
// Defer removal to cleanupClients(). Disconnect callbacks can fire while
1001999
// iterating _clients for broadcast sends, and erasing here invalidates the
1002-
// active iterator in the caller.
1000+
// active iterator in the caller. However, emit the disconnect event now so
1001+
// applications observe the disconnect at the time it happens even though the
1002+
// client object remains in _clients until cleanup.
1003+
_handleEvent(client, WS_EVT_DISCONNECT, NULL, NULL, 0);
10031004
}
10041005

10051006
bool AsyncWebSocket::availableForWriteAll() {

0 commit comments

Comments
 (0)