[glib/wip/gmain: 7/8] spawn-multithreaded: Clean up IO channel code
- From: Colin Walters <walters src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/wip/gmain: 7/8] spawn-multithreaded: Clean up IO channel code
- Date: Fri, 10 Jun 2011 15:06:52 +0000 (UTC)
commit 34c130e5afa275b5c505067fa99c63789d4089aa
Author: Colin Walters <walters verbum org>
Date: Fri Jun 10 10:35:27 2011 -0400
spawn-multithreaded: Clean up IO channel code
I modeled the new bits after how gunixmount.c handles GIOChannel;
it's apparently easier not to look at the condition.
gthread/tests/spawn-multithreaded.c | 27 ++++++++++++++++-----------
1 files changed, 16 insertions(+), 11 deletions(-)
---
diff --git a/gthread/tests/spawn-multithreaded.c b/gthread/tests/spawn-multithreaded.c
index d31cb3b..1eaf4e3 100644
--- a/gthread/tests/spawn-multithreaded.c
+++ b/gthread/tests/spawn-multithreaded.c
@@ -118,21 +118,26 @@ on_child_stdout (GIOChannel *channel,
char buf[1024];
GError *error = NULL;
gsize bytes_read;
+ GIOStatus status;
SpawnAsyncMultithreadedData *data = datap;
- if (condition & G_IO_IN)
+ read:
+ status = g_io_channel_read_chars (channel, buf, sizeof (buf), &bytes_read, &error);
+ if (status == G_IO_STATUS_NORMAL)
+ {
+ g_string_append_len (data->stdout_buf, buf, (gssize) bytes_read);
+ if (bytes_read == sizeof (buf))
+ goto read;
+ }
+ else if (status == G_IO_STATUS_EOF)
{
- GIOStatus status;
- status = g_io_channel_read_chars (channel, buf, sizeof (buf), &bytes_read, &error);
- g_assert_no_error (error);
g_string_append_len (data->stdout_buf, buf, (gssize) bytes_read);
- if (status == G_IO_STATUS_EOF)
- data->stdout_done = TRUE;
+ data->stdout_done = TRUE;
+ }
+ else if (status == G_IO_STATUS_ERROR)
+ {
+ g_error ("Error reading from child stdin: %s", error->message);
}
- if (condition & G_IO_HUP)
- data->stdout_done = TRUE;
- if (condition & G_IO_ERR)
- g_error ("Error reading from child stdin");
if (data->child_exited && data->stdout_done)
g_main_loop_quit (data->loop);
@@ -181,7 +186,7 @@ test_spawn_async_multithreaded_instance (gpointer thread_data)
g_source_unref (source);
channel = g_io_channel_unix_new (child_stdout_fd);
- source = g_io_create_watch (channel, G_IO_IN | G_IO_HUP | G_IO_ERR);
+ source = g_io_create_watch (channel, G_IO_IN | G_IO_HUP);
g_source_set_callback (source, (GSourceFunc)on_child_stdout, &data, NULL);
g_source_attach (source, context);
g_source_unref (source);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]