[xiph-commits] r8551 - icecast/trunk/libshout/src

brendan at motherfish-iii.xiph.org brendan at motherfish-iii.xiph.org
Tue Dec 28 21:44:14 PST 2004


Author: brendan
Date: 2004-12-28 21:44:13 -0800 (Tue, 28 Dec 2004)
New Revision: 8551

Modified:
   icecast/trunk/libshout/src/shout.c
Log:
Loop over send operation on short writes until write finishes or returns an error.

Modified: icecast/trunk/libshout/src/shout.c
===================================================================
--- icecast/trunk/libshout/src/shout.c	2004-12-29 05:38:20 UTC (rev 8550)
+++ icecast/trunk/libshout/src/shout.c	2004-12-29 05:44:13 UTC (rev 8551)
@@ -1003,8 +1003,19 @@
 
 static int try_write (shout_t *self, const void *data, size_t len)
 {
-    int ret = sock_write_bytes (self->socket, data, len);
+    /* loop until whole buffer is written (unless it would block) */
+    int write_unfinished = 1;
+    int ret;
+    size_t pos = 0;
 
+    do {
+        ret = sock_write_bytes (self->socket, data + pos, len - pos);
+        if (ret > 0)
+            pos += ret;
+        if (pos == len)
+            write_unfinished = 0;
+    } while (write_unfinished && ret >= 0);
+
     if (ret < 0)
     {
         if (sock_recoverable (sock_error()))
@@ -1014,7 +1025,8 @@
         }
         self->error = SHOUTERR_SOCKET;
     }
-    return ret;
+
+    return pos;
 }
 
 /* collect nodes of a queue into a single buffer */



More information about the commits mailing list