diff options
| author | Johan Hedberg <johan.hedberg@nokia.com> | 2006-09-26 10:26:59 +0000 | 
|---|---|---|
| committer | Johan Hedberg <johan.hedberg@nokia.com> | 2006-09-26 10:26:59 +0000 | 
| commit | b7f70f67039d79361f7aa12b572da4f97e717595 (patch) | |
| tree | 82c41378a7633dfa1985cf580f77b835806e15cc /common | |
| parent | 3361d4251e1d494378eb2b3b80304605d002bab7 (diff) | |
Fix closing of a GIOChannel so that G_IO_NVAL gets properly signaled
Diffstat (limited to 'common')
| -rw-r--r-- | common/glib-ectomy.c | 12 | 
1 files changed, 10 insertions, 2 deletions
| diff --git a/common/glib-ectomy.c b/common/glib-ectomy.c index 6831fcff..fe6f524e 100644 --- a/common/glib-ectomy.c +++ b/common/glib-ectomy.c @@ -26,6 +26,7 @@ struct timeout {  struct _GIOChannel {  	int fd; +	gboolean closed;  	gboolean close_on_unref;  }; @@ -52,6 +53,9 @@ GIOError g_io_channel_read(GIOChannel *channel, gchar *buf, gsize count, gsize *  	int fd = channel->fd;  	gssize result; +	if (channel->closed) +		return G_IO_STATUS_ERROR; +  	/* At least according to the Debian manpage for read */  	if (count > SSIZE_MAX)  		count = SSIZE_MAX; @@ -83,11 +87,12 @@ retry:  void g_io_channel_close(GIOChannel *channel)  { -	if (!channel || channel->fd < 0) +	if (!channel || channel->closed)  		return;  	close(channel->fd); -	channel->fd = -1; + +	channel->closed = TRUE;  }  void g_io_channel_unref(GIOChannel *channel) @@ -123,6 +128,9 @@ void g_io_channel_set_close_on_unref(GIOChannel *channel, gboolean do_close)  gint g_io_channel_unix_get_fd(GIOChannel *channel)  { +	if (channel->closed) +		return -1; +  	return channel->fd;  } | 
