From 176de27df67f3b57d9af87cda8920b5424aa0d6a Mon Sep 17 00:00:00 2001 From: Andy Green Date: Sat, 15 Feb 2014 14:36:02 +0800 Subject: [PATCH] add timeout between accept and negotiation Signed-off-by: Andy Green --- lib/handshake.c | 1 + lib/server.c | 12 +++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/handshake.c b/lib/handshake.c index 1e4919a7..35c6e4d6 100644 --- a/lib/handshake.c +++ b/lib/handshake.c @@ -169,6 +169,7 @@ http_postbody: lwsl_parser("libwebsocket_parse sees parsing complete\n"); wsi->mode = LWS_CONNMODE_PRE_WS_SERVING_ACCEPT; + libwebsocket_set_timeout(wsi, NO_PENDING_TIMEOUT, 0); /* is this websocket protocol or normal http 1.0? */ diff --git a/lib/server.c b/lib/server.c index 547364c9..dcb6cc19 100644 --- a/lib/server.c +++ b/lib/server.c @@ -282,6 +282,11 @@ int lws_server_socket_service(struct libwebsocket_context *context, new_wsi->sock = accept_fd; + /* the transport is accepted... give him time to negotiate */ + libwebsocket_set_timeout(new_wsi, + PENDING_TIMEOUT_ESTABLISH_WITH_SERVER, + AWAITING_TIMEOUT); + /* * A new connection was accepted. Give the user a chance to * set properties of the newly created wsi. There's no protocol @@ -416,9 +421,10 @@ int lws_server_socket_service(struct libwebsocket_context *context, } accepted: - /* OK, we are accepted */ - - libwebsocket_set_timeout(wsi, NO_PENDING_TIMEOUT, 0); + /* OK, we are accepted... give him some time to negotiate */ + libwebsocket_set_timeout(wsi, + PENDING_TIMEOUT_ESTABLISH_WITH_SERVER, + AWAITING_TIMEOUT); wsi->mode = LWS_CONNMODE_HTTP_SERVING;