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

karl at svn.xiph.org karl at svn.xiph.org
Mon Feb 4 20:21:15 PST 2008


Author: karl
Date: 2008-02-04 20:21:12 -0800 (Mon, 04 Feb 2008)
New Revision: 14457

Modified:
   icecast/trunk/net/sock.c
Log:
Use poll if available, select can cause stack corruption if descriptor value is over 1024


Modified: icecast/trunk/net/sock.c
===================================================================
--- icecast/trunk/net/sock.c	2008-02-03 11:01:47 UTC (rev 14456)
+++ icecast/trunk/net/sock.c	2008-02-05 04:21:12 UTC (rev 14457)
@@ -30,6 +30,9 @@
 #include <string.h>
 #include <fcntl.h>
 #include <errno.h>
+#ifdef HAVE_POLL
+#include <poll.h>
+#endif
 #ifdef HAVE_SYS_SELECT_H
 #include <sys/select.h>
 #endif
@@ -508,8 +511,28 @@
  * return 0 for try again, interrupted
  * return 1 for ok 
  */
+#ifdef HAVE_POLL
 int sock_connected (sock_t sock, int timeout)
 {
+    struct pollfd check;
+
+    check.fd = sock;
+    check.events = POLLOUT;
+    switch (poll (&check, 1, timeout*1000))
+    {
+        case 0: return SOCK_TIMEOUT;
+        case -1:
+            if (sock_recoverable (sock_error()))
+                return 0;
+            return SOCK_ERROR;
+        default: return 1;
+    }                                           
+}
+
+#else
+
+int sock_connected (sock_t sock, int timeout)
+{
     fd_set wfds;
     int val = SOCK_ERROR;
     socklen_t size = sizeof val;
@@ -545,6 +568,7 @@
             return SOCK_ERROR;
     }
 }
+#endif
 
 #ifdef HAVE_GETADDRINFO
 



More information about the commits mailing list