From c04c193dc36c674bd5eec13af8b5c821367c0d08 Mon Sep 17 00:00:00 2001 From: Nick Dowell Date: Thu, 5 Apr 2012 10:29:39 +0800 Subject: [PATCH] close connection if socket recv() fails. This prevents a problem observed on Windows whereby a client that disconnects before fully establishing the WebSocket would cause the server to use 100% CPU since recv() would continually return -1 for that socket. Signed-off-by: Nick Dowell --- lib/libwebsockets.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/libwebsockets.c b/lib/libwebsockets.c index 6baf2c71..b75ab3b1 100644 --- a/lib/libwebsockets.c +++ b/lib/libwebsockets.c @@ -1964,7 +1964,10 @@ bail3: if (eff_buf.token_len < 0) { fprintf(stderr, "Socket read returned %d\n", eff_buf.token_len); - break; + if (errno != EINTR) + libwebsocket_close_and_free_session(context, wsi, + LWS_CLOSE_STATUS_NOSTATUS); + return 1; } if (!eff_buf.token_len) { libwebsocket_close_and_free_session(context, wsi,