diff options
Diffstat (limited to 'common/glib-ectomy.c')
-rw-r--r-- | common/glib-ectomy.c | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/common/glib-ectomy.c b/common/glib-ectomy.c index 41641ee6..33d20533 100644 --- a/common/glib-ectomy.c +++ b/common/glib-ectomy.c @@ -24,6 +24,11 @@ struct timeout { GSourceFunc function; }; +struct _GIOChannel { + int fd; + gboolean close_on_unref; +}; + struct _GMainContext { guint next_id; glong next_timeout; @@ -82,8 +87,17 @@ void g_io_channel_close(GIOChannel *channel) return; close(channel->fd); + channel->fd = -1; +} + +void g_io_channel_unref(GIOChannel *channel) +{ + if (!channel) + return; + + if (channel->close_on_unref && channel->fd >= 0) + g_io_channel_close(channel); - memset(channel, 0, sizeof(channel)); free(channel); } @@ -95,11 +109,18 @@ GIOChannel *g_io_channel_unix_new(int fd) if (!channel) return NULL; + memset(channel, 0, sizeof(GIOChannel)); + channel->fd = fd; return channel; } +void g_io_channel_set_close_on_unref(GIOChannel *channel, gboolean do_close) +{ + channel->close_on_unref = do_close; +} + gint g_io_channel_unix_get_fd(GIOChannel *channel) { return channel->fd; |