rfbsrc: Check for connection being closed

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.
This commit is contained in:
Nicolas Dufresne 2016-03-24 18:27:54 -04:00
parent 0eb5722af6
commit 89f3f162a5

View file

@ -188,6 +188,7 @@ rfb_decoder_read (RfbDecoder * decoder, guint32 len)
{ {
GInputStream *in; GInputStream *in;
GError *err = NULL; GError *err = NULL;
gsize count = 0;
if (!decoder->connection) if (!decoder->connection)
return FALSE; return FALSE;
@ -204,10 +205,16 @@ rfb_decoder_read (RfbDecoder * decoder, guint32 len)
decoder->data_len = 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)) decoder->cancellable, &err))
goto recv_error; 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; return decoder->data;
recv_error: recv_error: