[xiph-commits] r7350 - icecast/branches/kh/net

karl at dactyl.lonelymoon.com karl
Mon Jul 26 09:27:01 PDT 2004


Author: karl
Date: Mon Jul 26 09:27:01 2004
New Revision: 7350

Modified:
icecast/branches/kh/net/sock.c
icecast/branches/kh/net/sock.h
Log:
resync with trunk, sock_connected timeout 0 means non-blocking
and don't loop on sock_connected when timeout occurs.


Modified: icecast/branches/kh/net/sock.c
===================================================================
--- icecast/branches/kh/net/sock.c	2004-07-26 16:03:52 UTC (rev 7349)
+++ icecast/branches/kh/net/sock.c	2004-07-26 16:26:58 UTC (rev 7350)
@@ -472,20 +472,22 @@
}
}

-/* see if a connection has been established
+/* see if a connection has been established. If timeout is < 0 then wait
+ * indefinitely, else wait for the stated number of seconds.
* return SOCK_TIMEOUT for timeout
* return SOCK_ERROR for failure
* return 0 for try again, interrupted
* return 1 for ok
*/
-int sock_connected (int sock, unsigned timeout)
+int sock_connected (int sock, int timeout)
{
fd_set wfds;
int val = SOCK_ERROR;
socklen_t size = sizeof val;
struct timeval tv, *timeval = NULL;

-    if (timeout)
+    /* make a timeout of <0 be indefinite */
+    if (timeout >= 0)
{
tv.tv_sec = timeout;
tv.tv_usec = 0;
@@ -555,8 +557,11 @@
return sock;
}

-
-sock_t sock_connect_wto(const char *hostname, const int port, const int timeout)
+/* issue a connect, but return after the timeout (seconds) is reached. If
+ * timeout is 0 or less then we will wait until the OS gives up on the connect
+ * The socket is returned
+ */
+sock_t sock_connect_wto(const char *hostname, int port, int timeout)
{
int sock = SOCK_ERROR;
struct addrinfo *ai, *head, hints;
@@ -575,7 +580,7 @@
{
if ((sock = socket (ai->ai_family, ai->ai_socktype, ai->ai_protocol)) >= 0)
{
-            if (timeout)
+            if (timeout > 0)
sock_set_blocking (sock, SOCK_NONBLOCK);

if (connect (sock, ai->ai_addr, ai->ai_addrlen) == 0)
@@ -586,13 +591,15 @@
{
if (sock_recoverable (sock_error()))
{
-                    if (sock_connected (sock, timeout) > 0)
+                    int connected = sock_connected (sock, timeout);
+                    if (connected == 0)  /* try again, interrupted */
+                        continue;
+                    if (connected == 1) /* connected */
{
-                        if (timeout) /* really wants to reset to what it was before */
+                        if (timeout >= 0)
sock_set_blocking(sock, SOCK_BLOCK);
break;
}
-                    continue;
}
sock_close (sock);
sock = SOCK_ERROR;

Modified: icecast/branches/kh/net/sock.h
===================================================================
--- icecast/branches/kh/net/sock.h	2004-07-26 16:03:52 UTC (rev 7349)
+++ icecast/branches/kh/net/sock.h	2004-07-26 16:26:58 UTC (rev 7350)
@@ -114,9 +114,9 @@
int sock_close(sock_t  sock);

/* Connection related socket functions */
-sock_t sock_connect_wto(const char *hostname, const int port, const int timeout);
+sock_t sock_connect_wto(const char *hostname, int port, int timeout);
int sock_connect_non_blocking(const char *host, const unsigned port);
-int sock_connected(int sock, unsigned timeout);
+int sock_connected(int sock, int timeout);

/* Socket write functions */
int sock_write_bytes(sock_t sock, const void *buff, const size_t len);



More information about the commits mailing list