diff options
Diffstat (limited to 'poll/unix/epoll.c')
-rw-r--r-- | poll/unix/epoll.c | 43 |
1 files changed, 26 insertions, 17 deletions
diff --git a/poll/unix/epoll.c b/poll/unix/epoll.c index fe006db013c0c..4ab03f67ccc17 100644 --- a/poll/unix/epoll.c +++ b/poll/unix/epoll.c @@ -157,7 +157,7 @@ static apr_status_t impl_pollset_add(apr_pollset_t *pollset, const apr_pollfd_t *descriptor) { struct epoll_event ev = {0}; - int ret = -1; + int ret; pfd_elem_t *elem = NULL; apr_status_t rv = APR_SUCCESS; @@ -214,7 +214,7 @@ static apr_status_t impl_pollset_remove(apr_pollset_t *pollset, struct epoll_event ev = {0}; /* ignored, but must be passed with * kernel < 2.6.9 */ - int ret = -1; + int ret; if (descriptor->desc_type == APR_POLL_SOCKET) { ret = epoll_ctl(pollset->p->epoll_fd, EPOLL_CTL_DEL, @@ -255,9 +255,10 @@ static apr_status_t impl_pollset_poll(apr_pollset_t *pollset, apr_int32_t *num, const apr_pollfd_t **descriptors) { - int ret, i, j; + int ret; apr_status_t rv = APR_SUCCESS; - apr_pollfd_t *fdptr; + + *num = 0; if (timeout > 0) { timeout /= 1000; @@ -265,8 +266,6 @@ static apr_status_t impl_pollset_poll(apr_pollset_t *pollset, ret = epoll_wait(pollset->p->epoll_fd, pollset->p->pollset, pollset->nalloc, timeout); - (*num) = ret; - if (ret < 0) { rv = apr_get_netos_error(); } @@ -274,6 +273,9 @@ static apr_status_t impl_pollset_poll(apr_pollset_t *pollset, rv = APR_TIMEUP; } else { + int i, j; + const apr_pollfd_t *fdptr; + for (i = 0, j = 0; i < ret; i++) { if (pollset->flags & APR_POLLSET_NOCOPY) { fdptr = (apr_pollfd_t *)(pollset->p->pollset[i].data.ptr); @@ -287,7 +289,7 @@ static apr_status_t impl_pollset_poll(apr_pollset_t *pollset, if ((pollset->flags & APR_POLLSET_WAKEABLE) && fdptr->desc_type == APR_POLL_FILE && fdptr->desc.f == pollset->wakeup_pipe[0]) { - apr_pollset_drain_wakeup_pipe(pollset); + apr_poll_drain_wakeup_pipe(pollset->wakeup_pipe); rv = APR_EINTR; } else { @@ -318,7 +320,7 @@ static apr_status_t impl_pollset_poll(apr_pollset_t *pollset, return rv; } -static apr_pollset_provider_t impl = { +static const apr_pollset_provider_t impl = { impl_pollset_create, impl_pollset_add, impl_pollset_remove, @@ -327,11 +329,10 @@ static apr_pollset_provider_t impl = { "epoll" }; -apr_pollset_provider_t *apr_pollset_provider_epoll = &impl; +const apr_pollset_provider_t *const apr_pollset_provider_epoll = &impl; -static apr_status_t cb_cleanup(void *p_) +static apr_status_t impl_pollcb_cleanup(apr_pollcb_t *pollcb) { - apr_pollcb_t *pollcb = (apr_pollcb_t *) p_; close(pollcb->fd); return APR_SUCCESS; } @@ -377,7 +378,6 @@ static apr_status_t impl_pollcb_create(apr_pollcb_t *pollcb, pollcb->fd = fd; pollcb->pollset.epoll = apr_palloc(p, size * sizeof(struct epoll_event)); - apr_pool_cleanup_register(p, pollcb, cb_cleanup, apr_pool_cleanup_null); return APR_SUCCESS; } @@ -385,11 +385,11 @@ static apr_status_t impl_pollcb_create(apr_pollcb_t *pollcb, static apr_status_t impl_pollcb_add(apr_pollcb_t *pollcb, apr_pollfd_t *descriptor) { - struct epoll_event ev; + struct epoll_event ev = { 0 }; int ret; ev.events = get_epoll_event(descriptor->reqevents); - ev.data.ptr = (void *)descriptor; + ev.data.ptr = (void *) descriptor; if (descriptor->desc_type == APR_POLL_SOCKET) { ret = epoll_ctl(pollcb->fd, EPOLL_CTL_ADD, @@ -414,7 +414,7 @@ static apr_status_t impl_pollcb_remove(apr_pollcb_t *pollcb, struct epoll_event ev = {0}; /* ignored, but must be passed with * kernel < 2.6.9 */ - int ret = -1; + int ret; if (descriptor->desc_type == APR_POLL_SOCKET) { ret = epoll_ctl(pollcb->fd, EPOLL_CTL_DEL, @@ -456,6 +456,14 @@ static apr_status_t impl_pollcb_poll(apr_pollcb_t *pollcb, else { for (i = 0; i < ret; i++) { apr_pollfd_t *pollfd = (apr_pollfd_t *)(pollcb->pollset.epoll[i].data.ptr); + + if ((pollcb->flags & APR_POLLSET_WAKEABLE) && + pollfd->desc_type == APR_POLL_FILE && + pollfd->desc.f == pollcb->wakeup_pipe[0]) { + apr_poll_drain_wakeup_pipe(pollcb->wakeup_pipe); + return APR_EINTR; + } + pollfd->rtnevents = get_epoll_revent(pollcb->pollset.epoll[i].events); rv = func(baton, pollfd); @@ -468,14 +476,15 @@ static apr_status_t impl_pollcb_poll(apr_pollcb_t *pollcb, return rv; } -static apr_pollcb_provider_t impl_cb = { +static const apr_pollcb_provider_t impl_cb = { impl_pollcb_create, impl_pollcb_add, impl_pollcb_remove, impl_pollcb_poll, + impl_pollcb_cleanup, "epoll" }; -apr_pollcb_provider_t *apr_pollcb_provider_epoll = &impl_cb; +const apr_pollcb_provider_t *const apr_pollcb_provider_epoll = &impl_cb; #endif /* HAVE_EPOLL */ |