apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Justin Erenkrantz" <jus...@erenkrantz.com>
Subject [PATCH] apr_pollset_poll() returns WSAEINVAL if no sockets are in the pollset
Date Wed, 27 Aug 2008 05:18:32 GMT
The patch below fixes a cosmetic problem seen with serf on Win32 if
apr_pollset_poll is called without any sockets already in the pollset.
 select on Win32 will immediately return WSAEINVAL (730022) in this
case.

The MSDN docs for select() -
http://msdn.microsoft.com/en-us/library/ms740141.aspx - says:

---
Any two of the parameters, readfds, writefds, or exceptfds, can be
given as null. At least one must be non-null, and any non-null
descriptor set must contain at least one handle to a socket.
---

Earlier in the doc, it says that select() ignores the first parameter
(nfds), so it looks like while other OSes may have a short-circuit
success on the 0 nfds case, Win32 will just return WSAEINVAL in this
case.  Instead of returning an error, I believe the right thing is for
APR to hide this and return success.

So, any objections to committing the following?  (If we're going to do
1.3.5, I'd like to see this backported too.)

Thanks!  -- justin

Index: poll/unix/select.c
===================================================================
--- poll/unix/select.c  (revision 689358)
+++ poll/unix/select.c  (working copy)
@@ -453,6 +453,17 @@ APR_DECLARE(apr_status_t) apr_pollset_poll(apr_pol
     fd_set readset, writeset, exceptset;
     apr_status_t rv = APR_SUCCESS;

+#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 (pollset->nelts == 0) {
+        (*num) = 0;
+        return APR_SUCCESS;
+    }
+#endif
+
     if (timeout < 0) {
         tvptr = NULL;
     }

Mime
View raw message