]> git.kaiwu.me - nginx.git/commitdiff
Use EPOLLRDHUP in ngx_http_test_reading() (ticket #320).
authorValentin Bartenev <vbart@nginx.com>
Mon, 16 Sep 2013 14:33:39 +0000 (18:33 +0400)
committerValentin Bartenev <vbart@nginx.com>
Mon, 16 Sep 2013 14:33:39 +0000 (18:33 +0400)
This allows to detect client connection close with pending data when
the ngx_http_test_reading() request event handler is set.

src/http/ngx_http_request.c

index 37efb2a52ca131e6717eb7a55de977f711777f58..1f6d246bc26c6ec818f296eff746cebe48d40054 100644 (file)
@@ -2692,6 +2692,33 @@ ngx_http_test_reading(ngx_http_request_t *r)
         goto closed;
     }
 
+#endif
+
+#if (NGX_HAVE_EPOLLRDHUP)
+
+    if ((ngx_event_flags & NGX_USE_EPOLL_EVENT) && rev->pending_eof) {
+        socklen_t  len;
+
+        rev->eof = 1;
+        c->error = 1;
+
+        err = 0;
+        len = sizeof(ngx_err_t);
+
+        /*
+         * BSDs and Linux return 0 and set a pending error in err
+         * Solaris returns -1 and sets errno
+         */
+
+        if (getsockopt(c->fd, SOL_SOCKET, SO_ERROR, (void *) &err, &len)
+            == -1)
+        {
+            err = ngx_errno;
+        }
+
+        goto closed;
+    }
+
 #endif
 
     n = recv(c->fd, buf, 1, MSG_PEEK);