mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-25 06:56:14 +01:00
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. https://bugzilla.gnome.org/show_bug.cgi?id=652072
This commit is contained in:
parent
7e1886ba72
commit
c2364ce9a4
@ -118,21 +118,26 @@ on_child_stdout (GIOChannel *channel,
|
|||||||
char buf[1024];
|
char buf[1024];
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
gsize bytes_read;
|
gsize bytes_read;
|
||||||
|
GIOStatus status;
|
||||||
SpawnAsyncMultithreadedData *data = datap;
|
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)
|
||||||
{
|
{
|
||||||
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);
|
g_string_append_len (data->stdout_buf, buf, (gssize) bytes_read);
|
||||||
if (status == G_IO_STATUS_EOF)
|
if (bytes_read == sizeof (buf))
|
||||||
data->stdout_done = TRUE;
|
goto read;
|
||||||
|
}
|
||||||
|
else if (status == G_IO_STATUS_EOF)
|
||||||
|
{
|
||||||
|
g_string_append_len (data->stdout_buf, buf, (gssize) bytes_read);
|
||||||
|
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)
|
if (data->child_exited && data->stdout_done)
|
||||||
g_main_loop_quit (data->loop);
|
g_main_loop_quit (data->loop);
|
||||||
@ -181,7 +186,7 @@ test_spawn_async_multithreaded_instance (gpointer thread_data)
|
|||||||
g_source_unref (source);
|
g_source_unref (source);
|
||||||
|
|
||||||
channel = g_io_channel_unix_new (child_stdout_fd);
|
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_set_callback (source, (GSourceFunc)on_child_stdout, &data, NULL);
|
||||||
g_source_attach (source, context);
|
g_source_attach (source, context);
|
||||||
g_source_unref (source);
|
g_source_unref (source);
|
||||||
|
Loading…
Reference in New Issue
Block a user