Mercurial > hg > nginx
diff src/event/modules/ngx_iocp_module.c @ 103:6dfda4cf5200
nginx-0.0.1-2003-06-11-19:28:34 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Wed, 11 Jun 2003 15:28:34 +0000 |
parents | 7e86d028d8f0 |
children | ac69ab96328d |
line wrap: on
line diff
--- a/src/event/modules/ngx_iocp_module.c +++ b/src/event/modules/ngx_iocp_module.c @@ -7,16 +7,13 @@ #include <ngx_config.h> #include <ngx_core.h> #include <ngx_event.h> - - -typedef struct { - int threads; -} ngx_iocp_conf_t; +#include <ngx_iocp_module.h> static int ngx_iocp_init(ngx_log_t *log); static void ngx_iocp_done(ngx_log_t *log); static int ngx_iocp_add_event(ngx_event_t *ev, int event, u_int key); +static int ngx_iocp_del_connection(ngx_connection_t *c); static int ngx_iocp_process_events(ngx_log_t *log); static void *ngx_iocp_create_conf(ngx_pool_t *pool); static char *ngx_iocp_init_conf(ngx_pool_t *pool, void *conf); @@ -33,6 +30,20 @@ static ngx_command_t ngx_iocp_commands[ offsetof(ngx_iocp_conf_t, threads), NULL}, + {ngx_string("acceptex"), + NGX_EVENT_CONF|NGX_CONF_TAKE1, + ngx_conf_set_num_slot, + 0, + offsetof(ngx_iocp_conf_t, acceptex), + NULL}, + + {ngx_string("acceptex_read"), + NGX_EVENT_CONF|NGX_CONF_TAKE1, + ngx_conf_set_flag_slot, + 0, + offsetof(ngx_iocp_conf_t, acceptex_read), + NULL}, + ngx_null_command }; @@ -48,7 +59,7 @@ ngx_event_module_t ngx_iocp_module_ctx NULL, /* enable an event */ NULL, /* disable an event */ NULL, /* add an connection */ - NULL, /* delete an connection */ + ngx_iocp_del_connection, /* delete an connection */ ngx_iocp_process_events, /* process the events */ ngx_iocp_init, /* init the events */ ngx_iocp_done /* done the events */ @@ -111,10 +122,13 @@ static int ngx_iocp_add_event(ngx_event_ c = (ngx_connection_t *) ev->data; - ngx_log_debug(ev->log, "iocp add: %d, %08x:%08x" _ c->fd _ key _ &ev->ovlp); + c->read->active = 1; + c->write->active = 1; + + ngx_log_debug(ev->log, "iocp add: %d, %d:%08x" _ c->fd _ key _ &ev->ovlp); if (CreateIoCompletionPort((HANDLE) c->fd, iocp, key, 0) == NULL) { - ngx_log_error(NGX_LOG_ALERT, ev->log, ngx_errno, + ngx_log_error(NGX_LOG_ALERT, c->log, ngx_errno, "CreateIoCompletionPort() failed"); return NGX_ERROR; } @@ -123,6 +137,17 @@ static int ngx_iocp_add_event(ngx_event_ } +static int ngx_iocp_del_connection(ngx_connection_t *c) +{ + if (CancelIo((HANDLE) c->fd) == 0) { + ngx_log_error(NGX_LOG_ALERT, c->log, ngx_errno, "CancelIo() failed"); + return NGX_ERROR; + } + + return NGX_OK; +} + + static int ngx_iocp_process_events(ngx_log_t *log) { int rc; @@ -148,7 +173,7 @@ static int ngx_iocp_process_events(ngx_l rc = GetQueuedCompletionStatus(iocp, &bytes, (LPDWORD) &key, (LPOVERLAPPED *) &ovlp, timer); - ngx_log_debug(log, "iocp: %d, %d:%08x:%08x" _ rc _ bytes _ key _ ovlp); + ngx_log_debug(log, "iocp: %d, %d, %d:%08x" _ rc _ bytes _ key _ ovlp); if (rc == 0) { err = ngx_errno; @@ -179,13 +204,17 @@ ngx_log_debug(log, "iocp ev: %08x" _ ev) switch (key) { case NGX_IOCP_IO: ev->ready = 1; - ev->available = bytes; break; case NGX_IOCP_ACCEPT: + if (bytes) { + ev->ready = 1; + } break; } + ev->available = bytes; + ngx_log_debug(log, "iocp ev handler: %08x" _ ev->event_handler); ev->event_handler(ev); @@ -203,6 +232,8 @@ static void *ngx_iocp_create_conf(ngx_po NGX_CONF_ERROR); cf->threads = NGX_CONF_UNSET; + cf->acceptex = NGX_CONF_UNSET; + cf->acceptex_read = NGX_CONF_UNSET; return cf; } @@ -213,6 +244,8 @@ static char *ngx_iocp_init_conf(ngx_pool ngx_iocp_conf_t *cf = conf; ngx_conf_init_value(cf->threads, 0); + ngx_conf_init_value(cf->acceptex, 10); + ngx_conf_init_value(cf->acceptex_read, 1); return NGX_CONF_OK; }