close connection if socket recv() fails.
authorNick Dowell <nick@nickdowell.com>
Thu, 5 Apr 2012 02:29:39 +0000 (10:29 +0800)
committerAndy Green <andy.green@linaro.org>
Thu, 5 Apr 2012 02:29:39 +0000 (10:29 +0800)
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 <nick@nickdowell.com>
lib/libwebsockets.c

index 6baf2c7..b75ab3b 100644 (file)
@@ -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,