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 <andy.green@linaro.org>
Signed-off-by: Graham Newton <gnewton@peavey-eu.com>
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 @@
 
 	}
 
+	/* 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 @@
 	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 @@
 			   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)) {