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
@@ -219,7 +220,7 @@ void WSocketClient::_clientSend(size_t acked_bytes){
219220 // log_d("infl:%u, credits:%u", _in_flight, _in_flight_credit);
220221 // check if we were waiting to ack our disconnection frame
221222 if (!_in_flight && (_connection == conn_state_t ::disconnecting)){
222- log_d (" closing tcp-conn" );
223+ // log_d("closing tcp-conn");
223224 // we are server, should close connection first as per https://datatracker.ietf.org/doc/html/rfc6455#section-7.1.1
224225 // here we close from the app side, send TCP-FIN to the party and move to FIN_WAIT_1/2 states
225226 _client->close ();
@@ -244,7 +245,7 @@ void WSocketClient::_clientSend(size_t acked_bytes){
244245 // ignore the call if available sock space is smaller then acked data and we won't be able to fit message's ramainder there
245246 // this will reduce AsyncTCP's event Q pressure under heavy load
246247 if ((_outFrame.msg && (_outFrame.len - _outFrame.index > _client->space ())) && (_client->space () < acked_bytes) ){
247- log_d (" defer ws send call, in-flight:%u/%u" , _in_flight, _client->space ());
248+ // log_d("defer ws send call, in-flight:%u/%u", _in_flight, _client->space());
248249 return ;
249250 }
250251
@@ -362,12 +363,12 @@ void WSocketClient::_onTimeout(uint32_t time) {
362363
363364void WSocketClient::_onDisconnect (AsyncClient *c) {
364365 _connection = conn_state_t ::disconnected;
365- log_d (" TCP client disconnected" );
366+ // log_d("TCP client disconnected");
366367 _sendEvent (event_t ::disconnect);
367368}
368369
369370void WSocketClient::_onData (void *pbuf, size_t plen) {
370- Serial. printf (" _onData, len:%u\n " , plen);
371+ // log_d ("_onData, len:%u\n", plen);
371372 if (!pbuf || !plen || _connection == conn_state_t ::disconnected) return ;
372373 char *data = (char *)pbuf;
373374
@@ -405,7 +406,7 @@ void WSocketClient::_onData(void *pbuf, size_t plen) {
405406
406407 // if we got whole frame now
407408 if (_inFrame.index == _inFrame.len ){
408- log_d (" _onData, cmplt msg len:%u" , (uint32_t )_inFrame.len );
409+ // log_d("cmplt msg len:%u", (uint32_t)_inFrame.len);
409410
410411 if (_inFrame.msg ->getStatusCode () == 1007 ){
411412 // this is a dummy/corrupted message, we discard it
@@ -417,7 +418,7 @@ void WSocketClient::_onData(void *pbuf, size_t plen) {
417418 // received close message
418419 case WSFrameType_t::close : {
419420 if (_connection == conn_state_t ::disconnecting){
420- log_d (" recv close ack" );
421+ // log_d("recv close ack");
421422 // if it was ws-close ack - we can close TCP connection
422423 _connection = conn_state_t ::disconnected;
423424 // normally we should call close() here and wait for other side also close tcp connection with TCP-FIN, but
@@ -432,7 +433,7 @@ void WSocketClient::_onData(void *pbuf, size_t plen) {
432433 }
433434
434435 // 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
435- log_d (" recv client's ws-close req" );
436+ // log_d("recv client's ws-close req");
436437 {
437438 #ifdef ESP32
438439 std::unique_lock<std::recursive_mutex> lockin (_inQlock);
@@ -488,6 +489,7 @@ std::pair<size_t, uint16_t> WSocketClient::_mkNewFrame(char* data, size_t len, W
488489 // read frame size
489490 frame.len = data[1 ] & 0x7F ;
490491 size_t offset = 2 ; // first 2 bytes
492+ /*
491493 Serial.print("ws hdr: ");
492494 //Serial.println(frame.mask, HEX);
493495 char buffer[10] = {}; // Buffer for hex conversion
@@ -499,7 +501,7 @@ std::pair<size_t, uint16_t> WSocketClient::_mkNewFrame(char* data, size_t len, W
499501 ++ptr;
500502 }
501503 Serial.println();
502-
504+ */
503505 // find message size from header
504506 if (frame.len == 126 && len >= 4 ) {
505507 // two byte
@@ -513,7 +515,7 @@ std::pair<size_t, uint16_t> WSocketClient::_mkNewFrame(char* data, size_t len, W
513515 offset += 8 ;
514516 }
515517
516- log_d (" recv hdr, sock data:%u, msg body size:%u" , len, frame.len );
518+ // log_d("recv hdr, sock data:%u, msg body size:%u", len, frame.len);
517519
518520 // 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
519521 if (masked && len >= offset + 4 ) {
@@ -609,7 +611,7 @@ std::pair<size_t, uint16_t> WSocketClient::_mkNewFrame(char* data, size_t len, W
609611 _inFrame.index = bodylen;
610612 }
611613
612- log_e (" new msg frame size:%u, bodylen:%u" , offset, bodylen);
614+ // log_e("new msg frame size:%u, bodylen:%u", offset, bodylen);
613615 // return the number of consumed data from input buffer
614616 return {offset, 0 };
615617}
@@ -734,9 +736,6 @@ void WSocketServer::handleRequest(AsyncWebServerRequest *request) {
734736 const AsyncWebHeader *key = request->getHeader (WS_STR_KEY);
735737 AsyncWebServerResponse *response = new AsyncWebSocketResponse (key->value (), [this ](AsyncWebServerRequest *r){ return newClient (r); });
736738 if (response == NULL ) {
737- #ifdef ESP32
738- log_e (" Failed to allocate" );
739- #endif
740739 request->abort ();
741740 return ;
742741 }
@@ -831,7 +830,6 @@ WSocketServer::msgall_err_t WSocketServer::messageToEndpoint(uint32_t hash, WSMe
831830}
832831
833832void WSocketServer::_purgeClients (){
834- log_d (" purging clients" );
835833 std::lock_guard lock (clientslock);
836834 // purge clients that are disconnected and with all messages consumed
837835 _clients.remove_if ([](const WSocketClient& c){ return (c.connection () == WSocketClient::conn_state_t ::disconnected && !c.inQueueSize () ); });
@@ -885,7 +883,7 @@ bool WSocketServerWorker::newClient(AsyncWebServerRequest *request){
885883 #endif
886884 _clients.emplace_back (getNextId (), request,
887885 [this ](WSocketClient *c, WSocketClient::event_t e){
888- log_d (" client event id:%u state:%u" , c->id , c->state ());
886+ // log_d("client event id:%u state:%u", c->id, c->state());
889887 // server echo call
890888 if (e == WSocketClient::event_t ::msgRecv) serverEcho (c);
891889 if (_task_hndlr) xTaskNotifyGive (_task_hndlr);
@@ -981,5 +979,6 @@ void WSocketServerWorker::_taskRunner(){
981979 vTaskDelete (NULL );
982980}
983981
984- #endif // ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)
982+ #endif // (ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0))
983+ #endif // defined(ESP32)
985984#endif // __cplusplus >= 201703L
0 commit comments