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

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 io
events.
I close my gioChannel in the foo_dialog_response_cb(), just before
destroy 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 channel
will not destroy it untill the GIOWatch source has been destroyed...
calling g_io_channel_shutdown(); depending on the file type and what
events you are watching... may trigger an event on the fd (a hangup
detected ? 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,
                       -Tristan























g_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 GIOChannel
flush : if TRUE, flush pending
err : location to store a GIOChannelError
Returns :the status of the operation. 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值