From b1aa1d3389416f44b1aab9b9255e4737fe91d5ec Mon Sep 17 00:00:00 2001 From: Graham Newton Date: Mon, 4 Nov 2013 09:47:06 +0800 Subject: [PATCH] handle HUP on any mode socket I am using libwebsockets on Windows 7 in external poll mode. I am finding that if I present a socket fd on a normal HTTP connection (LWS_CONNMODE_HTTP_SERVING:) to libwebsocket_service_fd with just a HUP event, the event doesn't get handled but revents gets cleared indicating that the event has been handled. Should it be handled in the same way as LWS_CONNMODE_WS_SERVING? (Modified by AG to apply to all sockets) Signed-off-by: Andy Green Signed-off-by: Graham Newton --- lib/libwebsockets.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/lib/libwebsockets.c b/lib/libwebsockets.c index 8e1e4fa..4378317 100644 --- a/lib/libwebsockets.c +++ b/lib/libwebsockets.c @@ -986,6 +986,17 @@ libwebsocket_service_fd(struct libwebsocket_context *context, } + /* handle session socket closed */ + + if ((!(pollfd->revents & POLLIN)) && + (pollfd->revents & (POLLERR | POLLHUP))) { + + lwsl_debug("Session Socket %p (fd=%d) dead\n", + (void *)wsi, pollfd->fd); + + goto close_and_handled; + } + /* okay, what we came here to do... */ switch (wsi->mode) { @@ -1002,17 +1013,6 @@ libwebsocket_service_fd(struct libwebsocket_context *context, case LWS_CONNMODE_WS_SERVING: case LWS_CONNMODE_WS_CLIENT: - /* handle session socket closed */ - - if ((!(pollfd->revents & POLLIN)) && - (pollfd->revents & (POLLERR | POLLHUP))) { - - lwsl_debug("Session Socket %p (fd=%d) dead\n", - (void *)wsi, pollfd->fd); - - goto close_and_handled; - } - /* the guy requested a callback when it was OK to write */ if ((pollfd->revents & POLLOUT) && @@ -1020,8 +1020,7 @@ libwebsocket_service_fd(struct libwebsocket_context *context, lws_handle_POLLOUT_event(context, wsi, pollfd) < 0) { lwsl_info("libwebsocket_service_fd: closing\n"); goto close_and_handled; - } - + } if (wsi->u.ws.rxflow_buffer && (wsi->u.ws.rxflow_change_to & LWS_RXFLOW_ALLOW)) { -- 2.7.4