rfbsrc: Check for connection being closed
authorNicolas Dufresne <nicolas.dufresne@collabora.com>
Thu, 24 Mar 2016 22:27:54 +0000 (18:27 -0400)
committerNicolas Dufresne <nicolas.dufresne@collabora.com>
Tue, 5 Apr 2016 17:35:25 +0000 (13:35 -0400)
Although it's not very well documented, g_input_stream_read_all() will
set the number of bytes read to 0 if the connection is closed rather
then returning an error.

gst/librfb/rfbdecoder.c

index 9142f1dcbe2df89d596e7ceb4e03520365e0b984..e6eb70135a2474ed0cf46aea9a36e1dbcb873a1f 100644 (file)
@@ -188,6 +188,7 @@ rfb_decoder_read (RfbDecoder * decoder, guint32 len)
 {
   GInputStream *in;
   GError *err = NULL;
+  gsize count = 0;
 
   if (!decoder->connection)
     return FALSE;
@@ -204,10 +205,16 @@ rfb_decoder_read (RfbDecoder * decoder, guint32 len)
     decoder->data_len = len;
   }
 
-  if (!g_input_stream_read_all (in, decoder->data, len, NULL,
+  if (!g_input_stream_read_all (in, decoder->data, len, &count,
           decoder->cancellable, &err))
     goto recv_error;
 
+  if (count == 0) {
+    g_set_error_literal (&err, G_IO_ERROR, G_IO_ERROR_BROKEN_PIPE,
+        "Connection was closed.");
+    goto recv_error;
+  }
+
   return decoder->data;
 
 recv_error: