GIOChannel, G_IO_HUP



A glib question:

I have an application that talks over a pipe to another process.  When
either process is done, it says goodbye over the pipe and then shuts
down.  The other sees the goodbye, cleans up its business, and shuts
down.

I register the fd's of the pipe with the main event loop.  All works
quite well, except at shutdown.  If one process sends a goodbye
message and then closes its ends of the pipe, the other guy, rather
than seeing the goodbye data in the pipe, sees the shutdown
(cond==G_IO_HUP) instead.

I do have to pay attention to the G_IO_HUP, of course, since a process
might die (be killed, have a bug, etc.) rather than shutdown cleanly.

The question, then, is what is the right way to do this?  Am I
interacting with the GIOChannel incorrectly?  Am I misunderstanding
something fundamental about pipes?

Below is a short code snippet of one of my I/O handlers, this one for
output to the pipe.

Thanks much for any advice.


  /* Return 0 to be deregistered and removed from the event list,
     non-zero to stay registered */
  static gboolean io_output_handler(GIOChannel *ioch, GIOCondition cond, void *data)
  {
          assert(ioch);
          assert(data);
          g_assert(cond != G_IO_IN);
          if(cond & G_IO_ERR) ...
          if(cond & G_IO_NVAL) ...
          if(cond & G_IO_HUP) {
                  g_message("Deregistering output handler and signaling quit");
                  quit_main_loop();  /* Clean up happens when the main
                                        loop quits. */
                  return 0;
          }
          ...

-- 
 Jeff

 Jeff Abrahamson  <http://www.purple.com/jeff/>
 GPG fingerprint: 1A1A BA95 D082 A558 A276  63C6 16BF 8C4C 0D1D AE4B



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]