gst/tcp/gstmultifdsink.c: Make sure we don't try to read more from a client that...
authorWim Taymans <wim.taymans@gmail.com>
Fri, 6 Aug 2004 15:42:58 +0000 (15:42 +0000)
committerWim Taymans <wim.taymans@gmail.com>
Fri, 6 Aug 2004 15:42:58 +0000 (15:42 +0000)
Original commit message from CVS:
* gst/tcp/gstmultifdsink.c: (gst_multifdsink_class_init),
(gst_multifdsink_add), (gst_multifdsink_get_stats),
(gst_multifdsink_client_remove),
(gst_multifdsink_handle_client_read),
(gst_multifdsink_handle_client_write),
(gst_multifdsink_queue_buffer), (gst_multifdsink_handle_clients):
Make sure we don't try to read more from a client that what
ioctl says us or we deadlock.

ChangeLog
gst/tcp/gstmultifdsink.c

index 8ffc9da..95b89dc 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2004-08-06  Wim Taymans  <wim@fluendo.com>
+
+       * gst/tcp/gstmultifdsink.c: (gst_multifdsink_class_init),
+       (gst_multifdsink_add), (gst_multifdsink_get_stats),
+       (gst_multifdsink_client_remove),
+       (gst_multifdsink_handle_client_read),
+       (gst_multifdsink_handle_client_write),
+       (gst_multifdsink_queue_buffer), (gst_multifdsink_handle_clients):
+       Make sure we don't try to read more from a client that what 
+       ioctl says us or we deadlock.
+
 2004-08-05  Thomas Vander Stichele  <thomas at apestaart dot org>
 
        * gst/videotestsrc/gstvideotestsrc.c: (gst_videotestsrc_src_link),
index f9fa248..b2dd429 100644 (file)
@@ -474,6 +474,7 @@ gst_multifdsink_handle_client_read (GstMultiFdSink * sink,
     GstTCPClient * client)
 {
   int avail, fd;
+  gboolean ret;
 
   fd = client->fd;
 
@@ -482,27 +483,39 @@ gst_multifdsink_handle_client_read (GstMultiFdSink * sink,
   GST_LOG_OBJECT (sink, "select reports client read on fd %d of %d bytes",
       fd, avail);
 
+  ret = TRUE;
+
   if (avail == 0) {
     /* client sent close, so remove it */
     GST_DEBUG_OBJECT (sink, "client asked for close, removing on fd %d", fd);
-    return FALSE;
+    ret = FALSE;
   } else {
     guint8 dummy[512];
     gint nread;
 
-    /* just Read 'n' Drop */
+    /* just Read 'n' Drop, could also just drop the client as it's not supposed
+     * to write to us except for closing the socket, I guess it's because we
+     * like to listen to our customers. */
     do {
-      nread = read (fd, dummy, 512);
+      /* this is the maximum we can read */
+      gint to_read = MIN (avail, 512);
+
+      nread = read (fd, dummy, to_read);
       if (nread < -1) {
         GST_DEBUG_OBJECT (sink, "could not read bytes from fd %d: %s",
             fd, g_strerror (errno));
+        ret = FALSE;
+        break;
+      } else if (nread == 0) {
+        GST_WARNING_OBJECT (sink, "fd %d: gave 0 bytes in read, removing", fd);
+        ret = FALSE;
         break;
       }
       avail -= nread;
     }
     while (avail > 0);
   }
-  return TRUE;
+  return ret;
 }
 
 static gboolean