avoid flush on esp32, add/fix debugs, longer yield when waiting for data
flush causes a bunch of reads as we try to close the socket on esp32. I think flush is broken on that platform. the comments indicate confusion. added some debug logs for important cases that were missing them, some missing newlines to exisitng logs. added a longer yield when waiting for data, in some super busy cases it could trigger a task watchdog or otherwise starve the system. (yield alone doesn't always switch to lower priority tasks) make some other yields conditional to avoid some waste when it would double-yield.
This commit is contained in:
@@ -501,7 +501,7 @@ void WebSockets::handleWebsocketPayloadCb(WSclient_t * client, bool ok, uint8_t
|
||||
reasonCode = payload[0] << 8 | payload[1];
|
||||
}
|
||||
#endif
|
||||
DEBUG_WEBSOCKETS("[WS][%d][handleWebsocket] get ask for close. Code: %d", client->num, reasonCode);
|
||||
DEBUG_WEBSOCKETS("[WS][%d][handleWebsocket] get ask for close. Code: %d\n", client->num, reasonCode);
|
||||
if(header->payloadLen > 2) {
|
||||
DEBUG_WEBSOCKETS(" (%s)\n", (payload + 2));
|
||||
} else {
|
||||
@@ -510,6 +510,7 @@ void WebSockets::handleWebsocketPayloadCb(WSclient_t * client, bool ok, uint8_t
|
||||
clientDisconnect(client, 1000);
|
||||
} break;
|
||||
default:
|
||||
DEBUG_WEBSOCKETS("[WS][%d][handleWebsocket] got unknown opcode: %d\n", client->num, header->opCode);
|
||||
clientDisconnect(client, 1002);
|
||||
break;
|
||||
}
|
||||
@@ -630,7 +631,7 @@ bool WebSockets::readCb(WSclient_t * client, uint8_t * out, size_t n, WSreadWait
|
||||
}
|
||||
|
||||
if(!client->tcp->available()) {
|
||||
WEBSOCKETS_YIELD();
|
||||
WEBSOCKETS_YIELD_MORE();
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -643,7 +644,9 @@ bool WebSockets::readCb(WSclient_t * client, uint8_t * out, size_t n, WSreadWait
|
||||
} else {
|
||||
//DEBUG_WEBSOCKETS("Receive %d left %d!\n", len, n);
|
||||
}
|
||||
WEBSOCKETS_YIELD();
|
||||
if (n > 0) {
|
||||
WEBSOCKETS_YIELD();
|
||||
}
|
||||
}
|
||||
if(cb) {
|
||||
cb(client, true);
|
||||
@@ -693,9 +696,11 @@ size_t WebSockets::write(WSclient_t * client, uint8_t * out, size_t n) {
|
||||
total += len;
|
||||
//DEBUG_WEBSOCKETS("write %d left %d!\n", len, n);
|
||||
} else {
|
||||
//DEBUG_WEBSOCKETS("write %d failed left %d!\n", len, n);
|
||||
DEBUG_WEBSOCKETS("WS write %d failed left %d!\n", len, n);
|
||||
}
|
||||
if (n > 0) {
|
||||
WEBSOCKETS_YIELD();
|
||||
}
|
||||
WEBSOCKETS_YIELD();
|
||||
}
|
||||
WEBSOCKETS_YIELD();
|
||||
return total;
|
||||
|
||||
Reference in New Issue
Block a user