mirror of
https://github.com/me-no-dev/ESPAsyncWebServer.git
synced 2025-07-29 18:27:34 +02:00
move AsyncWebSocket's WS_EVT_CONNECT callback out of AsyncWebSocketClient's constructor
- this is wrong place to call user code from an object constructor - it is wrong to call AsyncWebSocket's method from other's objects constructor - the callback is executed when new object is not yet linked to server's clients list Closes #176
This commit is contained in:
@ -287,7 +287,6 @@ AsyncWebSocketClient::AsyncWebSocketClient(AsyncWebServerRequest* request, Async
|
||||
_client->onTimeout([](void* r, AsyncClient* c, uint32_t time) { (void)c; ((AsyncWebSocketClient*)(r))->_onTimeout(time); }, this);
|
||||
_client->onData([](void* r, AsyncClient* c, void* buf, size_t len) { (void)c; ((AsyncWebSocketClient*)(r))->_onData(buf, len); }, this);
|
||||
_client->onPoll([](void* r, AsyncClient* c) { (void)c; ((AsyncWebSocketClient*)(r))->_onPoll(); }, this);
|
||||
_server->_handleEvent(this, WS_EVT_CONNECT, request, NULL, 0);
|
||||
delete request;
|
||||
memset(&_pinfo, 0, sizeof(_pinfo));
|
||||
}
|
||||
@ -781,6 +780,7 @@ void AsyncWebSocket::_handleEvent(AsyncWebSocketClient* client, AwsEventType typ
|
||||
|
||||
AsyncWebSocketClient* AsyncWebSocket::_newClient(AsyncWebServerRequest* request) {
|
||||
_clients.emplace_back(request, this);
|
||||
_handleEvent(&_clients.back(), WS_EVT_CONNECT, request, NULL, 0);
|
||||
return &_clients.back();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user