summaryrefslogtreecommitdiff
path: root/poll
diff options
context:
space:
mode:
authorIvan Zhakov <ivan@apache.org>2022-02-09 10:39:35 +0000
committerIvan Zhakov <ivan@apache.org>2022-02-09 10:39:35 +0000
commit0ef545062eda29eb0db5f49e11ca4fec3e038529 (patch)
tree7e8a150c4e114f40c21af7dc5a9cb04a7033e9d4 /poll
parent011f944967c77b5608eaebf4cdc1947b7340d804 (diff)
parent89682a8e2e5eb498b6c4e4ff162052c7e2406a0b (diff)
downloadapr-0ef545062eda29eb0db5f49e11ca4fec3e038529.tar.gz
On 'win32-pollset-wakeup-no-file-socket-emulation' branch: Merge changes fromwin32-pollset-wakeup-no-file-socket-emulation
trunk. git-svn-id: https://svn.apache.org/repos/asf/apr/apr/branches/win32-pollset-wakeup-no-file-socket-emulation@1897894 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'poll')
-rw-r--r--poll/unix/epoll.c12
-rw-r--r--poll/unix/kqueue.c127
2 files changed, 86 insertions, 53 deletions
diff --git a/poll/unix/epoll.c b/poll/unix/epoll.c
index c00a1094d..7e811241d 100644
--- a/poll/unix/epoll.c
+++ b/poll/unix/epoll.c
@@ -25,9 +25,9 @@
#if defined(HAVE_EPOLL)
-static apr_int16_t get_epoll_event(apr_int16_t event)
+static unsigned get_epoll_event(apr_int16_t event)
{
- apr_int16_t rv = 0;
+ unsigned rv = 0;
if (event & APR_POLLIN)
rv |= EPOLLIN;
@@ -35,12 +35,16 @@ static apr_int16_t get_epoll_event(apr_int16_t event)
rv |= EPOLLPRI;
if (event & APR_POLLOUT)
rv |= EPOLLOUT;
+#ifdef EPOLLEXCLUSIVE
+ if (event & APR_POLLEXCL)
+ rv |= EPOLLEXCLUSIVE;
+#endif
/* APR_POLLNVAL is not handled by epoll. EPOLLERR and EPOLLHUP are return-only */
return rv;
}
-static apr_int16_t get_epoll_revent(apr_int16_t event)
+static apr_int16_t get_epoll_revent(unsigned event)
{
apr_int16_t rv = 0;
@@ -123,7 +127,7 @@ static apr_status_t impl_pollset_create(apr_pollset_t *pollset,
}
#endif
- pollset->p = apr_palloc(p, sizeof(apr_pollset_private_t));
+ pollset->p = apr_pcalloc(p, sizeof(apr_pollset_private_t));
#if APR_HAS_THREADS
if ((flags & APR_POLLSET_THREADSAFE) &&
!(flags & APR_POLLSET_NOCOPY) &&
diff --git a/poll/unix/kqueue.c b/poll/unix/kqueue.c
index e8a1ef95b..aa4251f1b 100644
--- a/poll/unix/kqueue.c
+++ b/poll/unix/kqueue.c
@@ -75,9 +75,12 @@ static apr_status_t impl_pollset_create(apr_pollset_t *pollset,
apr_uint32_t flags)
{
apr_status_t rv;
- pollset->p = apr_palloc(p, sizeof(apr_pollset_private_t));
+
+ pollset->p = apr_pcalloc(p, sizeof(apr_pollset_private_t));
+
#if APR_HAS_THREADS
if (flags & APR_POLLSET_THREADSAFE &&
+ !(flags & APR_POLLSET_NOCOPY) &&
((rv = apr_thread_mutex_create(&pollset->p->ring_lock,
APR_THREAD_MUTEX_DEFAULT,
p)) != APR_SUCCESS)) {
@@ -99,14 +102,9 @@ static apr_status_t impl_pollset_create(apr_pollset_t *pollset,
* for the same descriptor)
*/
pollset->p->setsize = 2 * size;
-
- pollset->p->ke_set =
- (struct kevent *) apr_palloc(p, pollset->p->setsize * sizeof(struct kevent));
-
- memset(pollset->p->ke_set, 0, pollset->p->setsize * sizeof(struct kevent));
+ pollset->p->ke_set = apr_pcalloc(p, pollset->p->setsize * sizeof(struct kevent));
pollset->p->kqueue_fd = kqueue();
-
if (pollset->p->kqueue_fd == -1) {
pollset->p = NULL;
return apr_get_netos_error();
@@ -133,9 +131,11 @@ static apr_status_t impl_pollset_create(apr_pollset_t *pollset,
pollset->p->result_set = apr_palloc(p, pollset->p->setsize * sizeof(apr_pollfd_t));
- APR_RING_INIT(&pollset->p->query_ring, pfd_elem_t, link);
- APR_RING_INIT(&pollset->p->free_ring, pfd_elem_t, link);
- APR_RING_INIT(&pollset->p->dead_ring, pfd_elem_t, link);
+ if (!(flags & APR_POLLSET_NOCOPY)) {
+ APR_RING_INIT(&pollset->p->query_ring, pfd_elem_t, link);
+ APR_RING_INIT(&pollset->p->free_ring, pfd_elem_t, link);
+ APR_RING_INIT(&pollset->p->dead_ring, pfd_elem_t, link);
+ }
return APR_SUCCESS;
}
@@ -144,20 +144,22 @@ static apr_status_t impl_pollset_add(apr_pollset_t *pollset,
const apr_pollfd_t *descriptor)
{
apr_os_sock_t fd;
- pfd_elem_t *elem;
+ pfd_elem_t *elem = NULL;
apr_status_t rv = APR_SUCCESS;
- pollset_lock_rings();
+ if (!(pollset->flags & APR_POLLSET_NOCOPY)) {
+ pollset_lock_rings();
- if (!APR_RING_EMPTY(&(pollset->p->free_ring), pfd_elem_t, link)) {
- elem = APR_RING_FIRST(&(pollset->p->free_ring));
- APR_RING_REMOVE(elem, link);
- }
- else {
- elem = (pfd_elem_t *) apr_palloc(pollset->pool, sizeof(pfd_elem_t));
- APR_RING_ELEM_INIT(elem, link);
+ if (!APR_RING_EMPTY(&(pollset->p->free_ring), pfd_elem_t, link)) {
+ elem = APR_RING_FIRST(&(pollset->p->free_ring));
+ APR_RING_REMOVE(elem, link);
+ }
+ else {
+ elem = (pfd_elem_t *) apr_palloc(pollset->pool, sizeof(pfd_elem_t));
+ APR_RING_ELEM_INIT(elem, link);
+ }
+ elem->pfd = *descriptor;
}
- elem->pfd = *descriptor;
if (descriptor->desc_type == APR_POLL_SOCKET) {
fd = descriptor->desc.s->socketdes;
@@ -167,7 +169,14 @@ static apr_status_t impl_pollset_add(apr_pollset_t *pollset,
}
if (descriptor->reqevents & APR_POLLIN) {
- EV_SET(&pollset->p->kevent, fd, EVFILT_READ, EV_ADD, 0, 0, elem);
+ if (pollset->flags & APR_POLLSET_NOCOPY) {
+ EV_SET(&pollset->p->kevent, fd, EVFILT_READ, EV_ADD, 0, 0,
+ descriptor);
+ }
+ else {
+ EV_SET(&pollset->p->kevent, fd, EVFILT_READ, EV_ADD, 0, 0,
+ elem);
+ }
if (kevent(pollset->p->kqueue_fd, &pollset->p->kevent, 1, NULL, 0,
NULL) == -1) {
@@ -176,7 +185,14 @@ static apr_status_t impl_pollset_add(apr_pollset_t *pollset,
}
if (descriptor->reqevents & APR_POLLOUT && rv == APR_SUCCESS) {
- EV_SET(&pollset->p->kevent, fd, EVFILT_WRITE, EV_ADD, 0, 0, elem);
+ if (pollset->flags & APR_POLLSET_NOCOPY) {
+ EV_SET(&pollset->p->kevent, fd, EVFILT_WRITE, EV_ADD, 0, 0,
+ descriptor);
+ }
+ else {
+ EV_SET(&pollset->p->kevent, fd, EVFILT_WRITE, EV_ADD, 0, 0,
+ elem);
+ }
if (kevent(pollset->p->kqueue_fd, &pollset->p->kevent, 1, NULL, 0,
NULL) == -1) {
@@ -184,14 +200,16 @@ static apr_status_t impl_pollset_add(apr_pollset_t *pollset,
}
}
- if (rv == APR_SUCCESS) {
- APR_RING_INSERT_TAIL(&(pollset->p->query_ring), elem, pfd_elem_t, link);
- }
- else {
- APR_RING_INSERT_TAIL(&(pollset->p->free_ring), elem, pfd_elem_t, link);
- }
+ if (!(pollset->flags & APR_POLLSET_NOCOPY)) {
+ if (rv == APR_SUCCESS) {
+ APR_RING_INSERT_TAIL(&(pollset->p->query_ring), elem, pfd_elem_t, link);
+ }
+ else {
+ APR_RING_INSERT_TAIL(&(pollset->p->free_ring), elem, pfd_elem_t, link);
+ }
- pollset_unlock_rings();
+ pollset_unlock_rings();
+ }
return rv;
}
@@ -199,12 +217,9 @@ static apr_status_t impl_pollset_add(apr_pollset_t *pollset,
static apr_status_t impl_pollset_remove(apr_pollset_t *pollset,
const apr_pollfd_t *descriptor)
{
- pfd_elem_t *ep;
apr_status_t rv;
apr_os_sock_t fd;
- pollset_lock_rings();
-
if (descriptor->desc_type == APR_POLL_SOCKET) {
fd = descriptor->desc.s->socketdes;
}
@@ -231,20 +246,26 @@ static apr_status_t impl_pollset_remove(apr_pollset_t *pollset,
}
}
- for (ep = APR_RING_FIRST(&(pollset->p->query_ring));
- ep != APR_RING_SENTINEL(&(pollset->p->query_ring),
- pfd_elem_t, link);
- ep = APR_RING_NEXT(ep, link)) {
+ if (!(pollset->flags & APR_POLLSET_NOCOPY)) {
+ pfd_elem_t *ep;
+
+ pollset_lock_rings();
- if (descriptor->desc.s == ep->pfd.desc.s) {
- APR_RING_REMOVE(ep, link);
- APR_RING_INSERT_TAIL(&(pollset->p->dead_ring),
- ep, pfd_elem_t, link);
- break;
+ for (ep = APR_RING_FIRST(&(pollset->p->query_ring));
+ ep != APR_RING_SENTINEL(&(pollset->p->query_ring),
+ pfd_elem_t, link);
+ ep = APR_RING_NEXT(ep, link)) {
+
+ if (descriptor->desc.s == ep->pfd.desc.s) {
+ APR_RING_REMOVE(ep, link);
+ APR_RING_INSERT_TAIL(&(pollset->p->dead_ring),
+ ep, pfd_elem_t, link);
+ break;
+ }
}
- }
- pollset_unlock_rings();
+ pollset_unlock_rings();
+ }
return rv;
}
@@ -282,7 +303,13 @@ static apr_status_t impl_pollset_poll(apr_pollset_t *pollset,
const apr_pollfd_t *fd;
for (i = 0, j = 0; i < ret; i++) {
- fd = &((pfd_elem_t *)pollset->p->ke_set[i].udata)->pfd;
+ if (pollset->flags & APR_POLLSET_NOCOPY) {
+ fd = (apr_pollfd_t *)pollset->p->ke_set[i].udata;
+ }
+ else {
+ fd = &((pfd_elem_t *)pollset->p->ke_set[i].udata)->pfd;
+ }
+
if ((pollset->flags & APR_POLLSET_WAKEABLE) &&
fd->desc_type == APR_POLL_FILE &&
fd->desc.f == pollset->wakeup_pipe[0]) {
@@ -305,13 +332,15 @@ static apr_status_t impl_pollset_poll(apr_pollset_t *pollset,
}
}
- pollset_lock_rings();
+ if (!(pollset->flags & APR_POLLSET_NOCOPY)) {
+ pollset_lock_rings();
- /* Shift all PFDs in the Dead Ring to the Free Ring */
- APR_RING_CONCAT(&(pollset->p->free_ring), &(pollset->p->dead_ring),
- pfd_elem_t, link);
+ /* Shift all PFDs in the Dead Ring to the Free Ring */
+ APR_RING_CONCAT(&(pollset->p->free_ring), &(pollset->p->dead_ring),
+ pfd_elem_t, link);
- pollset_unlock_rings();
+ pollset_unlock_rings();
+ }
return rv;
}