8000 try to improve · robokoding/arduinoWebSockets@7a22dad · GitHub
[go: up one dir, main page]

Skip to content

Commit 7a22dad

Browse files
committed
try to improve
see: Links2004#23
1 parent 92a63e9 commit 7a22dad

File tree

4 files changed

+28
-16
lines changed

4 files changed

+28
-16
lines changed

src/WebSockets.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,11 @@ void WebSockets::handleWebsocket(WSclient_t * client) {
254254
}
255255

256256
if(mask) {
257-
client->tcp.read(maskKey, 4);
257+
if(!readWait(client, maskKey, 4)) {
258+
//timeout
259+
clientDisconnect(client, 1002);
260+
return;
261+
}
258262
}
259263

260264
if(payloadLen > 0) {

src/WebSockets.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
#endif
4545

4646
#define WEBSOCKETS_MAX_DATA_SIZE (15*1024)
47-
#define WEBSOCKETS_TCP_TIMEOUT (1000)
47+
#define WEBSOCKETS_TCP_TIMEOUT (1500)
4848

4949
typedef enum {
5050
WSC_NOT_CONNECTED,

src/WebSocketsClient.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -218,13 +218,17 @@ void WebSocketsClient::clientDisconnect(WSclient_t * client) {
218218
*/
219219
bool WebSocketsClient::clientIsConnected(WSclient_t * client) {
220220

221-
if(client->status != WSC_NOT_CONNECTED && client->tcp.connected()) {
222-
return true;
223-
}
224-
225-
if(client->status != WSC_NOT_CONNECTED) {
226-
// cleanup
227-
clientDisconnect(&_client);
221+
if(client->tcp.connected()) {
222+
if(client->status != WSC_NOT_CONNECTED) {
223+
return true;
224+
}
225+
} else {
226+
// client lost
227+
if(client->status != WSC_NOT_CONNECTED) {
228+
DEBUG_WEBSOCKETS("[WS-Client] connection lost.\n");
229+
// do cleanup
230+
clientDisconnect(client);
231+
}
228232
}
229233
return false;
230234
}
Original file line numberDiff line numberDiff line change
@@ -302,13 +302,17 @@ void WebSocketsServer::clientDisconnect(WSclient_t * client) {
302302
*/
303303
bool WebSocketsServer::clientIsConnected(WSclient_t * client) {
304304

305-
if(client->status != WSC_NOT_CONNECTED && client->tcp.connected()) {
306-
return true;
307-
}
308-
309-
if(client->status != WSC_NOT_CONNECTED) {
310-
// cleanup
311-
clientDisconnect(client);
305+
if(client->tcp.connected()) {
306+
if(client->status != WSC_NOT_CONNECTED) {
307+
return true;
308+
}
309+
} else {
310+
// client lost
311+
if(client->status != WSC_NOT_CONNECTED) {
312+
DEBUG_WEBSOCKETS("[WS-Server][%d] client connection lost.\n", client->num);
313+
// do cleanup
314+
clientDisconnect(client);
315+
}
312316
}
313317
return false;
314318
}
0