Re: g_spawn_async_with_pipes and g_io_add_watch problem
- From: "Ole C." <oles lists gmail com>
- To: Tim Müller <zen18864 zen co uk>
- Cc: gtk-app-devel-list gnome org
- Subject: Re: g_spawn_async_with_pipes and g_io_add_watch problem
- Date: Mon, 4 Apr 2005 15:34:35 +0200
Hello all again,
I can't really seem to hack this, so I guess I give it another shot
providing some code.
The first spawn starts a c program that takes stdout from the perl
script as input.
The next spawn starts a perl script that reads a file, changes it and
puts it on stdout.
The callback functions are listed below that. The problem is that the
program does a few calls to the pipe_to_mkukoa callback function and
then hangs in the first g_io_channel_write_chars call.
Ideas anyone? I have stared myself blind on this now I think.
GIOChannel *iocfinalp1 = g_io_channel_new_file (s_p1finalpath, "w+", NULL);
gint ok = g_spawn_async_with_pipes (NULL, s_removelfProgString, NULL, 0,
NULL,
NULL,
NULL,
&rlfsin,
&rlfsout,
&rlfserr,
&errormk);
/*set up the channels */
/*This channel will be written to from stdout from the perl script */
GIOChannel *iocrlfsin = g_io_channel_unix_new (rlfsin);
/*this channel will output to the final file */
GIOChannel *iocrlfsout = g_io_channel_unix_new (rlfsout);
/*Spawn the p1edit program */
gint okrlf = g_spawn_async_with_pipes (NULL,
s_extProgString,
NULL,
0,
NULL,
NULL,
NULL,
NULL, /*no stdin, filename as parameter */
&p1usout,
&p1userr,
&errorp1);
GIOChannel *iocstdout = g_io_channel_unix_new (p1usout);
g_io_add_watch (iocstdout, G_IO_IN | G_IO_HUP, pipe_output_to_mkukoa,
iocrlfsin);
/*The standard out from those files should then be directed to the
final file */
g_io_add_watch (iocrlfsout, G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
pipe_output_to_file, iocfinalp1);
gboolean
pipe_output_to_mkukoa (GIOChannel * ioc, GIOCondition condition,
gpointer data)
{
gchar *buffer;
GIOChannel *iocrlf = (GIOChannel *) data;
gsize bytes;
buffer = malloc (g_io_channel_get_buffer_size (ioc)+1);
if (condition & G_IO_IN)
{
if (g_io_channel_read_chars (ioc, buffer,
g_io_channel_get_buffer_size(ioc), &bytes, NULL)
!= G_IO_STATUS_ERROR && bytes > 0)
{
GIOStatus retur =
g_io_channel_write_chars (iocrlf, buffer, bytes, NULL, NULL);
}
.
.//misc other stuff here, but it hangs on the write_chars above
.
.
gboolean
pipe_output_to_file (GIOChannel * ioc, GIOCondition condition, gpointer data)
{
gchar *buffer = malloc (g_io_channel_get_buffer_size (ioc));
GIOChannel *iocfh = (GIOChannel *) data;
gsize bytes;
if (condition & G_IO_IN)
{
if (g_io_channel_read_chars (ioc, buffer,
g_io_channel_get_buffer_size (ioc), &bytes, NULL)
!= G_IO_STATUS_ERROR && bytes > 0)
{
GIOStatus retur =
g_io_channel_write_chars (iocfh, buffer, bytes, NULL, NULL);
}
if (condition & G_IO_HUP)
{
while (g_io_channel_read_chars (iocfh, buffer,
g_io_channel_get_buffer_size (ioc), &bytes, NULL)
!= G_IO_STATUS_ERROR && bytes > 0)
{
GIOStatus retur =
g_io_channel_write_chars (iocfh, buffer, bytes, NULL, NULL);
}
return FALSE;
}
}
if (condition & (G_IO_HUP | G_IO_ERR | G_IO_NVAL))
{
g_io_channel_unref (ioc);
g_io_channel_shutdown (ioc, TRUE, NULL);
}
return TRUE;
}
On Mar 17, 2005 1:41 AM, Tim Müller <zen18864 zen co uk> wrote:
On Wednesday 16 March 2005 21:55, Ole C. wrote:
(snip a lot)
I have to admit I have only quickly looked over your text and not read it in
much detail, but it sounds like you might not be checking the condition in
the g_io_add_watch() callback on a per-flag basis. Your callback could be
called with condition = G_IO_IN | G_IO_HUP at the end, so if you just check
with if (condition == G_IO_IN) etc. instead of if ((condition & G_IO_IN)) you
won't catch that case properly.
Just a thought. If that's not it, I'd recommend you post some code somewhere
for people to look at (the shorter, the better).
Cheers
-Tim
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]