diff options
| author | Igor Sysoev <igor@sysoev.ru> | 2004-02-11 17:08:49 +0000 |
|---|---|---|
| committer | Igor Sysoev <igor@sysoev.ru> | 2004-02-11 17:08:49 +0000 |
| commit | 54498db7a2a2e7e74fba61ec073b248da05e999e (patch) | |
| tree | 7e5bda151896efa349f2220fc122ba9792ce5dfb /src/event | |
| parent | c7a2f6860669f45f5abe342163de5bc68e344816 (diff) | |
| download | nginx-54498db7a2a2e7e74fba61ec073b248da05e999e.tar.gz nginx-54498db7a2a2e7e74fba61ec073b248da05e999e.tar.bz2 | |
nginx-0.0.2-2004-02-11-20:08:49 import
Diffstat (limited to 'src/event')
| -rw-r--r-- | src/event/modules/ngx_aio_module.c | 2 | ||||
| -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/ngx_event.c | 5 | ||||
| -rw-r--r-- | src/event/ngx_event.h | 28 | ||||
| -rw-r--r-- | src/event/ngx_event_accept.c | 32 | ||||
| -rw-r--r-- | src/event/ngx_event_connect.c | 17 | ||||
| -rw-r--r-- | src/event/ngx_event_pipe.c | 36 |
8 files changed, 169 insertions, 52 deletions
diff --git a/src/event/modules/ngx_aio_module.c b/src/event/modules/ngx_aio_module.c index 4ca53714b..2f9c09b21 100644 --- a/src/event/modules/ngx_aio_module.c +++ b/src/event/modules/ngx_aio_module.c @@ -106,7 +106,7 @@ static int ngx_aio_del_connection(ngx_connection_t *c) rc = aio_cancel(c->fd, NULL); - ngx_log_debug(c->log, "aio_cancel: %d" _ rc); + ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, "aio_cancel: %d", rc); if (rc == AIO_CANCELED) { c->read->active = c->write->active = 0; 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/ngx_event.c b/src/event/ngx_event.c index c2d24e55b..8d3b06502 100644 --- a/src/event/ngx_event.c +++ b/src/event/ngx_event.c @@ -19,6 +19,11 @@ extern ngx_module_t ngx_devpoll_module; extern ngx_event_module_t ngx_devpoll_module_ctx; #endif +#if (HAVE_EPOLL) +extern ngx_module_t ngx_epoll_module; +extern ngx_event_module_t ngx_epoll_module_ctx; +#endif + #if (HAVE_AIO) #include <ngx_aio_module.h> #endif diff --git a/src/event/ngx_event.h b/src/event/ngx_event.h index a2c1e9cb6..493f8d1f7 100644 --- a/src/event/ngx_event.h +++ b/src/event/ngx_event.h @@ -176,18 +176,19 @@ extern ngx_event_actions_t ngx_event_actions; /* * The event filter requires to read/write the whole data - - * select, poll, /dev/poll, kqueue. + * select, poll, /dev/poll, kqueue, epoll. */ #define NGX_USE_LEVEL_EVENT 0x00000001 /* * The event filter is deleted after a notification without an additional - * syscall - select, poll, kqueue. + * syscall - select, poll, kqueue, epoll. */ #define NGX_USE_ONESHOT_EVENT 0x00000002 /* - * The event filter notifies only the changes and an initial level - kqueue. + * The event filter notifies only the changes and an initial level - + * kqueue, epoll. */ #define NGX_USE_CLEAR_EVENT 0x00000004 @@ -205,7 +206,7 @@ extern ngx_event_actions_t ngx_event_actions; /* * The event filter notifies only the changes (the edges) - * but not an initial level - epoll. + * but not an initial level - early epoll patches. */ #define NGX_USE_EDGE_EVENT 0x00000020 @@ -275,21 +276,34 @@ extern ngx_event_actions_t ngx_event_actions; #define NGX_DISABLE_EVENT EV_DISABLE -#elif (HAVE_POLL) +#elif (HAVE_DEVPOLL) #define NGX_READ_EVENT POLLIN #define NGX_WRITE_EVENT POLLOUT #define NGX_LEVEL_EVENT 0 -#define NGX_ONESHOT_EVENT 1 -#elif (HAVE_DEVPOLL) +#elif (HAVE_EPOLL) + +#define NGX_READ_EVENT EPOLLIN +#define NGX_WRITE_EVENT EPOLLOUT + +#define NGX_LEVEL_EVENT 0 +#define NGX_CLEAR_EVENT EPOLLET +#define NGX_ONESHOT_EVENT 0x70000000 +#if 0 +#define NGX_ONESHOT_EVENT EPOLLONESHOT +#endif + + +#elif (HAVE_POLL) #define NGX_READ_EVENT POLLIN #define NGX_WRITE_EVENT POLLOUT #define NGX_LEVEL_EVENT 0 +#define NGX_ONESHOT_EVENT 1 #else /* select */ diff --git a/src/event/ngx_event_accept.c b/src/event/ngx_event_accept.c index cbd92a2fe..fa1323dd0 100644 --- a/src/event/ngx_event_accept.c +++ b/src/event/ngx_event_accept.c @@ -5,6 +5,12 @@ #include <nginx.h> +typedef struct { + int flag; + char *name; +} ngx_accept_log_ctx_t; + + static size_t ngx_accept_log_error(void *data, char *buf, size_t len); @@ -20,6 +26,7 @@ void ngx_event_accept(ngx_event_t *ev) ngx_event_t *rev, *wev; ngx_connection_t *c, *ls; ngx_event_conf_t *ecf; + ngx_accept_log_ctx_t *ctx; ecf = ngx_event_get_conf(ngx_cycle->conf_ctx, ngx_event_core_module); @@ -32,9 +39,9 @@ void ngx_event_accept(ngx_event_t *ev) ls = ev->data; - ngx_log_debug(ev->log, "accept on %s ready: %d" _ - ls->listening->addr_text.data _ - ev->available); + ngx_log_debug2(NGX_LOG_DEBUG_EVENT, ev->log, 0, + "accept on %s, ready: %d", + ls->listening->addr_text.data, ev->available); ev->ready = 0; accepted = 0; @@ -68,7 +75,16 @@ void ngx_event_accept(ngx_event_t *ev) ngx_memcpy(log, ls->log, sizeof(ngx_log_t)); pool->log = log; - log->data = ls->listening->addr_text.data; + if (!(ctx = ngx_palloc(pool, sizeof(ngx_accept_log_ctx_t)))) { + ngx_destroy_pool(pool); + return; + } + + /* -1 disable logging the connection number */ + ctx->flag = -1; + ctx->name = ls->listening->addr_text.data; + + log->data = ctx; log->handler = ngx_accept_log_error; len = ls->listening->socklen; @@ -233,8 +249,8 @@ void ngx_event_accept(ngx_event_t *ev) wev->log = log; /* - * In the multithreaded model the connection counter is updated by - * the main thread only that accept()s connections. + * TODO: MT: - atomic increment (x86: lock xadd) + * or protection by critical section or mutex * * TODO: MP: - allocated in a shared memory * - atomic increment (x86: lock xadd) @@ -279,7 +295,7 @@ void ngx_event_accept(ngx_event_t *ev) static size_t ngx_accept_log_error(void *data, char *buf, size_t len) { - char *sock = data; + ngx_accept_log_ctx_t *ctx = data; - return ngx_snprintf(buf, len, " while accept() on %s", sock); + return ngx_snprintf(buf, len, " while accept() on %s", ctx->name); } diff --git a/src/event/ngx_event_connect.c b/src/event/ngx_event_connect.c index 7884cd8b6..b11ccd4ef 100644 --- a/src/event/ngx_event_connect.c +++ b/src/event/ngx_event_connect.c @@ -3,6 +3,7 @@ #include <ngx_core.h> #include <ngx_event.h> #include <ngx_event_connect.h> +#include <nginx.h> /* AF_INET only */ @@ -180,6 +181,17 @@ int ngx_event_connect_peer(ngx_peer_connection_t *pc) pc->connection = c; + /* + * TODO: MT: - atomic increment (x86: lock xadd) + * or protection by critical section or mutex + * + * TODO: MP: - allocated in a shared memory + * - atomic increment (x86: lock xadd) + * or protection by critical section or mutex + */ + + c->number = ngx_connection_counter++; + if (ngx_add_conn) { if (ngx_add_conn(c) == NGX_ERROR) { return NGX_ERROR; @@ -192,7 +204,8 @@ int ngx_event_connect_peer(ngx_peer_connection_t *pc) addr.sin_port = peer->port; addr.sin_addr.s_addr = peer->addr; -ngx_log_debug(pc->log, "CONNECT: %s" _ peer->addr_port_text.data); + ngx_log_debug1(NGX_LOG_DEBUG_EVENT, pc->log, 0, + "connect to %s", peer->addr_port_text.data); rc = connect(s, (struct sockaddr *) &addr, sizeof(struct sockaddr_in)); @@ -269,7 +282,7 @@ ngx_log_debug(pc->log, "CONNECT: %s" _ peer->addr_port_text.data); return NGX_AGAIN; } -ngx_log_debug(pc->log, "CONNECTED"); + ngx_log_debug0(NGX_LOG_DEBUG_EVENT, pc->log, 0, "connected"); wev->ready = 1; diff --git a/src/event/ngx_event_pipe.c b/src/event/ngx_event_pipe.c index 5696cbce5..c5b15bda9 100644 --- a/src/event/ngx_event_pipe.c +++ b/src/event/ngx_event_pipe.c @@ -83,7 +83,8 @@ int ngx_event_pipe_read_upstream(ngx_event_pipe_t *p) return NGX_OK; } - ngx_log_debug(p->log, "read upstream: %d" _ p->upstream->read->ready); + ngx_log_debug1(NGX_LOG_DEBUG_EVENT, p->log, 0, + "pipe read upstream: %d", p->upstream->read->ready); for ( ;; ) { @@ -104,7 +105,8 @@ int ngx_event_pipe_read_upstream(ngx_event_pipe_t *p) p->preread_hunks = NULL; n = p->preread_size; - ngx_log_debug(p->log, "preread: %d" _ n); + ngx_log_debug1(NGX_LOG_DEBUG_EVENT, p->log, 0, + "pipe preread: %d", n); } else { @@ -169,7 +171,8 @@ int ngx_event_pipe_read_upstream(ngx_event_pipe_t *p) p->upstream_blocked = 1; - ngx_log_debug(p->log, "downstream ready"); + ngx_log_debug0(NGX_LOG_DEBUG_EVENT, p->log, 0, + "pipe downstream ready"); break; @@ -184,7 +187,8 @@ int ngx_event_pipe_read_upstream(ngx_event_pipe_t *p) rc = ngx_event_pipe_write_chain_to_temp_file(p); - ngx_log_debug(p->log, "temp offset: %d" _ p->temp_file->offset); + ngx_log_debug1(NGX_LOG_DEBUG_EVENT, p->log, 0, + "pipe temp offset: %d", p->temp_file->offset); if (rc == NGX_AGAIN) { if (ngx_event_flags & NGX_USE_LEVEL_EVENT @@ -215,14 +219,16 @@ int ngx_event_pipe_read_upstream(ngx_event_pipe_t *p) /* if there're no hunks to read in then disable a level event */ - ngx_log_debug(p->log, "no hunks to read in"); + ngx_log_debug0(NGX_LOG_DEBUG_EVENT, p->log, 0, + "no pipe hunks to read in"); break; } n = ngx_recv_chain(p->upstream, chain); - ngx_log_debug(p->log, "recv_chain: %d" _ n); + ngx_log_debug1(NGX_LOG_DEBUG_EVENT, p->log, 0, + "pipe recv chain: %d", n); if (p->free_raw_hunks) { chain->next = p->free_raw_hunks; @@ -312,7 +318,8 @@ int ngx_event_pipe_write_to_downstream(ngx_event_pipe_t *p) ngx_hunk_t *h; ngx_chain_t *out, **ll, *cl, *tl; - ngx_log_debug(p->log, "write downstream: %d" _ p->downstream->write->ready); + ngx_log_debug1(NGX_LOG_DEBUG_EVENT, p->log, 0, + "pipe write downstream: %d", p->downstream->write->ready); for ( ;; ) { if (p->downstream_error) { @@ -383,7 +390,8 @@ int ngx_event_pipe_write_to_downstream(ngx_event_pipe_t *p) } if (out == NULL) { - ngx_log_debug(p->log, "no hunks to write BUSY: %d" _ to_write); + ngx_log_debug1(NGX_LOG_DEBUG_EVENT, p->log, 0, + "pipe busy hunk data: %d", to_write); if (!(p->upstream_blocked && to_write)) { break; @@ -472,12 +480,14 @@ static int ngx_event_pipe_write_chain_to_temp_file(ngx_event_pipe_t *p) cl = out; ll = NULL; -ngx_log_debug(p->log, "offset: %d" _ p->temp_file->offset); + ngx_log_debug1(NGX_LOG_DEBUG_EVENT, p->log, 0, + "pipe offset: %d", p->temp_file->offset); do { hsize = cl->hunk->last - cl->hunk->pos; -ngx_log_debug(p->log, "hunk size: %d" _ hsize); + ngx_log_debug1(NGX_LOG_DEBUG_EVENT, p->log, 0, + "pipe hunk size: %d", hsize); if ((size + hsize > p->temp_file_write_size) || (p->temp_file->offset + size + hsize > p->max_temp_file_size)) @@ -491,7 +501,7 @@ ngx_log_debug(p->log, "hunk size: %d" _ hsize); } while (cl); -ngx_log_debug(p->log, "size: %d" _ size); + ngx_log_debug1(NGX_LOG_DEBUG_EVENT, p->log, 0, "size: %d", size); if (cl) { p->in = cl; @@ -584,7 +594,9 @@ int ngx_event_pipe_copy_input_filter(ngx_event_pipe_t *p, ngx_hunk_t *hunk) hunk->shadow = h; ngx_alloc_link_and_set_hunk(cl, h, p->pool, NGX_ERROR); -ngx_log_debug(p->log, "HUNK %d" _ h->num); + + ngx_log_debug1(NGX_LOG_DEBUG_EVENT, p->log, 0, "hunk #%d", h->num); + ngx_chain_add_link(p->in, p->last_in, cl); return NGX_OK; |
