aboutsummaryrefslogtreecommitdiff
path: root/src/event/modules
diff options
context:
space:
mode:
Diffstat (limited to 'src/event/modules')
-rw-r--r--src/event/modules/ngx_devpoll_module.c34
-rw-r--r--src/event/modules/ngx_epoll_module.c55
-rw-r--r--src/event/modules/ngx_poll_module.c39
3 files changed, 82 insertions, 46 deletions
diff --git a/src/event/modules/ngx_devpoll_module.c b/src/event/modules/ngx_devpoll_module.c
index 34775f2b1..aa61df7de 100644
--- a/src/event/modules/ngx_devpoll_module.c
+++ b/src/event/modules/ngx_devpoll_module.c
@@ -310,7 +310,7 @@ static int ngx_devpoll_set_event(ngx_event_t *ev, int event, u_int flags)
int ngx_devpoll_process_events(ngx_cycle_t *cycle)
{
- int events;
+ int events, revents;
ngx_int_t i;
ngx_uint_t j, lock, accept_lock, expire;
size_t n;
@@ -463,30 +463,40 @@ int ngx_devpoll_process_events(ngx_cycle_t *cycle)
}
#endif
+ revents = event_list[i].revents;
+
ngx_log_debug3(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
"devpoll: fd:%d, ev:%04Xd, rev:%04Xd",
- event_list[i].fd,
- event_list[i].events, event_list[i].revents);
+ event_list[i].fd, event_list[i].events, revents);
- if (event_list[i].revents & (POLLERR|POLLHUP|POLLNVAL)) {
+ if (revents & (POLLERR|POLLHUP|POLLNVAL)) {
ngx_log_error(NGX_LOG_ALERT, cycle->log, 0,
"ioctl(DP_POLL) error fd:%d ev:%04Xd rev:%04Xd",
- event_list[i].fd,
- event_list[i].events, event_list[i].revents);
+ event_list[i].fd, event_list[i].events, revents);
}
- if (event_list[i].revents & ~(POLLIN|POLLOUT|POLLERR|POLLHUP|POLLNVAL))
- {
+ if (revents & ~(POLLIN|POLLOUT|POLLERR|POLLHUP|POLLNVAL)) {
ngx_log_error(NGX_LOG_ALERT, cycle->log, 0,
"strange ioctl(DP_POLL) events "
"fd:%d ev:%04Xd rev:%04Xd",
- event_list[i].fd,
- event_list[i].events, event_list[i].revents);
+ event_list[i].fd, event_list[i].events, revents);
+ }
+
+ if ((revents & (POLLERR|POLLHUP|POLLNVAL))
+ && (revents & (POLLIN|POLLOUT)) == 0)
+ {
+ /*
+ * if the error events were returned without POLLIN or POLLOUT,
+ * then add these flags to handle the events at least in one
+ * active handler
+ */
+
+ revents |= POLLIN|POLLOUT;
}
wev = c->write;
- if ((event_list[i].events & (POLLOUT|POLLERR|POLLHUP)) && wev->active) {
+ if ((revents & POLLOUT) && wev->active) {
wev->ready = 1;
if (!ngx_threaded && !ngx_accept_mutex_held) {
@@ -505,7 +515,7 @@ int ngx_devpoll_process_events(ngx_cycle_t *cycle)
rev = c->read;
- if ((event_list[i].events & (POLLIN|POLLERR|POLLHUP)) && rev->active) {
+ if ((revents & POLLIN) && rev->active) {
rev->ready = 1;
if (!ngx_threaded && !ngx_accept_mutex_held) {
diff --git a/src/event/modules/ngx_epoll_module.c b/src/event/modules/ngx_epoll_module.c
index 907d6aeb5..af2781851 100644
--- a/src/event/modules/ngx_epoll_module.c
+++ b/src/event/modules/ngx_epoll_module.c
@@ -198,37 +198,40 @@ 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;
+ int op;
+ uint32_t events, prev;
ngx_event_t *e;
ngx_connection_t *c;
struct epoll_event ee;
c = ev->data;
+ events = (uint32_t) event;
+
if (event == NGX_READ_EVENT) {
e = c->write;
prev = EPOLLOUT;
#if (NGX_READ_EVENT != EPOLLIN)
- event = EPOLLIN;
+ events = EPOLLIN;
#endif
} else {
e = c->read;
prev = EPOLLIN;
#if (NGX_WRITE_EVENT != EPOLLOUT)
- event = EPOLLOUT;
+ events = EPOLLOUT;
#endif
}
if (e->active) {
op = EPOLL_CTL_MOD;
- event |= prev;
+ events |= prev;
} else {
op = EPOLL_CTL_ADD;
}
- ee.events = event | flags;
+ ee.events = events | flags;
ee.data.u64 = (uintptr_t) c | ev->instance;
ngx_log_debug3(NGX_LOG_DEBUG_EVENT, ev->log, 0,
@@ -252,14 +255,15 @@ 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;
+ int op;
+ uint32_t 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
+ * 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
*/
@@ -370,6 +374,7 @@ int ngx_epoll_process_events(ngx_cycle_t *cycle)
{
int events;
size_t n;
+ uint32_t revents;
ngx_int_t instance, i;
ngx_uint_t lock, accept_lock, expire;
ngx_err_t err;
@@ -521,27 +526,40 @@ int ngx_epoll_process_events(ngx_cycle_t *cycle)
log = c->log ? c->log : cycle->log;
#endif
+ revents = event_list[i].events;
+
ngx_log_debug3(NGX_LOG_DEBUG_EVENT, log, 0,
"epoll: fd:%d ev:%04XD d:%p",
- c->fd, event_list[i].events, event_list[i].data);
+ c->fd, revents, event_list[i].data);
- if (event_list[i].events & (EPOLLERR|EPOLLHUP)) {
+ if (revents & (EPOLLERR|EPOLLHUP)) {
ngx_log_debug2(NGX_LOG_DEBUG_EVENT, log, 0,
"epoll_wait() error on fd:%d ev:%04XD",
- c->fd, event_list[i].events);
+ c->fd, revents);
}
- if (event_list[i].events & ~(EPOLLIN|EPOLLOUT|EPOLLERR|EPOLLHUP)) {
+ if (revents & ~(EPOLLIN|EPOLLOUT|EPOLLERR|EPOLLHUP)) {
ngx_log_error(NGX_LOG_ALERT, log, 0,
"strange epoll_wait() events fd:%d ev:%04XD",
- c->fd, event_list[i].events);
+ c->fd, revents);
+ }
+
+ if ((revents & (EPOLLERR|EPOLLHUP))
+ && (revents & (EPOLLIN|EPOLLOUT)) == 0)
+ {
+ /*
+ * if the error events were returned without EPOLLIN or EPOLLOUT,
+ * then add these flags to handle the events at least in one
+ * active handler
+ */
+
+ revents |= EPOLLIN|EPOLLOUT;
}
wev = c->write;
- if ((event_list[i].events & (EPOLLOUT|EPOLLERR|EPOLLHUP))
- && wev->active)
- {
+ if ((revents & EPOLLOUT) && wev->active) {
+
if (ngx_threaded) {
wev->posted_ready = 1;
ngx_post_event(wev);
@@ -564,9 +582,8 @@ int ngx_epoll_process_events(ngx_cycle_t *cycle)
* if the accept event is the last one.
*/
- if ((event_list[i].events & (EPOLLIN|EPOLLERR|EPOLLHUP))
- && rev->active)
- {
+ if ((revents & EPOLLIN) && rev->active) {
+
if (ngx_threaded && !rev->accept) {
rev->posted_ready = 1;
diff --git a/src/event/modules/ngx_poll_module.c b/src/event/modules/ngx_poll_module.c
index 18f72c3b5..12726b58d 100644
--- a/src/event/modules/ngx_poll_module.c
+++ b/src/event/modules/ngx_poll_module.c
@@ -262,7 +262,7 @@ static ngx_int_t ngx_poll_del_event(ngx_event_t *ev, int event, u_int flags)
static ngx_int_t ngx_poll_process_events(ngx_cycle_t *cycle)
{
- int ready;
+ int ready, revents;
ngx_int_t i, nready;
ngx_uint_t n, found, lock, expire;
ngx_msec_t timer;
@@ -378,33 +378,30 @@ static ngx_int_t ngx_poll_process_events(ngx_cycle_t *cycle)
for (i = 0; i < nevents && ready; i++) {
+ revents = event_list[i].revents;
+
#if 0
ngx_log_debug4(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
"poll: %d: fd:%d ev:%04Xd rev:%04Xd",
- i, event_list[i].fd,
- event_list[i].events, event_list[i].revents);
+ i, event_list[i].fd, event_list[i].events, revents);
#else
- if (event_list[i].revents) {
+ if (revents) {
ngx_log_debug4(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
"poll: %d: fd:%d ev:%04Xd rev:%04Xd",
- i, event_list[i].fd,
- event_list[i].events, event_list[i].revents);
+ i, event_list[i].fd, event_list[i].events, revents);
}
#endif
- if (event_list[i].revents & POLLNVAL) {
+ if (revents & POLLNVAL) {
ngx_log_error(NGX_LOG_ALERT, cycle->log, 0,
"poll() error fd:%d ev:%04Xd rev:%04Xd",
- event_list[i].fd,
- event_list[i].events, event_list[i].revents);
+ event_list[i].fd, event_list[i].events, revents);
}
- if (event_list[i].revents & ~(POLLIN|POLLOUT|POLLERR|POLLHUP|POLLNVAL))
- {
+ if (revents & ~(POLLIN|POLLOUT|POLLERR|POLLHUP|POLLNVAL)) {
ngx_log_error(NGX_LOG_ALERT, cycle->log, 0,
"strange poll() events fd:%d ev:%04Xd rev:%04Xd",
- event_list[i].fd,
- event_list[i].events, event_list[i].revents);
+ event_list[i].fd, event_list[i].events, revents);
}
if (event_list[i].fd == -1) {
@@ -447,9 +444,21 @@ static ngx_int_t ngx_poll_process_events(ngx_cycle_t *cycle)
continue;
}
+ if ((revents & (POLLERR|POLLHUP|POLLNVAL))
+ && (revents & (POLLIN|POLLOUT)) == 0)
+ {
+ /*
+ * if the error events were returned without POLLIN or POLLOUT,
+ * then add these flags to handle the events at least in one
+ * active handler
+ */
+
+ revents |= POLLIN|POLLOUT;
+ }
+
found = 0;
- if (event_list[i].revents & (POLLIN|POLLERR|POLLHUP|POLLNVAL)) {
+ if (revents & POLLIN) {
found = 1;
ev = c->read;
@@ -474,7 +483,7 @@ static ngx_int_t ngx_poll_process_events(ngx_cycle_t *cycle)
#endif
}
- if (event_list[i].revents & (POLLOUT|POLLERR|POLLHUP|POLLNVAL)) {
+ if (revents & POLLOUT) {
found = 1;
ev = c->write;
ev->ready = 1;