shutdown g_io_channel之后,仍旧会有event发送

来源:互联网 发布:花旗软件待遇 编辑:程序博客网 时间:2024/04/28 06:19

Re: GIOFunc called after a g_io_channel_shutdown


  • From: Tristan Van Berkom <tvb gnome org>
  • To: Renaud Malaval <Renaud Malaval palmsource com>
  • Cc: gtk-app-devel-list gnome org
  • Subject: Re: GIOFunc called after a g_io_channel_shutdown
  • Date: Tue, 16 May 2006 13:14:38 -0400

Renaud Malaval wrote:
Hello,

I use g_io_channel_unix_new() in a custom dialog to check somes ioevents.I close my gioChannel in the foo_dialog_response_cb(), just beforedestroy the custom dialog.

To close the gioChannel I Does :

status = g_io_channel_shutdown(privP->gioChannelP, FALSE, &gerrorP); if( gerrorP) {g_error_free(gerrorP);}g_io_channel_unref(privP->gioChannelP);

I don't have errors (status is ok and no gerrorP) About 1 or 2 seconds
after that my GIOFunc callback is called and crash because of bad
context (user_data pointer is breaked)


I don't understood why the gioChannel is not closed.

Any idea, please ?
The GIOWatch has a reference to the channel, so unreffing the channelwill not destroy it untill the GIOWatch source has been destroyed...calling g_io_channel_shutdown(); depending on the file type and whatevents you are watching... may trigger an event on the fd (a hangupdetected ? or and EOF maybe ?)

Typicly... in very simple situations I do something like this:========================================================channel   = channel_new (probably _unix_new with an fd);source_id = g_io_add_watch (channel ... args);g_io_channel_unref (channel); // pass ownership of the channel to the watch

/* ...now later... when shutting down I do: */g_source_remove (source_id); // this will remove the event source and unreff the channel.========================================================

Cheers,                       -Tristang_io_channel_shutdown ()GIOStatus           g_io_channel_shutdown               (GIOChannel *channel,                                                         gboolean flush,                                                         GError **err);Close an IO channel. Any pending data to be written will be flushed if flush is TRUE. The channel will not be freed until the last reference is dropped using g_io_channel_unref().channel : a GIOChannelflush : if TRUE, flush pendingerr : location to store a GIOChannelErrorReturns :the status of the operation. 

原创粉丝点击