the patch is based on 1.4.x; trunk isn't building for me today

the select() bypass needed more help than in the patch attached to the
bug, as the return code wasn't correct
oh, there's another select()
oh, what about WSAPoll()?  yep

there's another unhandled WSAPoll() in the pollcb support; I haven't
looked to see what it takes to drive it (I see a bunch of "pollcb not
supported" messages while running the test suite)

the new test runs fine on Windows 7 (MinGW) and Ubuntu 10.04
Index: poll/unix/select.c
===================================================================
--- poll/unix/select.c  (revision 1084768)
+++ poll/unix/select.c  (working copy)
@@ -41,6 +41,21 @@
     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 @@
      */
     if (pollset->nelts == 0) {
         (*num) = 0;
+        if (timeout > 0) {
+            apr_sleep(timeout);
+            return APR_TIMEUP;
+        }
         return APR_SUCCESS;
     }
 #endif
Index: poll/unix/poll.c
===================================================================
--- poll/unix/poll.c    (revision 1084768)
+++ poll/unix/poll.c    (working copy)
@@ -242,13 +242,20 @@
     apr_status_t rv = APR_SUCCESS;
     apr_uint32_t i, j;
 
-    if (timeout > 0) {
-        timeout /= 1000;
+#ifdef WIN32
+    /* WSAPoll() requires at least one socket. */
+    if (pollset->nelts == 0) {
+        *num = 0;
+        if (timeout > 0) {
+            apr_sleep(timeout);
+            return APR_TIMEUP;
+        }
+        return APR_SUCCESS;
     }
-#ifdef WIN32
-    ret = WSAPoll(pollset->p->pollset, pollset->nelts, (int)timeout);
+
+    ret = WSAPoll(pollset->p->pollset, pollset->nelts, (int)(timeout / 1000));
 #else
-    ret = poll(pollset->p->pollset, pollset->nelts, timeout);
+    ret = poll(pollset->p->pollset, pollset->nelts, timeout / 1000);
 #endif
     (*num) = ret;
     if (ret < 0) {
Index: test/testpoll.c
===================================================================
--- test/testpoll.c     (revision 1084768)
+++ test/testpoll.c     (working copy)
@@ -769,6 +769,49 @@
     }
 }
 
+static void justsleep(abts_case *tc, void *data)
+{
+    apr_int32_t nsds;
+    const apr_pollfd_t *hot_files;
+    apr_pollset_t *pollset;
+    apr_status_t rv;
+    apr_time_t t1, t2;
+    int i;
+    apr_pollset_method_e methods[2] = 
+        {APR_POLLSET_SELECT, APR_POLLSET_DEFAULT};
+
+    nsds = 1;
+    t1 = apr_time_now();
+    rv = apr_poll(NULL, 0, &nsds, apr_time_from_msec(200));
+    t2 = apr_time_now();
+    ABTS_INT_EQUAL(tc, 1, APR_STATUS_IS_TIMEUP(rv));
+    ABTS_INT_EQUAL(tc, 0, nsds);
+    ABTS_ASSERT(tc,
+                "apr_poll() didn't sleep",
+                (t2 - t1) > apr_time_from_msec(100));
+
+    for (i = 0; i < sizeof methods / sizeof methods[0]; i++) {
+        rv = apr_pollset_create_ex(&pollset, 5, p, 0, methods[i]);
+        if (rv != APR_ENOTIMPL) {
+            ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+
+            nsds = 1;
+            t1 = apr_time_now();
+            rv = apr_pollset_poll(pollset, apr_time_from_msec(200), &nsds,
+                                  &hot_files);
+            t2 = apr_time_now();
+            ABTS_INT_EQUAL(tc, 1, APR_STATUS_IS_TIMEUP(rv));
+            ABTS_INT_EQUAL(tc, 0, nsds);
+            ABTS_ASSERT(tc,
+                        "apr_pollset_poll() didn't sleep",
+                        (t2 - t1) > apr_time_from_msec(100));
+
+            rv = apr_pollset_destroy(pollset);
+            ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+        }
+    }
+}
+
 abts_suite *testpoll(abts_suite *suite)
 {
     suite = ADD_SUITE(suite)
@@ -808,6 +851,7 @@
     abts_run_test(suite, close_all_sockets, NULL);
     abts_run_test(suite, pollset_default, NULL);
     abts_run_test(suite, pollcb_default, NULL);
+    abts_run_test(suite, justsleep, NULL);
     return suite;
 }
 

Reply via email to