[xiph-commits] r16209 - icecast/trunk/net

karl at svn.xiph.org karl at svn.xiph.org
Mon Jul 6 07:28:16 PDT 2009


Author: karl
Date: 2009-07-06 07:28:16 -0700 (Mon, 06 Jul 2009)
New Revision: 16209

Modified:
   icecast/trunk/net/sock.c
Log:
bug+fix reported on icecast-dev (Petr Pisar, 06/07/2009). poll implementation
of sock_connected had incorrect return in failure case.


Modified: icecast/trunk/net/sock.c
===================================================================
--- icecast/trunk/net/sock.c	2009-07-05 18:45:30 UTC (rev 16208)
+++ icecast/trunk/net/sock.c	2009-07-06 14:28:16 UTC (rev 16209)
@@ -516,17 +516,27 @@
 int sock_connected (sock_t sock, int timeout)
 {
     struct pollfd check;
+    int val = SOCK_ERROR;
+    socklen_t size = sizeof val;
 
     check.fd = sock;
     check.events = POLLOUT;
     switch (poll (&check, 1, timeout*1000))
     {
         case 0: return SOCK_TIMEOUT;
+        default:
+            /* on windows getsockopt.val is defined as char* */
+            if (getsockopt(sock, SOL_SOCKET, SO_ERROR, (void*) &val, &size) == 0)
+            {
+                if (val == 0)
+                    return 1;
+                sock_set_error (val);
+            }
+            /* fall through */
         case -1:
             if (sock_recoverable (sock_error()))
                 return 0;
             return SOCK_ERROR;
-        default: return 1;
     }                                           
 }
 



More information about the commits mailing list