comparison src/event/modules/ngx_epoll_module.c @ 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 3ad1064a3aae
children 282448777dc2
comparison
equal deleted inserted replaced
6539:d94f57990492 6540:a01e400dd4a1
103 static ngx_int_t ngx_epoll_init(ngx_cycle_t *cycle, ngx_msec_t timer); 103 static ngx_int_t ngx_epoll_init(ngx_cycle_t *cycle, ngx_msec_t timer);
104 #if (NGX_HAVE_EVENTFD) 104 #if (NGX_HAVE_EVENTFD)
105 static ngx_int_t ngx_epoll_notify_init(ngx_log_t *log); 105 static ngx_int_t ngx_epoll_notify_init(ngx_log_t *log);
106 static void ngx_epoll_notify_handler(ngx_event_t *ev); 106 static void ngx_epoll_notify_handler(ngx_event_t *ev);
107 #endif 107 #endif
108 #if (NGX_HAVE_EPOLLRDHUP)
109 static void ngx_epoll_test_rdhup(ngx_cycle_t *cycle);
110 #endif
108 static void ngx_epoll_done(ngx_cycle_t *cycle); 111 static void ngx_epoll_done(ngx_cycle_t *cycle);
109 static ngx_int_t ngx_epoll_add_event(ngx_event_t *ev, ngx_int_t event, 112 static ngx_int_t ngx_epoll_add_event(ngx_event_t *ev, ngx_int_t event,
110 ngx_uint_t flags); 113 ngx_uint_t flags);
111 static ngx_int_t ngx_epoll_del_event(ngx_event_t *ev, ngx_int_t event, 114 static ngx_int_t ngx_epoll_del_event(ngx_event_t *ev, ngx_int_t event,
112 ngx_uint_t flags); 115 ngx_uint_t flags);
121 124
122 #if (NGX_HAVE_FILE_AIO) 125 #if (NGX_HAVE_FILE_AIO)
123 static void ngx_epoll_eventfd_handler(ngx_event_t *ev); 126 static void ngx_epoll_eventfd_handler(ngx_event_t *ev);
124 #endif 127 #endif
125 128
126 static ngx_int_t ngx_epoll_module_init(ngx_cycle_t *cycle);
127 static void *ngx_epoll_create_conf(ngx_cycle_t *cycle); 129 static void *ngx_epoll_create_conf(ngx_cycle_t *cycle);
128 static char *ngx_epoll_init_conf(ngx_cycle_t *cycle, void *conf); 130 static char *ngx_epoll_init_conf(ngx_cycle_t *cycle, void *conf);
129 131
130 static int ep = -1; 132 static int ep = -1;
131 static struct epoll_event *event_list; 133 static struct epoll_event *event_list;
200 NGX_MODULE_V1, 202 NGX_MODULE_V1,
201 &ngx_epoll_module_ctx, /* module context */ 203 &ngx_epoll_module_ctx, /* module context */
202 ngx_epoll_commands, /* module directives */ 204 ngx_epoll_commands, /* module directives */
203 NGX_EVENT_MODULE, /* module type */ 205 NGX_EVENT_MODULE, /* module type */
204 NULL, /* init master */ 206 NULL, /* init master */
205 ngx_epoll_module_init, /* init module */ 207 NULL, /* init module */
206 NULL, /* init process */ 208 NULL, /* init process */
207 NULL, /* init thread */ 209 NULL, /* init thread */
208 NULL, /* exit thread */ 210 NULL, /* exit thread */
209 NULL, /* exit process */ 211 NULL, /* exit process */
210 NULL, /* exit master */ 212 NULL, /* exit master */
337 ngx_epoll_module_ctx.actions.notify = NULL; 339 ngx_epoll_module_ctx.actions.notify = NULL;
338 } 340 }
339 #endif 341 #endif
340 342
341 #if (NGX_HAVE_FILE_AIO) 343 #if (NGX_HAVE_FILE_AIO)
342
343 ngx_epoll_aio_init(cycle, epcf); 344 ngx_epoll_aio_init(cycle, epcf);
344 345 #endif
346
347 #if (NGX_HAVE_EPOLLRDHUP)
348 ngx_epoll_test_rdhup(cycle);
345 #endif 349 #endif
346 } 350 }
347 351
348 if (nevents < epcf->events) { 352 if (nevents < epcf->events) {
349 if (event_list) { 353 if (event_list) {
447 } 451 }
448 } 452 }
449 453
450 handler = ev->data; 454 handler = ev->data;
451 handler(ev); 455 handler(ev);
456 }
457
458 #endif
459
460
461 #if (NGX_HAVE_EPOLLRDHUP)
462
463 static void
464 ngx_epoll_test_rdhup(ngx_cycle_t *cycle)
465 {
466 int epfd, s[2], events;
467 struct epoll_event ee;
468
469 epfd = epoll_create(1);
470
471 if (epfd == -1) {
472 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
473 "epoll_create() failed");
474 return;
475 }
476
477 if (socketpair(AF_UNIX, SOCK_STREAM, 0, s) == -1) {
478 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
479 "socketpair() failed");
480 return;
481 }
482
483 ee.events = EPOLLET|EPOLLIN|EPOLLRDHUP;
484
485 if (epoll_ctl(epfd, EPOLL_CTL_ADD, s[0], &ee) == -1) {
486 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
487 "epoll_ctl() failed");
488 return;
489 }
490
491 if (close(s[1]) == -1) {
492 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
493 "close() failed");
494 return;
495 }
496
497 events = epoll_wait(epfd, &ee, 1, 5000);
498
499 if (events == -1) {
500 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
501 "epoll_wait() failed");
502 return;
503 }
504
505 (void) close(s[0]);
506 (void) close(epfd);
507
508 if (events) {
509 ngx_use_epoll_rdhup = ee.events & EPOLLRDHUP;
510
511 } else {
512 ngx_log_error(NGX_LOG_ALERT, cycle->log, NGX_ETIMEDOUT,
513 "epoll_wait() timed out");
514 }
515
516 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
517 "testing the EPOLLRDHUP flag: %s",
518 ngx_use_epoll_rdhup ? "success" : "fail");
452 } 519 }
453 520
454 #endif 521 #endif
455 522
456 523
948 } 1015 }
949 1016
950 #endif 1017 #endif
951 1018
952 1019
953 static ngx_int_t
954 ngx_epoll_module_init(ngx_cycle_t *cycle)
955 {
956 #if (NGX_HAVE_EPOLLRDHUP)
957 int epfd, s[2], events;
958 struct epoll_event ee;
959
960 epfd = epoll_create(1);
961
962 if (epfd == -1) {
963 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
964 "epoll_create() failed");
965 return NGX_ERROR;
966 }
967
968 if (socketpair(AF_UNIX, SOCK_STREAM, 0, s) == -1) {
969 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
970 "socketpair() failed");
971 return NGX_ERROR;
972 }
973
974 ee.events = EPOLLET|EPOLLIN|EPOLLRDHUP;
975
976 if (epoll_ctl(epfd, EPOLL_CTL_ADD, s[0], &ee) == -1) {
977 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
978 "epoll_ctl() failed");
979 return NGX_ERROR;
980 }
981
982 if (close(s[1]) == -1) {
983 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
984 "close() failed");
985 return NGX_ERROR;
986 }
987
988 events = epoll_wait(epfd, &ee, 1, 5000);
989
990 if (events == -1) {
991 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
992 "epoll_wait() failed");
993 return NGX_ERROR;
994 }
995
996 (void) close(s[0]);
997 (void) close(epfd);
998
999 if (events) {
1000 ngx_use_epoll_rdhup = ee.events & EPOLLRDHUP;
1001
1002 } else {
1003 ngx_log_error(NGX_LOG_ALERT, cycle->log, NGX_ETIMEDOUT,
1004 "epoll_wait() timed out");
1005 }
1006
1007 ngx_log_error(NGX_LOG_NOTICE, cycle->log, 0,
1008 "testing the EPOLLRDHUP flag: %s",
1009 ngx_use_epoll_rdhup ? "success" : "fail");
1010 #endif
1011
1012 return NGX_OK;
1013 }
1014
1015
1016 static void * 1020 static void *
1017 ngx_epoll_create_conf(ngx_cycle_t *cycle) 1021 ngx_epoll_create_conf(ngx_cycle_t *cycle)
1018 { 1022 {
1019 ngx_epoll_conf_t *epcf; 1023 ngx_epoll_conf_t *epcf;
1020 1024