From: Wim Taymans Date: Fri, 6 Aug 2004 15:42:58 +0000 (+0000) Subject: gst/tcp/gstmultifdsink.c: Make sure we don't try to read more from a client that... X-Git-Tag: 1.19.3~511^2~13851 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=fd78bb16f1c75580557748233239c0c75fb62f05;p=platform%2Fupstream%2Fgstreamer.git gst/tcp/gstmultifdsink.c: Make sure we don't try to read more from a client that what ioctl says us or we deadlock. 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. --- diff --git a/ChangeLog b/ChangeLog index 8ffc9da..95b89dc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2004-08-06 Wim Taymans + + * 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 * gst/videotestsrc/gstvideotestsrc.c: (gst_videotestsrc_src_link), diff --git a/gst/tcp/gstmultifdsink.c b/gst/tcp/gstmultifdsink.c index f9fa248..b2dd429 100644 --- a/gst/tcp/gstmultifdsink.c +++ b/gst/tcp/gstmultifdsink.c @@ -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