Commit 1d67c965 authored by Ole André Vadla Ravnås's avatar Ole André Vadla Ravnås Committed by Olivier Crête

test-io-stream-closing-read: Handle partial I/O

parent f56f25ab
...@@ -54,10 +54,9 @@ GCond count_cond; ...@@ -54,10 +54,9 @@ GCond count_cond;
static void static void
read_thread_cb (GInputStream *input_stream, TestIOStreamThreadData *data) read_thread_cb (GInputStream *input_stream, TestIOStreamThreadData *data)
{ {
GError *error = NULL; gboolean success;
gssize len;
guint8 buf[MESSAGE_SIZE]; guint8 buf[MESSAGE_SIZE];
GError *error = NULL;
g_mutex_lock (&count_lock); g_mutex_lock (&count_lock);
count++; count++;
...@@ -66,13 +65,14 @@ read_thread_cb (GInputStream *input_stream, TestIOStreamThreadData *data) ...@@ -66,13 +65,14 @@ read_thread_cb (GInputStream *input_stream, TestIOStreamThreadData *data)
/* Block on receiving some data. */ /* Block on receiving some data. */
do { do {
len = g_input_stream_read (input_stream, buf, sizeof (buf), NULL, &error); gsize bytes_read = 0;
success = g_input_stream_read_all (input_stream, buf, sizeof (buf),
&bytes_read, NULL, &error);
if (!data->user_data) { if (!data->user_data) {
g_assert_cmpint (len, ==, sizeof(buf)); g_assert_cmpint (bytes_read, ==, sizeof (buf));
return; return;
} }
} while (len > 0); } while (success);
g_assert_cmpint (len, ==, -1);
g_assert_error (error, G_IO_ERROR, G_IO_ERROR_BROKEN_PIPE); g_assert_error (error, G_IO_ERROR, G_IO_ERROR_BROKEN_PIPE);
g_clear_error (&error); g_clear_error (&error);
...@@ -84,19 +84,18 @@ static void ...@@ -84,19 +84,18 @@ static void
write_thread_cb (GOutputStream *output_stream, TestIOStreamThreadData *data) write_thread_cb (GOutputStream *output_stream, TestIOStreamThreadData *data)
{ {
gchar buf[MESSAGE_SIZE] = {0}; gchar buf[MESSAGE_SIZE] = {0};
gssize ret; gsize bytes_written = 0;
GError *error = NULL;
gpointer tmp; gpointer tmp;
guint stream_id; guint stream_id;
ret = g_output_stream_write (output_stream, buf, sizeof (buf), NULL, g_output_stream_write_all (output_stream, buf, sizeof (buf), &bytes_written,
&error); NULL, NULL);
g_mutex_lock (&count_lock); g_mutex_lock (&count_lock);
count++; count++;
g_cond_broadcast (&count_cond); g_cond_broadcast (&count_cond);
if (data->user_data) { if (data->user_data) {
g_assert_cmpint (ret, ==, sizeof(buf)); g_assert_cmpint (bytes_written, ==, sizeof (buf));
g_mutex_unlock (&count_lock); g_mutex_unlock (&count_lock);
return; return;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment