summaryrefslogtreecommitdiff
path: root/src/event
diff options
context:
space:
mode:
authorIgor Sysoev <igor@sysoev.ru>2004-02-11 07:19:26 +0000
committerIgor Sysoev <igor@sysoev.ru>2004-02-11 07:19:26 +0000
commitdfe63ad1833a8d6d9398371ba595a1d8a19d6148 (patch)
tree6e3d88fea11d0a4f35e0672937aa945b8f5d4916 /src/event
parent54498db7a2a2e7e74fba61ec073b248da05e999e (diff)
downloadnginx-dfe63ad1833a8d6d9398371ba595a1d8a19d6148.tar.gz
nginx-0.0.2-2004-02-11-10:19:26 import
Diffstat (limited to 'src/event')
-rw-r--r--src/event/modules/ngx_epoll_module.c99
-rw-r--r--src/event/modules/ngx_kqueue_module.c2
-rw-r--r--src/event/ngx_event.h28
-rw-r--r--src/event/ngx_event_close.c41
-rw-r--r--src/event/ngx_event_close.h10
5 files changed, 29 insertions, 151 deletions
diff --git a/src/event/modules/ngx_epoll_module.c b/src/event/modules/ngx_epoll_module.c
index 0b2b7d258..111432b91 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 */
- NULL, /* add an connection */
- NULL, /* delete an connection */
+ ngx_epoll_add_connection, /* add an connection */
+ ngx_epoll_del_connection, /* delete an connection */
ngx_epoll_process_events, /* process the events */
ngx_epoll_init, /* init the events */
ngx_epoll_done, /* done the events */
@@ -167,11 +167,7 @@ static int ngx_epoll_init(ngx_cycle_t *cycle)
ngx_event_actions = ngx_epoll_module_ctx.actions;
-#if (HAVE_CLEAR_EVENT)
- ngx_event_flags = NGX_USE_CLEAR_EVENT;
-#else
- ngx_event_flags = NGX_USE_LEVEL_EVENT;
-#endif
+ ngx_event_flags = NGX_USE_EDGE_EVENT;
return NGX_OK;
}
@@ -195,53 +191,33 @@ static void ngx_epoll_done(ngx_cycle_t *cycle)
static int ngx_epoll_add_event(ngx_event_t *ev, int event, u_int flags)
{
- int op, prev;
- ngx_event_t *e;
- ngx_connection_t *c;
struct epoll_event ee;
+ ngx_connection_t *c;
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
- }
-
- if (e->active) {
- op = EPOLL_CTL_MOD;
- event |= prev;
-
- } else {
- op = EPOLL_CTL_ADD;
}
+#endif
- ee.events = event | flags;
- ee.data.ptr = (void *) ((uintptr_t) c | ev->instance);
+ ee.events = event|EPOLLET;
+ ee.data.ptr = (void *) ((uintptr_t) c | c->read->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);
+ ngx_log_debug2(NGX_LOG_DEBUG_EVENT, c->log, 0,
+ "epoll add event: fd:%d ev:%08X", c->fd, 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);
+ 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);
return NGX_ERROR;
}
ev->active = 1;
-#if 0
- ev->oneshot = (flags & NGX_ONESHOT_EVENT) ? 1 : 0;
-#endif
return NGX_OK;
}
@@ -249,51 +225,20 @@ 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)
{
- 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;
- }
+ ngx_connection_t *c;
c = ev->data;
- if (event == NGX_READ_EVENT) {
- e = c->write;
- prev = EPOLLOUT;
+ ee.events = 0;
+ ee.data.ptr = NULL;
- } else {
- e = c->read;
- prev = EPOLLIN;
- }
+ ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0,
+ "epoll del event: fd:%d", 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);
+ 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);
return NGX_ERROR;
}
@@ -303,7 +248,6 @@ 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;
@@ -334,7 +278,6 @@ 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 6f0688428..28966feb2 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 the kqueue automatically deletes
+ * when the file descriptor is closed a 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.h b/src/event/ngx_event.h
index 493f8d1f7..a2c1e9cb6 100644
--- a/src/event/ngx_event.h
+++ b/src/event/ngx_event.h
@@ -176,19 +176,18 @@ extern ngx_event_actions_t ngx_event_actions;
/*
* The event filter requires to read/write the whole data -
- * select, poll, /dev/poll, kqueue, epoll.
+ * select, poll, /dev/poll, kqueue.
*/
#define NGX_USE_LEVEL_EVENT 0x00000001
/*
* The event filter is deleted after a notification without an additional
- * syscall - select, poll, kqueue, epoll.
+ * syscall - select, poll, kqueue.
*/
#define NGX_USE_ONESHOT_EVENT 0x00000002
/*
- * The event filter notifies only the changes and an initial level -
- * kqueue, epoll.
+ * The event filter notifies only the changes and an initial level - kqueue.
*/
#define NGX_USE_CLEAR_EVENT 0x00000004
@@ -206,7 +205,7 @@ extern ngx_event_actions_t ngx_event_actions;
/*
* The event filter notifies only the changes (the edges)
- * but not an initial level - early epoll patches.
+ * but not an initial level - epoll.
*/
#define NGX_USE_EDGE_EVENT 0x00000020
@@ -276,34 +275,21 @@ extern ngx_event_actions_t ngx_event_actions;
#define NGX_DISABLE_EVENT EV_DISABLE
-#elif (HAVE_DEVPOLL)
+#elif (HAVE_POLL)
#define NGX_READ_EVENT POLLIN
#define NGX_WRITE_EVENT POLLOUT
#define NGX_LEVEL_EVENT 0
+#define NGX_ONESHOT_EVENT 1
-#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)
+#elif (HAVE_DEVPOLL)
#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_close.c b/src/event/ngx_event_close.c
deleted file mode 100644
index c57c19560..000000000
--- a/src/event/ngx_event_close.c
+++ /dev/null
@@ -1,41 +0,0 @@
-
-#include <ngx_config.h>
-#include <ngx_core.h>
-#include <ngx_types.h>
-#include <ngx_connection.h>
-#include <ngx_event.h>
-#include <ngx_event_timer.h>
-#include <ngx_event_close.h>
-
-
-int ngx_event_close_connection(ngx_event_t *ev)
-{
- int rc;
- ngx_connection_t *c = (ngx_connection_t *) ev->data;
-
- ngx_log_debug(c->log, "close connection: %d" _ c->fd);
-
- ngx_assert((c->fd != -1), return NGX_ERROR, c->log,
- "ngx_event_close: already closed");
-
- if (c->read->timer_set) {
- ngx_del_timer(c->read);
- }
-
- if (c->write->timer_set) {
- ngx_del_timer(c->write);
- }
-
- ngx_del_event(c->read, NGX_READ_EVENT, NGX_CLOSE_EVENT);
- ngx_del_event(c->write, NGX_WRITE_EVENT, NGX_CLOSE_EVENT);
-
- if ((rc = ngx_close_socket(c->fd)) == -1)
- ngx_log_error(NGX_LOG_ALERT, c->log, ngx_socket_errno,
- "ngx_event_close: close failed");
-
- c->fd = -1;
-
- ngx_destroy_pool(c->pool);
-
- return rc;
-}
diff --git a/src/event/ngx_event_close.h b/src/event/ngx_event_close.h
deleted file mode 100644
index 54a048df4..000000000
--- a/src/event/ngx_event_close.h
+++ /dev/null
@@ -1,10 +0,0 @@
-#ifndef _NGX_EVENT_CLOSE_H_INCLUDED_
-#define _NGX_EVENT_CLOSE_H_INCLUDED_
-
-
-#include <ngx_event.h>
-
-int ngx_event_close_connection(ngx_event_t *ev);
-
-
-#endif /* _NGX_EVENT_CLOSE_H_INCLUDED_ */