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.
{
GInputStream *in;
GError *err = NULL;
+ gsize count = 0;
if (!decoder->connection)
return FALSE;
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: