# HG changeset patch # User Maxim Dounin # Date 1463576248 -10800 # Node ID a01e400dd4a1fdcdc3404f06d0e2ca870e18c125 # Parent d94f579904920078c76fc18157dda0c7cffb64ce Fixed work with --test-build-epoll after f7849bfb6d21. diff --git a/src/event/modules/ngx_epoll_module.c b/src/event/modules/ngx_epoll_module.c --- a/src/event/modules/ngx_epoll_module.c +++ b/src/event/modules/ngx_epoll_module.c @@ -105,6 +105,9 @@ static ngx_int_t ngx_epoll_init(ngx_cycl 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_event 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_m #endif #if (NGX_HAVE_FILE_AIO) + ngx_epoll_aio_init(cycle, epcf); +#endif - ngx_epoll_aio_init(cycle, epcf); - +#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 *e #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) {