Hi, all,
It seems that one more spawn flag will be useful: SPAWN_LEAVE_STDIN_OPEN.
Suppose that you need to send data to your child not constantly, but
only from time to time (possibly after sending some startup data). You
should to discard the initial stdin callback/source, to prevent it from
being called when there is no data to send (and since the stdin channel
is free, the callback is invoked constantly and raises high CPU usage).
Normally you would reference the channel, remember it, return FALSE to
discard the initial callback, and create a new callback/source each time
you have data to send (glib does not allow re-attaching a removed
source). The problem with the current implementation is, as soon you
return FALSE, spawn shutdowns (closes) the channel completely.
You may assume that g_io_channel_set_close_on_unref() will handle
everything gracefully, but at least under Windows, if the child reads
it's stdin until EOF (for example cat), so the channel must be closed
explicitly on our end, glib will fail to auto-close it on unref (or even
block? because the child is alive? I'm not sure about that).
So, SPAWN_LEAVE_STDIN_OPEN tells spawn not to shutdown the stdin
channel, because you may hold a reference to it. Unfortunately, I see no
official way to verify the ref_count of a GIOChannel.
Now, one can dup(g_io_channel_unix_get_fd(channel)), create and setup a
new channel, and leave the original one to be closed (it works, I've
checked), but that's seems unnecessarily complicated.
Thoughts? Maybe I'm missing something?
--
E-gards: Jimmy