diff options
Diffstat (limited to 'src/event')
| -rw-r--r-- | src/event/modules/ngx_aio_module.c | 101 | ||||
| -rw-r--r-- | src/event/modules/ngx_devpoll_module.c | 2 | ||||
| -rw-r--r-- | src/event/modules/ngx_kqueue_module.c | 23 | ||||
| -rw-r--r-- | src/event/modules/ngx_kqueue_module.h | 2 | ||||
| -rw-r--r-- | src/event/ngx_event.c | 26 | ||||
| -rw-r--r-- | src/event/ngx_event.h | 2 | ||||
| -rw-r--r-- | src/event/ngx_event_accept.c | 60 | ||||
| -rw-r--r-- | src/event/ngx_event_acceptex.c | 16 |
8 files changed, 151 insertions, 81 deletions
diff --git a/src/event/modules/ngx_aio_module.c b/src/event/modules/ngx_aio_module.c index 20cb1a63c..24d049f80 100644 --- a/src/event/modules/ngx_aio_module.c +++ b/src/event/modules/ngx_aio_module.c @@ -1,39 +1,109 @@ #include <ngx_config.h> - #include <ngx_core.h> -#include <ngx_types.h> -#include <ngx_log.h> -#include <ngx_connection.h> #include <ngx_event.h> -#include <ngx_event_timer.h> +#include <ngx_aio.h> #if (HAVE_KQUEUE) #include <ngx_kqueue_module.h> #endif -int ngx_aio_init(int max_connections, ngx_log_t *log) -{ -#if (HAVE_KQUEUE) +static int ngx_aio_init(ngx_log_t *log); +static void ngx_aio_done(ngx_log_t *log); +static int ngx_aio_add_event(ngx_event_t *ev, int event, u_int flags); +static int ngx_aio_del_event(ngx_event_t *ev, int event, u_int flags); +static int ngx_aio_process_events(ngx_log_t *log); + + +ngx_os_io_t ngx_os_aio = { + ngx_aio_read, + NULL, + ngx_aio_write, + ngx_aio_write_chain, + NGX_HAVE_ZEROCOPY +}; + + +static ngx_str_t aio_name = ngx_string("aio"); + +ngx_event_module_t ngx_aio_module_ctx = { + NGX_EVENT_MODULE, + &aio_name, + NULL, /* create configuration */ + NULL, /* init configuration */ + + { + ngx_aio_add_event, /* add an event */ + ngx_aio_del_event, /* delete an event */ + NULL, /* enable an event */ + NULL, /* disable an event */ + NULL, /* add an connection */ + NULL, /* delete an connection */ + ngx_aio_process_events, /* process the events */ + ngx_aio_init, /* init the events */ + ngx_aio_done /* done the events */ + } + +}; - int rc; +ngx_module_t ngx_aio_module = { + &ngx_aio_module_ctx, /* module context */ + 0, /* module index */ + NULL, /* module directives */ + NGX_EVENT_MODULE_TYPE, /* module type */ + NULL /* init module */ +}; - rc = ngx_kqueue_init(max_connections, log); + + +#if (HAVE_KQUEUE) + +static int ngx_aio_init(ngx_log_t *log) +{ + if (ngx_kqueue_module_ctx.actions.init(log) == NGX_ERROR) { + return NGX_ERROR; + } ngx_event_flags = NGX_HAVE_AIO_EVENT|NGX_USE_AIO_EVENT; - ngx_write_chain_proc = ngx_aio_write_chain; + ngx_event_actions = ngx_aio_module_ctx.actions; + ngx_io = ngx_os_aio; - return rc; -#endif + return NGX_OK; } +static void ngx_aio_done(ngx_log_t *log) +{ + ngx_kqueue_module_ctx.actions.done(log); +} +/* The event adding and deleteing are needed for the listening sockets */ + +static int ngx_aio_add_event(ngx_event_t *ev, int event, u_int flags) +{ + return ngx_kqueue_module_ctx.actions.add(ev, event, flags); +} + + +static int ngx_aio_del_event(ngx_event_t *ev, int event, u_int flags) +{ + return ngx_kqueue_module_ctx.actions.del(ev, event, flags); +} + + +static int ngx_aio_process_events(ngx_log_t *log) +{ + return ngx_kqueue_module_ctx.actions.process(log); +} + +#endif + #if 0 + /* 1 */ int ngx_posix_aio_process_events(ngx_log_t *log) { @@ -66,6 +136,7 @@ int ngx_posix_aio_process_events(ngx_log_t *log) /* 3 */ int ngx_posix_aio_process_events(ngx_log_t *log) { +#if 0 unmask signal /* BUG: AIO signal can be delivered before select() */ @@ -73,6 +144,9 @@ int ngx_posix_aio_process_events(ngx_log_t *log) select(listen); mask signal +#endif + + pselect(listen, mask); if (ngx_socket_errno == NGX_EINTR) look ready array @@ -82,4 +156,5 @@ void aio_sig_handler(int signo, siginfo_t *siginfo, void *context) { push siginfo->si_value.sival_ptr } + #endif diff --git a/src/event/modules/ngx_devpoll_module.c b/src/event/modules/ngx_devpoll_module.c index 72efda4c4..531e96a24 100644 --- a/src/event/modules/ngx_devpoll_module.c +++ b/src/event/modules/ngx_devpoll_module.c @@ -10,7 +10,7 @@ #include <ngx_event.h> -#if (TEST_DEVPOLL) +#if (TEST_BUILD_DEVPOLL) /* Solaris declarations */ diff --git a/src/event/modules/ngx_kqueue_module.c b/src/event/modules/ngx_kqueue_module.c index 81475f70e..b8398b5f1 100644 --- a/src/event/modules/ngx_kqueue_module.c +++ b/src/event/modules/ngx_kqueue_module.c @@ -66,7 +66,7 @@ ngx_event_module_t ngx_kqueue_module_ctx = { NULL, /* delete an connection */ ngx_kqueue_process_events, /* process the events */ ngx_kqueue_init, /* init the events */ - ngx_kqueue_done, /* done the events */ + ngx_kqueue_done /* done the events */ } }; @@ -343,22 +343,23 @@ static int ngx_kqueue_process_events(ngx_log_t *log) } ev = (ngx_event_t *) event_list[i].udata; - instance = (uintptr_t) ev & 1; - ev = (void *) ((uintptr_t) ev & ~1); - - /* It's a stale event from a file descriptor - that was just closed in this iteration */ - - if (ev->active == 0 || ev->instance != instance) { - ngx_log_debug(log, "stale kevent"); - continue; - } switch (event_list[i].filter) { case EVFILT_READ: case EVFILT_WRITE: + instance = (uintptr_t) ev & 1; + ev = (void *) ((uintptr_t) ev & ~1); + + /* It's a stale event from a file descriptor + that was just closed in this iteration */ + + if (ev->active == 0 || ev->instance != instance) { + ngx_log_debug(log, "stale kevent"); + continue; + } + ev->available = event_list[i].data; if (event_list[i].flags & EV_EOF) { diff --git a/src/event/modules/ngx_kqueue_module.h b/src/event/modules/ngx_kqueue_module.h index 4f41ae790..72b85d235 100644 --- a/src/event/modules/ngx_kqueue_module.h +++ b/src/event/modules/ngx_kqueue_module.h @@ -9,6 +9,8 @@ typedef struct { extern int ngx_kqueue; +/* STUB */ extern ngx_event_module_t ngx_kqueue_module_ctx; + #endif /* _NGX_KQUEUE_MODULE_H_INCLUDED_ */ diff --git a/src/event/ngx_event.c b/src/event/ngx_event.c index dc46c6f49..9a4796ac1 100644 --- a/src/event/ngx_event.c +++ b/src/event/ngx_event.c @@ -31,7 +31,7 @@ extern ngx_event_module_t ngx_devpoll_module_ctx; static char *ngx_events_block(ngx_conf_t *cf, ngx_command_t *cmd, char *dummy); -static char *ngx_event_set_type(ngx_conf_t *cf, ngx_command_t *cmd, char *conf); +static char *ngx_event_use(ngx_conf_t *cf, ngx_command_t *cmd, char *conf); static void *ngx_event_create_conf(ngx_pool_t *pool); static char *ngx_event_init_conf(ngx_pool_t *pool, void *conf); @@ -84,9 +84,9 @@ static ngx_command_t ngx_event_commands[] = { offsetof(ngx_event_conf_t, connections), NULL}, - {ngx_string("type"), + {ngx_string("use"), NGX_EVENT_CONF|NGX_CONF_TAKE1, - ngx_event_set_type, + ngx_event_use, 0, 0, NULL}, @@ -135,7 +135,7 @@ int ngx_pre_thread(ngx_array_t *ls, ngx_pool_t *pool, ngx_log_t *log) ecf = ngx_event_get_conf(ngx_event_module_ctx); ngx_log_debug(log, "CONN: %d" _ ecf->connections); -ngx_log_debug(log, "TYPE: %d" _ ecf->type); +ngx_log_debug(log, "TYPE: %d" _ ecf->use); for (m = 0; ngx_modules[m]; m++) { if (ngx_modules[m]->type != NGX_EVENT_MODULE_TYPE) { @@ -143,7 +143,7 @@ ngx_log_debug(log, "TYPE: %d" _ ecf->type); } module = ngx_modules[m]->ctx; - if (module->index == ecf->type) { + if (module->index == ecf->use) { if (module->actions.init(log) == NGX_ERROR) { return NGX_ERROR; } @@ -317,7 +317,7 @@ static char *ngx_events_block(ngx_conf_t *cf, ngx_command_t *cmd, char *conf) } -static char *ngx_event_set_type(ngx_conf_t *cf, ngx_command_t *cmd, char *conf) +static char *ngx_event_use(ngx_conf_t *cf, ngx_command_t *cmd, char *conf) { ngx_event_conf_t *ecf = (ngx_event_conf_t *) conf; @@ -325,8 +325,8 @@ static char *ngx_event_set_type(ngx_conf_t *cf, ngx_command_t *cmd, char *conf) ngx_str_t *args; ngx_event_module_t *module; - if (ecf->type != NGX_CONF_UNSET) { - return "duplicate event type" ; + if (ecf->use != NGX_CONF_UNSET) { + return "is duplicate" ; } args = cf->args->elts; @@ -339,7 +339,7 @@ static char *ngx_event_set_type(ngx_conf_t *cf, ngx_command_t *cmd, char *conf) module = ngx_modules[m]->ctx; if (module->name->len == args[1].len) { if (ngx_strcmp(module->name->data, args[1].data) == 0) { - ecf->type = module->index; + ecf->use = module->index; return NGX_CONF_OK; } } @@ -358,7 +358,7 @@ static void *ngx_event_create_conf(ngx_pool_t *pool) ecf->connections = NGX_CONF_UNSET; ecf->timer_queues = NGX_CONF_UNSET; - ecf->type = NGX_CONF_UNSET; + ecf->use = NGX_CONF_UNSET; return ecf; } @@ -380,19 +380,19 @@ static char *ngx_event_init_conf(ngx_pool_t *pool, void *conf) #endif ngx_conf_init_value(ecf->connections, DEF_CONNECTIONS); - ngx_conf_init_value(ecf->type, ngx_kqueue_module_ctx.index); + ngx_conf_init_value(ecf->use, ngx_kqueue_module_ctx.index); #elif (HAVE_DEVPOLL) ngx_conf_init_value(ecf->connections, DEF_CONNECTIONS); - ngx_conf_init_value(ecf->type, ngx_devpoll_module_ctx.index); + ngx_conf_init_value(ecf->use, ngx_devpoll_module_ctx.index); #else /* HAVE_SELECT */ ngx_conf_init_value(ecf->connections, FD_SETSIZE < DEF_CONNECTIONS ? FD_SETSIZE : DEF_CONNECTIONS); - ngx_conf_init_value(ecf->type, ngx_select_module_ctx.index); + ngx_conf_init_value(ecf->use, ngx_select_module_ctx.index); #endif diff --git a/src/event/ngx_event.h b/src/event/ngx_event.h index 4325ab31f..c3f925f58 100644 --- a/src/event/ngx_event.h +++ b/src/event/ngx_event.h @@ -327,7 +327,7 @@ extern int ngx_event_flags; typedef struct { int connections; int timer_queues; - int type; + int use; } ngx_event_conf_t; diff --git a/src/event/ngx_event_accept.c b/src/event/ngx_event_accept.c index 75dda55c0..76eae62d9 100644 --- a/src/event/ngx_event_accept.c +++ b/src/event/ngx_event_accept.c @@ -65,39 +65,28 @@ void ngx_event_accept(ngx_event_t *ev) return; } - -#if (HAVE_INHERITED_NONBLOCK) - -#if (HAVE_AIO_EVENT) - if ((ngx_event_flags & NGX_HAVE_AIO_EVENT)) { - if (ngx_blocking(s) == -1) { - ngx_log_error(NGX_LOG_ALERT, ev->log, ngx_socket_errno, - ngx_blocking_n " %s failed", ls->addr_text.data); - return; + /* set a blocking mode for aio and non-blocking mode for others */ + + if (ngx_inherited_nonblocking) { + if ((ngx_event_flags & NGX_USE_AIO_EVENT)) { + if (ngx_blocking(s) == -1) { + ngx_log_error(NGX_LOG_ALERT, ev->log, ngx_socket_errno, + ngx_blocking_n " %s failed", + ls->addr_text.data); + return; + } } - } -#endif -#else /* !HAVE_INHERITED_NONBLOCK */ - -#if (HAVE_AIO_EVENT) - if (!(ngx_event_flags & NGX_HAVE_AIO_EVENT)) { - if (ngx_nonblocking(s) == -1) { - ngx_log_error(NGX_LOG_ALERT, ev->log, ngx_socket_errno, - ngx_nonblocking_n " %s failed", ls->addr_text.data); - return; + } else { + if ((ngx_event_flags & NGX_USE_AIO_EVENT) == 0) { + if (ngx_nonblocking(s) == -1) { + ngx_log_error(NGX_LOG_ALERT, ev->log, ngx_socket_errno, + ngx_nonblocking_n " %s failed", + ls->addr_text.data); + return; + } } } -#else - if (ngx_nonblocking(s) == -1) { - ngx_log_error(NGX_LOG_ALERT, ev->log, ngx_socket_errno, - ngx_nonblocking_n " %s failed", ls->addr_text.data); - return; - } -#endif - -#endif /* HAVE_INHERITED_NONBLOCK */ - rev = &ngx_read_events[s]; wev = &ngx_write_events[s]; @@ -130,15 +119,9 @@ void ngx_event_accept(ngx_event_t *ev) c->unexpected_eof = 1; wev->write = 1; -#if (USE_KQUEUE) - wev->ready = 1; -#else if ((ngx_event_flags & NGX_USE_AIO_EVENT) == 0) { wev->ready = 1; } -#endif - - /* STUB ? */ wev->timer = rev->timer = 10000; c->ctx = ls->ctx; c->servers = ls->servers; @@ -174,17 +157,10 @@ void ngx_event_accept(ngx_event_t *ev) ls->handler(c); -#if (USE_KQUEUE) - - ev->available--; - -#elif (HAVE_KQUEUE) - if (ngx_event_flags & NGX_HAVE_KQUEUE_EVENT) { ev->available--; } -#endif } while (ev->available); return; diff --git a/src/event/ngx_event_acceptex.c b/src/event/ngx_event_acceptex.c index ce46a16ce..fceb725d5 100644 --- a/src/event/ngx_event_acceptex.c +++ b/src/event/ngx_event_acceptex.c @@ -29,6 +29,22 @@ int ngx_event_acceptex(ngx_event_t *ev) return NGX_OK; } +#if 0 + + /* can we do SO_UPDATE_ACCEPT_CONTEXT just before shutdown() ??? + or AcceptEx's context will be lost ??? */ + + /* SO_UPDATE_ACCEPT_CONTEXT is required for shutdown() to work */ + if (setsockopt(context->accept_socket, SOL_SOCKET, + SO_UPDATE_ACCEPT_CONTEXT, (char *)&nsd, + sizeof(nsd))) { + ap_log_error(APLOG_MARK, APLOG_ERR, WSAGetLastError(), server_conf, + "setsockopt(SO_UPDATE_ACCEPT_CONTEXT) failed."); + + /* non fatal - we can not only do lingering close */ + +#endif + getacceptexsockaddrs(c->data, 0, c->socklen + 16, c->socklen + 16, &c->local_sockaddr, &c->local_socklen, |
