]> git.kaiwu.me - nginx.git/commitdiff
Fixed work with --test-build-epoll after f7849bfb6d21.
authorMaxim Dounin <mdounin@mdounin.ru>
Wed, 18 May 2016 12:57:28 +0000 (15:57 +0300)
committerMaxim Dounin <mdounin@mdounin.ru>
Wed, 18 May 2016 12:57:28 +0000 (15:57 +0300)
src/event/modules/ngx_epoll_module.c

index b1e520b2d4a7b9ae8f0a6551651255fa58126e71..f7f2c90042baae92ab5f80cb5f1c8fd1db14152e 100644 (file)
@@ -105,6 +105,9 @@ static ngx_int_t ngx_epoll_init(ngx_cycle_t *cycle, ngx_msec_t timer);
 static ngx_int_t ngx_epoll_notify_init(ngx_log_t *log);
 static void ngx_epoll_notify_handler(ngx_event_t *ev);
 #endif
+#if (NGX_HAVE_EPOLLRDHUP)
+static void ngx_epoll_test_rdhup(ngx_cycle_t *cycle);
+#endif
 static void ngx_epoll_done(ngx_cycle_t *cycle);
 static ngx_int_t ngx_epoll_add_event(ngx_event_t *ev, ngx_int_t event,
     ngx_uint_t flags);
@@ -123,7 +126,6 @@ static ngx_int_t ngx_epoll_process_events(ngx_cycle_t *cycle, ngx_msec_t timer,
 static void ngx_epoll_eventfd_handler(ngx_event_t *ev);
 #endif
 
-static ngx_int_t ngx_epoll_module_init(ngx_cycle_t *cycle);
 static void *ngx_epoll_create_conf(ngx_cycle_t *cycle);
 static char *ngx_epoll_init_conf(ngx_cycle_t *cycle, void *conf);
 
@@ -202,7 +204,7 @@ ngx_module_t  ngx_epoll_module = {
     ngx_epoll_commands,                  /* module directives */
     NGX_EVENT_MODULE,                    /* module type */
     NULL,                                /* init master */
-    ngx_epoll_module_init,               /* init module */
+    NULL,                                /* init module */
     NULL,                                /* init process */
     NULL,                                /* init thread */
     NULL,                                /* exit thread */
@@ -339,9 +341,11 @@ ngx_epoll_init(ngx_cycle_t *cycle, ngx_msec_t timer)
 #endif
 
 #if (NGX_HAVE_FILE_AIO)
-
         ngx_epoll_aio_init(cycle, epcf);
+#endif
 
+#if (NGX_HAVE_EPOLLRDHUP)
+        ngx_epoll_test_rdhup(cycle);
 #endif
     }
 
@@ -454,6 +458,69 @@ ngx_epoll_notify_handler(ngx_event_t *ev)
 #endif
 
 
+#if (NGX_HAVE_EPOLLRDHUP)
+
+static void
+ngx_epoll_test_rdhup(ngx_cycle_t *cycle)
+{
+    int                 epfd, s[2], events;
+    struct epoll_event  ee;
+
+    epfd = epoll_create(1);
+
+    if (epfd == -1) {
+        ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
+                      "epoll_create() failed");
+        return;
+    }
+
+    if (socketpair(AF_UNIX, SOCK_STREAM, 0, s) == -1) {
+        ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
+                      "socketpair() failed");
+        return;
+    }
+
+    ee.events = EPOLLET|EPOLLIN|EPOLLRDHUP;
+
+    if (epoll_ctl(epfd, EPOLL_CTL_ADD, s[0], &ee) == -1) {
+        ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
+                      "epoll_ctl() failed");
+        return;
+    }
+
+    if (close(s[1]) == -1) {
+        ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
+                      "close() failed");
+        return;
+    }
+
+    events = epoll_wait(epfd, &ee, 1, 5000);
+
+    if (events == -1) {
+        ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
+                      "epoll_wait() failed");
+        return;
+    }
+
+    (void) close(s[0]);
+    (void) close(epfd);
+
+    if (events) {
+        ngx_use_epoll_rdhup = ee.events & EPOLLRDHUP;
+
+    } else {
+        ngx_log_error(NGX_LOG_ALERT, cycle->log, NGX_ETIMEDOUT,
+                      "epoll_wait() timed out");
+    }
+
+    ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
+                   "testing the EPOLLRDHUP flag: %s",
+                   ngx_use_epoll_rdhup ? "success" : "fail");
+}
+
+#endif
+
+
 static void
 ngx_epoll_done(ngx_cycle_t *cycle)
 {
@@ -950,69 +1017,6 @@ ngx_epoll_eventfd_handler(ngx_event_t *ev)
 #endif
 
 
-static ngx_int_t
-ngx_epoll_module_init(ngx_cycle_t *cycle)
-{
-#if (NGX_HAVE_EPOLLRDHUP)
-    int                 epfd, s[2], events;
-    struct epoll_event  ee;
-
-    epfd = epoll_create(1);
-
-    if (epfd == -1) {
-        ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
-                      "epoll_create() failed");
-        return NGX_ERROR;
-    }
-
-    if (socketpair(AF_UNIX, SOCK_STREAM, 0, s) == -1) {
-        ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
-                      "socketpair() failed");
-        return NGX_ERROR;
-    }
-
-    ee.events = EPOLLET|EPOLLIN|EPOLLRDHUP;
-
-    if (epoll_ctl(epfd, EPOLL_CTL_ADD, s[0], &ee) == -1) {
-        ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
-                      "epoll_ctl() failed");
-        return NGX_ERROR;
-    }
-
-    if (close(s[1]) == -1) {
-        ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
-                      "close() failed");
-        return NGX_ERROR;
-    }
-
-    events = epoll_wait(epfd, &ee, 1, 5000);
-
-    if (events == -1) {
-        ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
-                      "epoll_wait() failed");
-        return NGX_ERROR;
-    }
-
-    (void) close(s[0]);
-    (void) close(epfd);
-
-    if (events) {
-        ngx_use_epoll_rdhup = ee.events & EPOLLRDHUP;
-
-    } else {
-        ngx_log_error(NGX_LOG_ALERT, cycle->log, NGX_ETIMEDOUT,
-                      "epoll_wait() timed out");
-    }
-
-    ngx_log_error(NGX_LOG_NOTICE, cycle->log, 0,
-                  "testing the EPOLLRDHUP flag: %s",
-                  ngx_use_epoll_rdhup ? "success" : "fail");
-#endif
-
-    return NGX_OK;
-}
-
-
 static void *
 ngx_epoll_create_conf(ngx_cycle_t *cycle)
 {