summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorylavic <ylavic@13f79535-47bb-0310-9956-ffa450edef68>2022-06-26 12:21:33 +0000
committerylavic <ylavic@13f79535-47bb-0310-9956-ffa450edef68>2022-06-26 12:21:33 +0000
commit3a8ad60223a187b27d9b9a9c54d6fe2640f6e34a (patch)
tree0e89c834a27783426663f8983ec033b95d2dc4fd
parent35591f029bf8cf34d45fca07f917dfe5ac232306 (diff)
downloadlibapr-3a8ad60223a187b27d9b9a9c54d6fe2640f6e34a.tar.gz
poll: Follow up to r1902236: Fix poll() sleeps cases.
Don't convert timeout to milliseconds before potentially callig apr_sleep(). Tests for "poll() didn't sleep" now use the real timeout as lower limit. git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@1902258 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--poll/unix/poll.c21
-rw-r--r--poll/unix/z_asio.c1
-rw-r--r--test/testpoll.c6
3 files changed, 18 insertions, 10 deletions
diff --git a/poll/unix/poll.c b/poll/unix/poll.c
index 97a636019..c33157296 100644
--- a/poll/unix/poll.c
+++ b/poll/unix/poll.c
@@ -236,9 +236,6 @@ 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) {
@@ -248,6 +245,13 @@ static apr_status_t impl_pollset_poll(apr_pollset_t *pollset,
}
return APR_SUCCESS;
}
+#endif
+
+ if (timeout > 0) {
+ timeout = (timeout + 999) / 1000;
+ }
+
+#ifdef WIN32
ret = WSAPoll(pollset->p->pollset, pollset->nelts, (int)timeout);
#else
ret = poll(pollset->p->pollset, pollset->nelts, timeout);
@@ -392,10 +396,6 @@ 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) {
@@ -405,6 +405,13 @@ static apr_status_t impl_pollcb_poll(apr_pollcb_t *pollcb,
}
return APR_SUCCESS;
}
+#endif
+
+ if (timeout > 0) {
+ timeout = (timeout + 999) / 1000;
+ }
+
+#ifdef WIN32
ret = WSAPoll(pollcb->pollset.ps, pollcb->nelts, (int)timeout);
#else
ret = poll(pollcb->pollset.ps, pollcb->nelts, timeout);
diff --git a/poll/unix/z_asio.c b/poll/unix/z_asio.c
index 8652f502d..e7d9d9da3 100644
--- a/poll/unix/z_asio.c
+++ b/poll/unix/z_asio.c
@@ -698,6 +698,7 @@ static apr_status_t asio_pollset_poll(apr_pollset_t *pollset,
tv.tv_nsec = apr_time_usec(timeout) * 1000;
} else {
tv.tv_sec = INT_MAX; /* block until something is ready */
+ tv.tv_nsec = 0;
}
DBG2(6, "nothing on the ready ring "
diff --git a/test/testpoll.c b/test/testpoll.c
index 9f90af2dd..fe3520137 100644
--- a/test/testpoll.c
+++ b/test/testpoll.c
@@ -878,7 +878,7 @@ static void justsleep(abts_case *tc, void *data)
ABTS_INT_EQUAL(tc, 0, nsds);
ABTS_ASSERT(tc,
"apr_poll() didn't sleep",
- (t2 - t1) > apr_time_from_msec(100));
+ (t2 - t1) >= apr_time_from_msec(200));
for (i = 0; i < sizeof methods / sizeof methods[0]; i++) {
rv = apr_pollset_create_ex(&pollset, 5, p, 0, methods[i]);
@@ -894,7 +894,7 @@ static void justsleep(abts_case *tc, void *data)
ABTS_INT_EQUAL(tc, 0, nsds);
ABTS_ASSERT(tc,
"apr_pollset_poll() didn't sleep",
- (t2 - t1) > apr_time_from_msec(100));
+ (t2 - t1) >= apr_time_from_msec(200));
rv = apr_pollset_destroy(pollset);
ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
@@ -910,7 +910,7 @@ static void justsleep(abts_case *tc, void *data)
ABTS_INT_EQUAL(tc, 1, APR_STATUS_IS_TIMEUP(rv));
ABTS_ASSERT(tc,
"apr_pollcb_poll() didn't sleep",
- (t2 - t1) > apr_time_from_msec(100));
+ (t2 - t1) >= apr_time_from_msec(200));
/* no apr_pollcb_destroy() */
}