66// We target C++17 capable toolchain
77#if __cplusplus >= 201703L
88#include " AsyncWSocket.h"
9- #if defined(ESP32) && (ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0))
9+ #if defined(ESP32)
10+ #if (ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0))
1011#include " literals.h"
1112
1213#define WS_MAX_HEADER_SIZE 16
@@ -220,7 +221,7 @@ void WSocketClient::_clientSend(size_t acked_bytes){
220221 // log_d("infl:%u, credits:%u", _in_flight, _in_flight_credit);
221222 // check if we were waiting to ack our disconnection frame
222223 if (!_in_flight && (_connection == conn_state_t ::disconnecting)){
223- log_d (" closing tcp-conn" );
224+ // log_d("closing tcp-conn");
224225 // we are server, should close connection first as per https://datatracker.ietf.org/doc/html/rfc6455#section-7.1.1
225226 // here we close from the app side, send TCP-FIN to the party and move to FIN_WAIT_1/2 states
226227 _client->close ();
@@ -245,7 +246,7 @@ void WSocketClient::_clientSend(size_t acked_bytes){
245246 // ignore the call if available sock space is smaller then acked data and we won't be able to fit message's ramainder there
246247 // this will reduce AsyncTCP's event Q pressure under heavy load
247248 if ((_outFrame.msg && (_outFrame.len - _outFrame.index > _client->space ())) && (_client->space () < acked_bytes) ){
248- log_d (" defer ws send call, in-flight:%u/%u" , _in_flight, _client->space ());
249+ // log_d("defer ws send call, in-flight:%u/%u", _in_flight, _client->space());
249250 return ;
250251 }
251252
@@ -363,12 +364,12 @@ void WSocketClient::_onTimeout(uint32_t time) {
363364
364365void WSocketClient::_onDisconnect (AsyncClient *c) {
365366 _connection = conn_state_t ::disconnected;
366- log_d (" TCP client disconnected" );
367+ // log_d("TCP client disconnected");
367368 _sendEvent (event_t ::disconnect);
368369}
369370
370371void WSocketClient::_onData (void *pbuf, size_t plen) {
371- Serial. printf (" _onData, len:%u\n " , plen);
372+ // log_d ("_onData, len:%u\n", plen);
372373 if (!pbuf || !plen || _connection == conn_state_t ::disconnected) return ;
373374 char *data = (char *)pbuf;
374375
@@ -406,7 +407,7 @@ void WSocketClient::_onData(void *pbuf, size_t plen) {
406407
407408 // if we got whole frame now
408409 if (_inFrame.index == _inFrame.len ){
409- log_d (" _onData, cmplt msg len:%u" , (uint32_t )_inFrame.len );
410+ // log_d("cmplt msg len:%u", (uint32_t)_inFrame.len);
410411
411412 if (_inFrame.msg ->getStatusCode () == 1007 ){
412413 // this is a dummy/corrupted message, we discard it
@@ -418,7 +419,7 @@ void WSocketClient::_onData(void *pbuf, size_t plen) {
418419 // received close message
419420 case WSFrameType_t::close : {
420421 if (_connection == conn_state_t ::disconnecting){
421- log_d (" recv close ack" );
422+ // log_d("recv close ack");
422423 // if it was ws-close ack - we can close TCP connection
423424 _connection = conn_state_t ::disconnected;
424425 // normally we should call close() here and wait for other side also close tcp connection with TCP-FIN, but
@@ -433,7 +434,7 @@ void WSocketClient::_onData(void *pbuf, size_t plen) {
433434 }
434435
435436 // otherwise it's a close request from a peer - echo back close message as per https://datatracker.ietf.org/doc/html/rfc6455#section-5.5.1
436- log_d (" recv client's ws-close req" );
437+ // log_d("recv client's ws-close req");
437438 {
438439 #ifdef ESP32
439440 std::unique_lock<std::recursive_mutex> lockin (_inQlock);
@@ -489,6 +490,7 @@ std::pair<size_t, uint16_t> WSocketClient::_mkNewFrame(char* data, size_t len, W
489490 // read frame size
490491 frame.len = data[1 ] & 0x7F ;
491492 size_t offset = 2 ; // first 2 bytes
493+ /*
492494 Serial.print("ws hdr: ");
493495 //Serial.println(frame.mask, HEX);
494496 char buffer[10] = {}; // Buffer for hex conversion
@@ -500,7 +502,7 @@ std::pair<size_t, uint16_t> WSocketClient::_mkNewFrame(char* data, size_t len, W
500502 ++ptr;
501503 }
502504 Serial.println();
503-
505+ */
504506 // find message size from header
505507 if (frame.len == 126 && len >= 4 ) {
506508 // two byte
@@ -514,7 +516,7 @@ std::pair<size_t, uint16_t> WSocketClient::_mkNewFrame(char* data, size_t len, W
514516 offset += 8 ;
515517 }
516518
517- log_d (" recv hdr, sock data:%u, msg body size:%u" , len, frame.len );
519+ // log_d("recv hdr, sock data:%u, msg body size:%u", len, frame.len);
518520
519521 // if ws.close() is called, Safari sends a close frame with plen 2 and masked bit set. We must not try to read mask key from beyond packet size
520522 if (masked && len >= offset + 4 ) {
@@ -611,7 +613,7 @@ std::pair<size_t, uint16_t> WSocketClient::_mkNewFrame(char* data, size_t len, W
611613 _inFrame.index = bodylen;
612614 }
613615
614- log_e (" new msg frame size:%u, bodylen:%u" , offset, bodylen);
616+ // log_e("new msg frame size:%u, bodylen:%u", offset, bodylen);
615617 // return the number of consumed data from input buffer
616618 return {offset, 0 };
617619}
@@ -736,9 +738,6 @@ void WSocketServer::handleRequest(AsyncWebServerRequest *request) {
736738 const AsyncWebHeader *key = request->getHeader (WS_STR_KEY);
737739 AsyncWebServerResponse *response = new AsyncWebSocketResponse (key->value (), [this ](AsyncWebServerRequest *r){ return newClient (r); });
738740 if (response == NULL ) {
739- #ifdef ESP32
740- log_e (" Failed to allocate" );
741- #endif
742741 request->abort ();
743742 return ;
744743 }
@@ -833,7 +832,6 @@ WSocketServer::msgall_err_t WSocketServer::messageToEndpoint(uint32_t hash, WSMe
833832}
834833
835834void WSocketServer::_purgeClients (){
836- log_d (" purging clients" );
837835 std::lock_guard lock (clientslock);
838836 // purge clients that are disconnected and with all messages consumed
839837 _clients.remove_if ([](const WSocketClient& c){ return (c.connection () == WSocketClient::conn_state_t ::disconnected && !c.inQueueSize () ); });
@@ -887,7 +885,7 @@ bool WSocketServerWorker::newClient(AsyncWebServerRequest *request){
887885 #endif
888886 _clients.emplace_back (getNextId (), request,
889887 [this ](WSocketClient *c, WSocketClient::event_t e){
890- log_d (" client event id:%u state:%u" , c->id , c->state ());
888+ // log_d("client event id:%u state:%u", c->id, c->state());
891889 // server echo call
892890 if (e == WSocketClient::event_t ::msgRecv) serverEcho (c);
893891 if (_task_hndlr) xTaskNotifyGive (_task_hndlr);
@@ -983,5 +981,6 @@ void WSocketServerWorker::_taskRunner(){
983981 vTaskDelete (NULL );
984982}
985983
986- #endif // ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)
984+ #endif // (ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0))
985+ #endif // defined(ESP32)
987986#endif // __cplusplus >= 201703L
0 commit comments