diff options
author | Johan Hedberg <johan.hedberg@nokia.com> | 2006-08-26 16:55:47 +0000 |
---|---|---|
committer | Johan Hedberg <johan.hedberg@nokia.com> | 2006-08-26 16:55:47 +0000 |
commit | ea7b976177bffc7f3c89e380a1273e1d85b2a24f (patch) | |
tree | 146321302301da35c12ae5ac10fd6f6700c13945 /common | |
parent | 448146fdeb6a90cdf11826fcdc88ce9068eb9646 (diff) |
Cleanup/fix glib-ectomy.c and its usage
Diffstat (limited to 'common')
-rw-r--r-- | common/glib-ectomy.c | 23 | ||||
-rw-r--r-- | common/glib-ectomy.h | 6 |
2 files changed, 25 insertions, 4 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; diff --git a/common/glib-ectomy.h b/common/glib-ectomy.h index 16f4810d..2885f019 100644 --- a/common/glib-ectomy.h +++ b/common/glib-ectomy.h @@ -30,9 +30,7 @@ typedef ssize_t gssize; #define MIN_TIMEOUT(a, b) (((a) < (b)) ? (a) : (b)) -typedef struct _GIOChannel { - int fd; -} GIOChannel; +typedef struct _GIOChannel GIOChannel; typedef gboolean (*GSourceFunc) (gpointer data); @@ -78,6 +76,8 @@ GIOError g_io_channel_read(GIOChannel *channel, gchar *buf, gsize count, gsize * void g_io_channel_close(GIOChannel *channel); GIOChannel *g_io_channel_unix_new(int fd); +void g_io_channel_unref(GIOChannel *channel); +void g_io_channel_set_close_on_unref(GIOChannel *channel, gboolean do_close); gint g_io_channel_unix_get_fd(GIOChannel *channel); guint g_io_add_watch(GIOChannel *channel, GIOCondition condition, GIOFunc func, gpointer user_data); |