diff options
| author | Igor Sysoev <igor@sysoev.ru> | 2004-02-12 20:57:10 +0000 |
|---|---|---|
| committer | Igor Sysoev <igor@sysoev.ru> | 2004-02-12 20:57:10 +0000 |
| commit | 7b6062a1b8f1f5d1b56deaad17aacde6f97b58c5 (patch) | |
| tree | 12dbd16539d541373dc5933e5e9835a80309704d /src/event/modules | |
| parent | dfe63ad1833a8d6d9398371ba595a1d8a19d6148 (diff) | |
| download | nginx-7b6062a1b8f1f5d1b56deaad17aacde6f97b58c5.tar.gz nginx-7b6062a1b8f1f5d1b56deaad17aacde6f97b58c5.tar.bz2 | |
nginx-0.0.2-2004-02-12-23:57:10 import
Diffstat (limited to 'src/event/modules')
| -rw-r--r-- | src/event/modules/ngx_epoll_module.c | 99 | ||||
| -rw-r--r-- | src/event/modules/ngx_kqueue_module.c | 2 | ||||
| -rw-r--r-- | src/event/modules/ngx_poll_module.c | 15 |
3 files changed, 87 insertions, 29 deletions
diff --git a/src/event/modules/ngx_epoll_module.c b/src/event/modules/ngx_epoll_module.c index 111432b91..0b2b7d258 100644 --- a/src/event/modules/ngx_epoll_module.c +++ b/src/event/modules/ngx_epoll_module.c @@ -111,8 +111,8 @@ ngx_event_module_t ngx_epoll_module_ctx = { ngx_epoll_del_event, /* delete an event */ ngx_epoll_add_event, /* enable an event */ ngx_epoll_del_event, /* disable an event */ - ngx_epoll_add_connection, /* add an connection */ - ngx_epoll_del_connection, /* delete an connection */ + NULL, /* add an connection */ + NULL, /* delete an connection */ ngx_epoll_process_events, /* process the events */ ngx_epoll_init, /* init the events */ ngx_epoll_done, /* done the events */ @@ -167,7 +167,11 @@ static int ngx_epoll_init(ngx_cycle_t *cycle) ngx_event_actions = ngx_epoll_module_ctx.actions; - ngx_event_flags = NGX_USE_EDGE_EVENT; +#if (HAVE_CLEAR_EVENT) + ngx_event_flags = NGX_USE_CLEAR_EVENT; +#else + ngx_event_flags = NGX_USE_LEVEL_EVENT; +#endif return NGX_OK; } @@ -191,33 +195,53 @@ static void ngx_epoll_done(ngx_cycle_t *cycle) static int ngx_epoll_add_event(ngx_event_t *ev, int event, u_int flags) { - struct epoll_event ee; + int op, prev; + ngx_event_t *e; ngx_connection_t *c; + struct epoll_event ee; c = ev->data; -#if (NGX_READ_EVENT != EPOLLIN) || (NGX_WRITE_EVENT != EPOLLOUT) if (event == NGX_READ_EVENT) { + e = c->write; + prev = EPOLLOUT; +#if (NGX_READ_EVENT != EPOLLIN) event = EPOLLIN; +#endif } else { + e = c->read; + prev = EPOLLIN; +#if (NGX_WRITE_EVENT != EPOLLOUT) event = EPOLLOUT; - } #endif + } - ee.events = event|EPOLLET; - ee.data.ptr = (void *) ((uintptr_t) c | c->read->instance); + if (e->active) { + op = EPOLL_CTL_MOD; + event |= prev; - ngx_log_debug2(NGX_LOG_DEBUG_EVENT, c->log, 0, - "epoll add event: fd:%d ev:%08X", c->fd, ee.events); + } else { + op = EPOLL_CTL_ADD; + } - if (epoll_ctl(ep, EPOLL_CTL_ADD, c->fd, &ee) == -1) { - ngx_log_error(NGX_LOG_ALERT, c->log, ngx_errno, - "epoll_ctl(EPOLL_CTL_MOD, %d) failed", c->fd); + ee.events = event | flags; + ee.data.ptr = (void *) ((uintptr_t) c | ev->instance); + + ngx_log_debug3(NGX_LOG_DEBUG_EVENT, ev->log, 0, + "epoll add event: fd:%d op:%d ev:%08X", + c->fd, op, ee.events); + + if (epoll_ctl(ep, op, c->fd, &ee) == -1) { + ngx_log_error(NGX_LOG_ALERT, ev->log, ngx_errno, + "epoll_ctl(%d, %d) failed", op, c->fd); return NGX_ERROR; } ev->active = 1; +#if 0 + ev->oneshot = (flags & NGX_ONESHOT_EVENT) ? 1 : 0; +#endif return NGX_OK; } @@ -225,20 +249,51 @@ static int ngx_epoll_add_event(ngx_event_t *ev, int event, u_int flags) static int ngx_epoll_del_event(ngx_event_t *ev, int event, u_int flags) { - struct epoll_event ee; + int op, prev; + ngx_event_t *e; ngx_connection_t *c; + struct epoll_event ee; + + /* + * when the file descriptor is closed the epoll automatically deletes + * it from its queue so we do not need to delete explicity the event + * before the closing the file descriptor. + */ + + if (flags & NGX_CLOSE_EVENT) { + ev->active = 0; + return NGX_OK; + } c = ev->data; - ee.events = 0; - ee.data.ptr = NULL; + if (event == NGX_READ_EVENT) { + e = c->write; + prev = EPOLLOUT; - ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, - "epoll del event: fd:%d", c->fd); + } else { + e = c->read; + prev = EPOLLIN; + } - if (epoll_ctl(ep, EPOLL_CTL_DEL, c->fd, &ee) == -1) { - ngx_log_error(NGX_LOG_ALERT, c->log, ngx_errno, - "epoll_ctl(EPOLL_CTL_MOD, %d) failed", c->fd); + if (e->active) { + op = EPOLL_CTL_MOD; + ee.events = prev | flags; + ee.data.ptr = (void *) ((uintptr_t) c | ev->instance); + + } else { + op = EPOLL_CTL_DEL; + ee.events = 0; + ee.data.ptr = NULL; + } + + ngx_log_debug3(NGX_LOG_DEBUG_EVENT, ev->log, 0, + "epoll del event: fd:%d op:%d ev:%08X", + c->fd, op, ee.events); + + if (epoll_ctl(ep, op, c->fd, &ee) == -1) { + ngx_log_error(NGX_LOG_ALERT, ev->log, ngx_errno, + "epoll_ctl(%d, %d) failed", op, c->fd); return NGX_ERROR; } @@ -248,6 +303,7 @@ static int ngx_epoll_del_event(ngx_event_t *ev, int event, u_int flags) } +#if 0 static int ngx_epoll_add_connection(ngx_connection_t *c) { struct epoll_event ee; @@ -278,6 +334,7 @@ static int ngx_epoll_del_connection(ngx_connection_t *c) return NGX_OK; } +#endif int ngx_epoll_process_events(ngx_log_t *log) diff --git a/src/event/modules/ngx_kqueue_module.c b/src/event/modules/ngx_kqueue_module.c index 28966feb2..6f0688428 100644 --- a/src/event/modules/ngx_kqueue_module.c +++ b/src/event/modules/ngx_kqueue_module.c @@ -254,7 +254,7 @@ static int ngx_kqueue_del_event(ngx_event_t *ev, int event, u_int flags) } /* - * when the file descriptor is closed a kqueue automatically deletes + * when the file descriptor is closed the kqueue automatically deletes * its filters so we do not need to delete explicity the event * before the closing the file descriptor. */ diff --git a/src/event/modules/ngx_poll_module.c b/src/event/modules/ngx_poll_module.c index dfc66cb76..9c5f8e12f 100644 --- a/src/event/modules/ngx_poll_module.c +++ b/src/event/modules/ngx_poll_module.c @@ -146,7 +146,7 @@ static int ngx_poll_add_event(ngx_event_t *ev, int event, u_int flags) } else { ngx_log_debug1(NGX_LOG_DEBUG_EVENT, ev->log, 0, - "poll index: %d", e->index); + "poll add index: %d", e->index); event_list[e->index].events |= event; ev->index = e->index; @@ -195,6 +195,10 @@ static int ngx_poll_del_event(ngx_event_t *ev, int event, u_int flags) nevents--; if (ev->index < (u_int) nevents) { + + ngx_log_debug2(NGX_LOG_DEBUG_EVENT, ev->log, 0, + "index: copy event %d to %d", nevents, ev->index); + event_list[ev->index] = event_list[nevents]; c = &ngx_cycle->connections[event_list[nevents].fd]; @@ -219,20 +223,17 @@ static int ngx_poll_del_event(ngx_event_t *ev, int event, u_int flags) } else { if (c->read->index == (u_int) nevents) { c->read->index = ev->index; + } - } else if (c->write->index == (u_int) nevents) { + if (c->write->index == (u_int) nevents) { c->write->index = ev->index; - - } else { - ngx_log_error(NGX_LOG_ALERT, ev->log, 0, - "unexpected last event index"); } } } } else { ngx_log_debug1(NGX_LOG_DEBUG_EVENT, ev->log, 0, - "poll index: %d", e->index); + "poll del index: %d", e->index); event_list[e->index].events &= ~event; } |
