apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From traw...@apache.org
Subject svn commit: r1089433 - in /apr/apr/trunk: CHANGES poll/unix/poll.c poll/unix/select.c test/testpoll.c
Date Wed, 06 Apr 2011 12:51:17 GMT
Author: trawick
Date: Wed Apr  6 12:51:17 2011
New Revision: 1089433

URL: http://svn.apache.org/viewvc?rev=1089433&view=rev
Log:
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

Modified:
    apr/apr/trunk/CHANGES
    apr/apr/trunk/poll/unix/poll.c
    apr/apr/trunk/poll/unix/select.c
    apr/apr/trunk/test/testpoll.c

Modified: apr/apr/trunk/CHANGES
URL: http://svn.apache.org/viewvc/apr/apr/trunk/CHANGES?rev=1089433&r1=1089432&r2=1089433&view=diff
==============================================================================
--- apr/apr/trunk/CHANGES [utf-8] (original)
+++ apr/apr/trunk/CHANGES [utf-8] Wed Apr  6 12:51:17 2011
@@ -1,6 +1,9 @@
                                                      -*- coding: utf-8 -*-
 Changes for APR 2.0.0
 
+  *) poll, pollset, pollcb on Windows: Handle calls with no file/socket
+     descriptors.  PR 49882.  [Stefan Ruppert <sr myarm.com>, Jeff Trawick]
+
   *) apr_socket_connect() on Windows: Handle WSAEISCONN.  PR 48736.
      [<inoue ariel-networks.com>, Jeff Trawick]
 

Modified: apr/apr/trunk/poll/unix/poll.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/poll/unix/poll.c?rev=1089433&r1=1089432&r2=1089433&view=diff
==============================================================================
--- apr/apr/trunk/poll/unix/poll.c (original)
+++ apr/apr/trunk/poll/unix/poll.c Wed Apr  6 12:51:17 2011
@@ -240,11 +240,24 @@ static apr_status_t impl_pollset_poll(ap
 {
     int ret;
     apr_status_t rv = APR_SUCCESS;
+#ifdef WIN32
+    apr_interval_time_t orig_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);

Modified: apr/apr/trunk/poll/unix/select.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/poll/unix/select.c?rev=1089433&r1=1089432&r2=1089433&view=diff
==============================================================================
--- apr/apr/trunk/poll/unix/select.c (original)
+++ apr/apr/trunk/poll/unix/select.c Wed Apr  6 12:51:17 2011
@@ -41,6 +41,21 @@ APR_DECLARE(apr_status_t) apr_poll(apr_p
     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(ap
      */
     if (pollset->nelts == 0) {
         (*num) = 0;
+        if (timeout > 0) {
+            apr_sleep(timeout);
+            return APR_TIMEUP;
+        }
         return APR_SUCCESS;
     }
 #endif

Modified: apr/apr/trunk/test/testpoll.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/test/testpoll.c?rev=1089433&r1=1089432&r2=1089433&view=diff
==============================================================================
--- apr/apr/trunk/test/testpoll.c (original)
+++ apr/apr/trunk/test/testpoll.c Wed Apr  6 12:51:17 2011
@@ -819,6 +819,69 @@ static void pollcb_wakeup(abts_case *tc,
     ABTS_INT_EQUAL(tc, APR_EINTR, rv);
 }
 
+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[] = {
+        APR_POLLSET_DEFAULT,
+        APR_POLLSET_SELECT,
+        APR_POLLSET_KQUEUE,
+        APR_POLLSET_PORT,
+        APR_POLLSET_EPOLL,
+        APR_POLLSET_POLL};
+
+    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);
+        }
+
+        rv = apr_pollcb_create_ex(&pollcb, 5, p, 0, methods[0]);
+        if (rv != APR_ENOTIMPL) {
+            ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+
+            t1 = apr_time_now();
+            rv = apr_pollcb_poll(pollcb, apr_time_from_msec(200), NULL, NULL);
+            t2 = apr_time_now();
+            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));
+
+            /* no apr_pollcb_destroy() */
+        }
+    }
+}
+
 abts_suite *testpoll(abts_suite *suite)
 {
     suite = ADD_SUITE(suite)
@@ -858,6 +921,7 @@ abts_suite *testpoll(abts_suite *suite)
     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);
 
     abts_run_test(suite, pollset_wakeup, NULL);
     abts_run_test(suite, pollcb_wakeup, NULL);



Mime
View raw message