diff options
Diffstat (limited to 'contrib/apr/poll/unix')
-rw-r--r-- | contrib/apr/poll/unix/epoll.c | 45 | ||||
-rw-r--r-- | contrib/apr/poll/unix/kqueue.c | 33 | ||||
-rw-r--r-- | contrib/apr/poll/unix/poll.c | 30 | ||||
-rw-r--r-- | contrib/apr/poll/unix/pollcb.c | 3 | ||||
-rw-r--r-- | contrib/apr/poll/unix/port.c | 33 | ||||
-rw-r--r-- | contrib/apr/poll/unix/z_asio.c | 13 |
6 files changed, 115 insertions, 42 deletions
diff --git a/contrib/apr/poll/unix/epoll.c b/contrib/apr/poll/unix/epoll.c index 326dac7..fe006db 100644 --- a/contrib/apr/poll/unix/epoll.c +++ b/contrib/apr/poll/unix/epoll.c @@ -104,14 +104,22 @@ static apr_status_t impl_pollset_create(apr_pollset_t *pollset, #ifndef HAVE_EPOLL_CREATE1 { - int flags; + int fd_flags; - if ((flags = fcntl(fd, F_GETFD)) == -1) - return errno; + if ((fd_flags = fcntl(fd, F_GETFD)) == -1) { + rv = errno; + close(fd); + pollset->p = NULL; + return rv; + } - flags |= FD_CLOEXEC; - if (fcntl(fd, F_SETFD, flags) == -1) - return errno; + fd_flags |= FD_CLOEXEC; + if (fcntl(fd, F_SETFD, fd_flags) == -1) { + rv = errno; + close(fd); + pollset->p = NULL; + return rv; + } } #endif @@ -122,11 +130,13 @@ static apr_status_t impl_pollset_create(apr_pollset_t *pollset, ((rv = apr_thread_mutex_create(&pollset->p->ring_lock, APR_THREAD_MUTEX_DEFAULT, p)) != APR_SUCCESS)) { + close(fd); pollset->p = NULL; return rv; } #else if (flags & APR_POLLSET_THREADSAFE) { + close(fd); pollset->p = NULL; return APR_ENOTIMPL; } @@ -345,14 +355,23 @@ static apr_status_t impl_pollcb_create(apr_pollcb_t *pollcb, #ifndef HAVE_EPOLL_CREATE1 { - int flags; - - if ((flags = fcntl(fd, F_GETFD)) == -1) - return errno; + int fd_flags; + apr_status_t rv; + + if ((fd_flags = fcntl(fd, F_GETFD)) == -1) { + rv = errno; + close(fd); + pollcb->fd = -1; + return rv; + } - flags |= FD_CLOEXEC; - if (fcntl(fd, F_SETFD, flags) == -1) - return errno; + fd_flags |= FD_CLOEXEC; + if (fcntl(fd, F_SETFD, fd_flags) == -1) { + rv = errno; + close(fd); + pollcb->fd = -1; + return rv; + } } #endif diff --git a/contrib/apr/poll/unix/kqueue.c b/contrib/apr/poll/unix/kqueue.c index dbe785a..efc5898 100644 --- a/contrib/apr/poll/unix/kqueue.c +++ b/contrib/apr/poll/unix/kqueue.c @@ -115,12 +115,20 @@ static apr_status_t impl_pollset_create(apr_pollset_t *pollset, { int flags; - if ((flags = fcntl(pollset->p->kqueue_fd, F_GETFD)) == -1) - return errno; + if ((flags = fcntl(pollset->p->kqueue_fd, F_GETFD)) == -1) { + rv = errno; + close(pollset->p->kqueue_fd); + pollset->p = NULL; + return rv; + } flags |= FD_CLOEXEC; - if (fcntl(pollset->p->kqueue_fd, F_SETFD, flags) == -1) - return errno; + if (fcntl(pollset->p->kqueue_fd, F_SETFD, flags) == -1) { + rv = errno; + close(pollset->p->kqueue_fd); + pollset->p = NULL; + return rv; + } } pollset->p->result_set = apr_palloc(p, pollset->p->setsize * sizeof(apr_pollfd_t)); @@ -338,13 +346,22 @@ static apr_status_t impl_pollcb_create(apr_pollcb_t *pollcb, { int flags; + apr_status_t rv; - if ((flags = fcntl(fd, F_GETFD)) == -1) - return errno; + if ((flags = fcntl(fd, F_GETFD)) == -1) { + rv = errno; + close(fd); + pollcb->fd = -1; + return rv; + } flags |= FD_CLOEXEC; - if (fcntl(fd, F_SETFD, flags) == -1) - return errno; + if (fcntl(fd, F_SETFD, flags) == -1) { + rv = errno; + close(fd); + pollcb->fd = -1; + return rv; + } } pollcb->fd = fd; diff --git a/contrib/apr/poll/unix/poll.c b/contrib/apr/poll/unix/poll.c index 7d15736..d7a436f 100644 --- a/contrib/apr/poll/unix/poll.c +++ b/contrib/apr/poll/unix/poll.c @@ -240,26 +240,25 @@ static apr_status_t impl_pollset_poll(apr_pollset_t *pollset, { int ret; apr_status_t rv = APR_SUCCESS; -#ifdef WIN32 - apr_interval_time_t orig_timeout = timeout; -#endif - if (timeout > 0) { - timeout /= 1000; - } #ifdef WIN32 /* WSAPoll() requires at least one socket. */ if (pollset->nelts == 0) { *num = 0; - if (orig_timeout > 0) { - apr_sleep(orig_timeout); + if (timeout > 0) { + apr_sleep(timeout); return APR_TIMEUP; } return APR_SUCCESS; } - + if (timeout > 0) { + timeout /= 1000; + } ret = WSAPoll(pollset->p->pollset, pollset->nelts, (int)timeout); #else + if (timeout > 0) { + timeout /= 1000; + } ret = poll(pollset->p->pollset, pollset->nelts, timeout); #endif (*num) = ret; @@ -398,12 +397,23 @@ static apr_status_t impl_pollcb_poll(apr_pollcb_t *pollcb, apr_status_t rv = APR_SUCCESS; apr_uint32_t i; +#ifdef WIN32 + /* WSAPoll() requires at least one socket. */ + if (pollcb->nelts == 0) { + if (timeout > 0) { + apr_sleep(timeout); + return APR_TIMEUP; + } + return APR_SUCCESS; + } if (timeout > 0) { timeout /= 1000; } -#ifdef WIN32 ret = WSAPoll(pollcb->pollset.ps, pollcb->nelts, (int)timeout); #else + if (timeout > 0) { + timeout /= 1000; + } ret = poll(pollcb->pollset.ps, pollcb->nelts, timeout); #endif if (ret < 0) { diff --git a/contrib/apr/poll/unix/pollcb.c b/contrib/apr/poll/unix/pollcb.c index 24f8010..da12f01 100644 --- a/contrib/apr/poll/unix/pollcb.c +++ b/contrib/apr/poll/unix/pollcb.c @@ -136,6 +136,9 @@ APR_DECLARE(apr_status_t) apr_pollcb_create_ex(apr_pollcb_t **ret_pollcb, } pollcb->provider = provider; } + else if (rv != APR_SUCCESS) { + return rv; + } *ret_pollcb = pollcb; return APR_SUCCESS; diff --git a/contrib/apr/poll/unix/port.c b/contrib/apr/poll/unix/port.c index 7a31c46..5002dfd 100644 --- a/contrib/apr/poll/unix/port.c +++ b/contrib/apr/poll/unix/port.c @@ -188,12 +188,20 @@ static apr_status_t impl_pollset_create(apr_pollset_t *pollset, { int flags; - if ((flags = fcntl(pollset->p->port_fd, F_GETFD)) == -1) - return errno; + if ((flags = fcntl(pollset->p->port_fd, F_GETFD)) == -1) { + rv = errno; + close(pollset->p->port_fd); + pollset->p = NULL; + return rv; + } flags |= FD_CLOEXEC; - if (fcntl(pollset->p->port_fd, F_SETFD, flags) == -1) - return errno; + if (fcntl(pollset->p->port_fd, F_SETFD, flags) == -1) { + rv = errno; + close(pollset->p->port_fd); + pollset->p = NULL; + return rv; + } } pollset->p->result_set = apr_palloc(p, size * sizeof(apr_pollfd_t)); @@ -478,13 +486,22 @@ static apr_status_t impl_pollcb_create(apr_pollcb_t *pollcb, { int flags; + apr_status_t rv; - if ((flags = fcntl(pollcb->fd, F_GETFD)) == -1) - return errno; + if ((flags = fcntl(pollcb->fd, F_GETFD)) == -1) { + rv = errno; + close(pollcb->fd); + pollcb->fd = -1; + return rv; + } flags |= FD_CLOEXEC; - if (fcntl(pollcb->fd, F_SETFD, flags) == -1) - return errno; + if (fcntl(pollcb->fd, F_SETFD, flags) == -1) { + rv = errno; + close(pollcb->fd); + pollcb->fd = -1; + return rv; + } } pollcb->pollset.port = apr_palloc(p, size * sizeof(port_event_t)); diff --git a/contrib/apr/poll/unix/z_asio.c b/contrib/apr/poll/unix/z_asio.c index ce158d3..7e0fd89 100644 --- a/contrib/apr/poll/unix/z_asio.c +++ b/contrib/apr/poll/unix/z_asio.c @@ -272,7 +272,7 @@ static apr_status_t asio_pollset_create(apr_pollset_t *pollset, APR_THREAD_MUTEX_DEFAULT, p) != APR_SUCCESS) { DBG1(1, "apr_thread_mutex_create returned %d\n", rv); - pollset = NULL; + pollset->p = NULL; return rv; } rv = msgget(IPC_PRIVATE, S_IWUSR+S_IRUSR); /* user r/w perms */ @@ -280,7 +280,7 @@ static apr_status_t asio_pollset_create(apr_pollset_t *pollset, #if DEBUG perror(__FUNCTION__ " msgget returned < 0 "); #endif - pollset = NULL; + pollset->p = NULL; return rv; } @@ -292,7 +292,7 @@ static apr_status_t asio_pollset_create(apr_pollset_t *pollset, APR_RING_INIT(&priv->prior_ready_ring, asio_elem_t, link); #else /* APR doesn't have threads but caller wants a threadsafe pollset */ - pollset = NULL; + pollset->p = NULL; return APR_ENOTIMPL; #endif @@ -304,6 +304,7 @@ static apr_status_t asio_pollset_create(apr_pollset_t *pollset, priv->query_set = apr_palloc(p, size * sizeof(apr_pollfd_t)); if ((!priv->pollset) || (!priv->query_set)) { + pollset->p = NULL; return APR_ENOMEM; } } @@ -314,6 +315,10 @@ static apr_status_t asio_pollset_create(apr_pollset_t *pollset, priv->size = size; priv->result_set = apr_palloc(p, size * sizeof(apr_pollfd_t)); if (!priv->result_set) { + if (flags & APR_POLLSET_THREADSAFE) { + msgctl(priv->msg_q, IPC_RMID, NULL); + } + pollset->p = NULL; return APR_ENOMEM; } @@ -379,6 +384,7 @@ static apr_status_t asio_pollset_add(apr_pollset_t *pollset, APR_RING_REMOVE(elem, link); DBG1(3, "used recycled memory at %08p\n", elem); elem->state = ASIO_INIT; + elem->a.aio_cflags = 0; } else { elem = (asio_elem_t *) apr_pcalloc(pollset->pool, sizeof(asio_elem_t)); @@ -659,6 +665,7 @@ static apr_status_t asio_pollset_poll(apr_pollset_t *pollset, if (ret == 1) { DBG(4, "asyncio() completed inline\n"); /* it's ready now */ + elem->state = ASIO_COMPLETE; APR_RING_INSERT_TAIL(&(priv->ready_ring), elem, asio_elem_t, link); } |