summaryrefslogtreecommitdiff
path: root/poll
diff options
context:
space:
mode:
authorJeff Trawick <trawick@apache.org>2011-04-29 12:12:55 +0000
committerJeff Trawick <trawick@apache.org>2011-04-29 12:12:55 +0000
commit5687c9eaa53170373b4e3b70e776f58701c7caec (patch)
tree68cab4dbea8a88498fb0b22ef41cc978a4806f96 /poll
parent0ccc46750048880fa44922e20664b59d31643e45 (diff)
downloadapr-5687c9eaa53170373b4e3b70e776f58701c7caec.tar.gz
From trunk:
1. r1089433 poll, pollset, pollcb on Windows: Handle calls with no file/socket descriptors. PR: 49882 Patch for one situation submitted by: Stefan Ruppert <sr myarm.com> Extended by: trawick 2. r1089528 fix variable initialization bug in r1089433 3. r987639 disable entire impl_pollcb_create() function if APR_HAS_THREADS instead of just inserting a return at the top 4. tiny part of r899905 move decl of loop control variables to the block where used git-svn-id: https://svn.apache.org/repos/asf/apr/apr/branches/1.5.x@1097783 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'poll')
-rw-r--r--poll/unix/poll.c22
-rw-r--r--poll/unix/select.c19
2 files changed, 37 insertions, 4 deletions
diff --git a/poll/unix/poll.c b/poll/unix/poll.c
index 3727b5b83..7d157367b 100644
--- a/poll/unix/poll.c
+++ b/poll/unix/poll.c
@@ -240,12 +240,24 @@ static apr_status_t impl_pollset_poll(apr_pollset_t *pollset,
{
int ret;
apr_status_t rv = APR_SUCCESS;
- apr_uint32_t i, j;
+#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);
+ return APR_TIMEUP;
+ }
+ return APR_SUCCESS;
+ }
+
ret = WSAPoll(pollset->p->pollset, pollset->nelts, (int)timeout);
#else
ret = poll(pollset->p->pollset, pollset->nelts, timeout);
@@ -258,6 +270,8 @@ static apr_status_t impl_pollset_poll(apr_pollset_t *pollset,
return APR_TIMEUP;
}
else {
+ apr_uint32_t i, j;
+
for (i = 0, j = 0; i < pollset->nelts; i++) {
if (pollset->p->pollset[i].revents != 0) {
/* Check if the polled descriptor is our
@@ -305,9 +319,8 @@ static apr_status_t impl_pollcb_create(apr_pollcb_t *pollcb,
apr_uint32_t flags)
{
#if APR_HAS_THREADS
- return APR_ENOTIMPL;
-#endif
-
+ return APR_ENOTIMPL;
+#else
pollcb->fd = -1;
#ifdef WIN32
if (!APR_HAVE_LATE_DLL_FUNC(WSAPoll)) {
@@ -319,6 +332,7 @@ static apr_status_t impl_pollcb_create(apr_pollcb_t *pollcb,
pollcb->copyset = apr_palloc(p, size * sizeof(apr_pollfd_t *));
return APR_SUCCESS;
+#endif
}
static apr_status_t impl_pollcb_add(apr_pollcb_t *pollcb,
diff --git a/poll/unix/select.c b/poll/unix/select.c
index 9288de00c..61a064f46 100644
--- a/poll/unix/select.c
+++ b/poll/unix/select.c
@@ -41,6 +41,21 @@ APR_DECLARE(apr_status_t) apr_poll(apr_pollfd_t *aprset, int num,
apr_datatype_e set_type = APR_NO_DESC;
#endif
+#ifdef WIN32
+ /* On Win32, select() must be presented with at least one socket to
+ * poll on, or select() will return WSAEINVAL. So, we'll just
+ * short-circuit and bail now.
+ */
+ if (num == 0) {
+ (*nsds) = 0;
+ if (timeout > 0) {
+ apr_sleep(timeout);
+ return APR_TIMEUP;
+ }
+ return APR_SUCCESS;
+ }
+#endif
+
if (timeout < 0) {
tvptr = NULL;
}
@@ -339,6 +354,10 @@ static apr_status_t impl_pollset_poll(apr_pollset_t *pollset,
*/
if (pollset->nelts == 0) {
(*num) = 0;
+ if (timeout > 0) {
+ apr_sleep(timeout);
+ return APR_TIMEUP;
+ }
return APR_SUCCESS;
}
#endif