header response timeout added

This commit is contained in:
Tobias Gessler
2020-09-12 17:20:03 +02:00
parent 7e34a8b246
commit e185668a97
2 changed files with 9 additions and 0 deletions

View File

@ -85,6 +85,7 @@ void WebSocketsClient::begin(const char * host, uint16_t port, const char * url,
#endif #endif
_lastConnectionFail = 0; _lastConnectionFail = 0;
_lastHeaderSent = 0;
} }
void WebSocketsClient::begin(String host, uint16_t port, String url, String protocol) { void WebSocketsClient::begin(String host, uint16_t port, String url, String protocol) {
@ -490,6 +491,12 @@ bool WebSocketsClient::clientIsConnected(WSclient_t * client) {
* Handel incomming data from Client * Handel incomming data from Client
*/ */
void WebSocketsClient::handleClientData(void) { void WebSocketsClient::handleClientData(void) {
if(_client.status == WSC_HEADER && _lastHeaderSent + WEBSOCKETS_TCP_TIMEOUT < millis()) {
DEBUG_WEBSOCKETS("[WS-Client][handleClientData] header response timeout.. disconnecting!\n");
clientDisconnect(&_client);
WEBSOCKETS_YIELD();
return;
}
int len = _client.tcp->available(); int len = _client.tcp->available();
if(len > 0) { if(len > 0) {
switch(_client.status) { switch(_client.status) {
@ -598,6 +605,7 @@ void WebSocketsClient::sendHeader(WSclient_t * client) {
#endif #endif
DEBUG_WEBSOCKETS("[WS-Client][sendHeader] sending header... Done (%luus).\n", (micros() - start)); DEBUG_WEBSOCKETS("[WS-Client][sendHeader] sending header... Done (%luus).\n", (micros() - start));
_lastHeaderSent = millis();
} }
/** /**

View File

@ -107,6 +107,7 @@ class WebSocketsClient : protected WebSockets {
unsigned long _lastConnectionFail; unsigned long _lastConnectionFail;
unsigned long _reconnectInterval; unsigned long _reconnectInterval;
unsigned long _lastHeaderSent;
void messageReceived(WSclient_t * client, WSopcode_t opcode, uint8_t * payload, size_t length, bool fin); void messageReceived(WSclient_t * client, WSopcode_t opcode, uint8_t * payload, size_t length, bool fin);