Skip to content

Commit

Permalink
added debug logs for issue #172 (#172)
Browse files Browse the repository at this point in the history
  • Loading branch information
mathieucarbou committed Dec 19, 2024
1 parent 7f0154c commit 4cdb84d
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 5 deletions.
6 changes: 6 additions & 0 deletions examples/SimpleServer/SimpleServer.ino
Original file line number Diff line number Diff line change
Expand Up @@ -766,6 +766,8 @@ uint32_t deltaSSE = 10;
uint32_t lastWS = 0;
uint32_t deltaWS = 100;

uint32_t lastHeap = 0;

void loop() {
uint32_t now = millis();
if (now - lastSSE >= deltaSSE) {
Expand All @@ -779,4 +781,8 @@ void loop() {
// }
lastWS = millis();
}
if(now - lastHeap >= 2000) {
Serial.printf("Free heap: %" PRIu32 "\n", ESP.getFreeHeap());
lastHeap = now;
}
}
7 changes: 6 additions & 1 deletion src/AsyncEventSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,12 @@ AsyncEventSourceClient::AsyncEventSourceClient(AsyncWebServerRequest* request, A
_client->onPoll([](void* r, AsyncClient* c) { (void)c; static_cast<AsyncEventSourceClient*>(r)->_onPoll(); }, this);
_client->onData(NULL, NULL);
_client->onTimeout([this](void* r, AsyncClient* c __attribute__((unused)), uint32_t time) { static_cast<AsyncEventSourceClient*>(r)->_onTimeout(time); }, this);
_client->onDisconnect([this](void* r, AsyncClient* c) { static_cast<AsyncEventSourceClient*>(r)->_onDisconnect(); delete c; }, this);
_client->onDisconnect([this](void* r, AsyncClient* c) {
static_cast<AsyncEventSourceClient*>(r)->_onDisconnect();
log_e("Delete client pointer: %p", c);
delete c;
},
this);

_server->_addClient(this);
delete request;
Expand Down
7 changes: 6 additions & 1 deletion src/AsyncWebSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,12 @@ AsyncWebSocketClient::AsyncWebSocketClient(AsyncWebServerRequest* request, Async
_client->setRxTimeout(0);
_client->onError([](void* r, AsyncClient* c, int8_t error) { (void)c; ((AsyncWebSocketClient*)(r))->_onError(error); }, this);
_client->onAck([](void* r, AsyncClient* c, size_t len, uint32_t time) { (void)c; ((AsyncWebSocketClient*)(r))->_onAck(len, time); }, this);
_client->onDisconnect([](void* r, AsyncClient* c) { ((AsyncWebSocketClient*)(r))->_onDisconnect(); delete c; }, this);
_client->onDisconnect([](void* r, AsyncClient* c) {
((AsyncWebSocketClient*)(r))->_onDisconnect();
log_e("Delete client pointer: %p", c);
delete c;
},
this);
_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);
Expand Down
22 changes: 19 additions & 3 deletions src/WebRequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,13 @@ AsyncWebServerRequest::AsyncWebServerRequest(AsyncWebServer* s, AsyncClient* c)
: _client(c), _server(s), _handler(NULL), _response(NULL), _temp(), _parseState(PARSE_REQ_START), _version(0), _method(HTTP_ANY), _url(), _host(), _contentType(), _boundary(), _authorization(), _reqconntype(RCT_HTTP), _authMethod(AsyncAuthType::AUTH_NONE), _isMultipart(false), _isPlainPost(false), _expectingContinue(false), _contentLength(0), _parsedLength(0), _multiParseState(0), _boundaryPosition(0), _itemStartIndex(0), _itemSize(0), _itemName(), _itemFilename(), _itemType(), _itemValue(), _itemBuffer(0), _itemBufferIndex(0), _itemIsFile(false), _tempObject(NULL) {
c->onError([](void* r, AsyncClient* c, int8_t error) { (void)c; AsyncWebServerRequest *req = (AsyncWebServerRequest*)r; req->_onError(error); }, this);
c->onAck([](void* r, AsyncClient* c, size_t len, uint32_t time) { (void)c; AsyncWebServerRequest *req = (AsyncWebServerRequest*)r; req->_onAck(len, time); }, this);
c->onDisconnect([](void* r, AsyncClient* c) { AsyncWebServerRequest *req = (AsyncWebServerRequest*)r; req->_onDisconnect(); delete c; }, this);
c->onDisconnect([](void* r, AsyncClient* c) {
AsyncWebServerRequest* req = (AsyncWebServerRequest*)r;
req->_onDisconnect();
log_e("Delete client pointer: %p", c);
delete c;
},
this);
c->onTimeout([](void* r, AsyncClient* c, uint32_t time) { (void)c; AsyncWebServerRequest *req = (AsyncWebServerRequest*)r; req->_onTimeout(time); }, this);
c->onData([](void* r, AsyncClient* c, void* buf, size_t len) { (void)c; AsyncWebServerRequest *req = (AsyncWebServerRequest*)r; req->_onData(buf, len); }, this);
c->onPoll([](void* r, AsyncClient* c) { (void)c; AsyncWebServerRequest *req = ( AsyncWebServerRequest*)r; req->_onPoll(); }, this);
Expand Down Expand Up @@ -67,14 +73,18 @@ AsyncWebServerRequest::~AsyncWebServerRequest() {
}

void AsyncWebServerRequest::_onData(void* buf, size_t len) {
log_d("Request pointer: %p", this);
log_d("Free Heap: %u", ESP.getFreeHeap());

// SSL/TLS handshake detection
#ifndef ASYNC_TCP_SSL_ENABLED
if (_parseState == PARSE_REQ_START && len && ((uint8_t*)buf)[0] == 0x16) { // 0x16 indicates a Handshake message (SSL/TLS).
#ifdef ESP32
log_d("SSL/TLS handshake detected: closing connection");
log_d("SSL/TLS handshake detected: resetting connection");
#endif
_parseState = PARSE_REQ_FAIL;
_client->close();
// _client->close();
_client->abort();
return;
}
#endif
Expand Down Expand Up @@ -171,6 +181,7 @@ void AsyncWebServerRequest::_onData(void* buf, size_t len) {
}

void AsyncWebServerRequest::_onPoll() {
log_d("Request pointer: %p", this);
// os_printf("p\n");
if (_response != NULL && _client != NULL && _client->canSend()) {
if (!_response->_finished()) {
Expand All @@ -186,6 +197,7 @@ void AsyncWebServerRequest::_onPoll() {
}

void AsyncWebServerRequest::_onAck(size_t len, uint32_t time) {
log_d("Request pointer: %p, len: %u, time: %u", this, len, time);
// os_printf("a:%u:%u\n", len, time);
if (_response != NULL) {
if (!_response->_finished()) {
Expand All @@ -201,10 +213,12 @@ void AsyncWebServerRequest::_onAck(size_t len, uint32_t time) {
}

void AsyncWebServerRequest::_onError(int8_t error) {
log_d("Client error: %d", error);
(void)error;
}

void AsyncWebServerRequest::_onTimeout(uint32_t time) {
log_d("Client timeout: %u", time);
(void)time;
// os_printf("TIMEOUT: %u, state: %s\n", time, _client->stateToString());
_client->close();
Expand All @@ -215,6 +229,8 @@ void AsyncWebServerRequest::onDisconnect(ArDisconnectHandler fn) {
}

void AsyncWebServerRequest::_onDisconnect() {
log_d("Client disconnected");

// os_printf("d\n");
if (_onDisconnectfn) {
_onDisconnectfn();
Expand Down
2 changes: 2 additions & 0 deletions src/WebServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ AsyncWebServer::AsyncWebServer(uint16_t port)
if (r == NULL) {
c->close(true);
c->free();
log_e("Delete client pointer: %p", c);
delete c;
}
},
Expand Down Expand Up @@ -135,6 +136,7 @@ void AsyncWebServer::beginSecure(const char* cert, const char* key, const char*
#endif

void AsyncWebServer::_handleDisconnect(AsyncWebServerRequest* request) {
log_d("Deleting request pointer: %p", request);
delete request;
}

Expand Down

0 comments on commit 4cdb84d

Please sign in to comment.