Mercurial > hg > nginx
changeset 6540:a01e400dd4a1
Fixed work with --test-build-epoll after f7849bfb6d21.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Wed, 18 May 2016 15:57:28 +0300 |
parents | d94f57990492 |
children | 282448777dc2 |
files | src/event/modules/ngx_epoll_module.c |
diffstat | 1 files changed, 71 insertions(+), 67 deletions(-) [+] |
line wrap: on
line diff
--- a/src/event/modules/ngx_epoll_module.c Mon May 16 20:37:38 2016 +0300 +++ b/src/event/modules/ngx_epoll_module.c Wed May 18 15:57:28 2016 +0300 @@ -105,6 +105,9 @@ 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 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_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 @@ #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 @@ #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 @@ #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) {