diff options
author | Yann Ylavic <ylavic@apache.org> | 2022-06-24 16:28:09 +0000 |
---|---|---|
committer | Yann Ylavic <ylavic@apache.org> | 2022-06-24 16:28:09 +0000 |
commit | 289e1190dc612308e7497eb1f76b4863b34908a6 (patch) | |
tree | 48b47ce4f4a1fafeb947ab6ef6c94ad6374c5a86 /poll | |
parent | 5007efd1b2a1a703a7059cbd5b0e1e819e6359c8 (diff) | |
download | apr-289e1190dc612308e7497eb1f76b4863b34908a6.tar.gz |
poll: Round up milliseconds timeouts.
When converting appr_interval_time_t (usecs) to system call's msecs, round up.
apr_*poll() calls should wait *at least* the given timeout, not less.
git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@1902236 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'poll')
-rw-r--r-- | poll/os2/poll.c | 3 | ||||
-rw-r--r-- | poll/os2/pollset.c | 2 | ||||
-rw-r--r-- | poll/unix/epoll.c | 4 | ||||
-rw-r--r-- | poll/unix/poll.c | 22 | ||||
-rw-r--r-- | poll/unix/z_asio.c | 2 |
5 files changed, 15 insertions, 18 deletions
diff --git a/poll/os2/poll.c b/poll/os2/poll.c index 3c36e5e68..a9d5153bf 100644 --- a/poll/os2/poll.c +++ b/poll/os2/poll.c @@ -61,7 +61,8 @@ APR_DECLARE(apr_status_t) apr_poll(apr_pollfd_t *aprset, apr_int32_t num, } if (timeout > 0) { - timeout /= 1000; /* convert microseconds to milliseconds */ + /* convert microseconds to milliseconds (round up) */ + timeout = (timeout + 999) / 1000; } i = select(pollset, num_read, num_write, num_except, timeout); diff --git a/poll/os2/pollset.c b/poll/os2/pollset.c index c407f5d98..8c7a4b130 100644 --- a/poll/os2/pollset.c +++ b/poll/os2/pollset.c @@ -223,7 +223,7 @@ APR_DECLARE(apr_status_t) apr_pollset_poll(apr_pollset_t *pollset, (*num) = 0; if (timeout > 0) { - timeout /= 1000; + timeout = (timeout + 999) / 1000; } rv = select(pollresult, pollset->num_read, pollset->num_write, pollset->num_except, timeout); diff --git a/poll/unix/epoll.c b/poll/unix/epoll.c index 7e811241d..485747732 100644 --- a/poll/unix/epoll.c +++ b/poll/unix/epoll.c @@ -265,7 +265,7 @@ static apr_status_t impl_pollset_poll(apr_pollset_t *pollset, *num = 0; if (timeout > 0) { - timeout /= 1000; + timeout = (timeout + 999) / 1000; } ret = epoll_wait(pollset->p->epoll_fd, pollset->p->pollset, pollset->nalloc, @@ -446,7 +446,7 @@ static apr_status_t impl_pollcb_poll(apr_pollcb_t *pollcb, apr_status_t rv = APR_SUCCESS; if (timeout > 0) { - timeout /= 1000; + timeout = (timeout + 999) / 1000; } ret = epoll_wait(pollcb->fd, pollcb->pollset.epoll, pollcb->nalloc, diff --git a/poll/unix/poll.c b/poll/unix/poll.c index 8c890d983..97a636019 100644 --- a/poll/unix/poll.c +++ b/poll/unix/poll.c @@ -114,7 +114,8 @@ APR_DECLARE(apr_status_t) apr_poll(apr_pollfd_t *aprset, apr_int32_t num, num_to_poll = i; if (timeout > 0) { - timeout /= 1000; /* convert microseconds to milliseconds */ + /* convert microseconds to milliseconds (round up) */ + timeout = (timeout + 999) / 1000; } i = poll(pollset, num_to_poll, timeout); @@ -235,6 +236,9 @@ static apr_status_t impl_pollset_poll(apr_pollset_t *pollset, *num = 0; + if (timeout > 0) { + timeout = (timeout + 999) / 1000; + } #ifdef WIN32 /* WSAPoll() requires at least one socket. */ if (pollset->nelts == 0) { @@ -244,14 +248,8 @@ static apr_status_t impl_pollset_poll(apr_pollset_t *pollset, } 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 if (ret < 0) { @@ -394,6 +392,10 @@ static apr_status_t impl_pollcb_poll(apr_pollcb_t *pollcb, apr_status_t rv = APR_SUCCESS; apr_uint32_t i; + if (timeout > 0) { + timeout = (timeout + 999) / 1000; + } + #ifdef WIN32 /* WSAPoll() requires at least one socket. */ if (pollcb->nelts == 0) { @@ -403,14 +405,8 @@ static apr_status_t impl_pollcb_poll(apr_pollcb_t *pollcb, } return APR_SUCCESS; } - if (timeout > 0) { - timeout /= 1000; - } 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/poll/unix/z_asio.c b/poll/unix/z_asio.c index 48b531cc8..8652f502d 100644 --- a/poll/unix/z_asio.c +++ b/poll/unix/z_asio.c @@ -554,7 +554,7 @@ static posix_poll(apr_pollset_t *pollset, DBG(4, "entered\n"); if (timeout > 0) { - timeout /= 1000; + timeout = (timeout + 999) / 1000; } rv = poll(priv->pollset, pollset->nelts, timeout); (*num) = rv; |