From b7f70f67039d79361f7aa12b572da4f97e717595 Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Tue, 26 Sep 2006 10:26:59 +0000 Subject: Fix closing of a GIOChannel so that G_IO_NVAL gets properly signaled --- common/glib-ectomy.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'common/glib-ectomy.c') 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; } -- cgit