summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSzymon Janc <szymon.janc@tieto.com>2014-01-09 11:31:48 +0100
committerJohan Hedberg <johan.hedberg@intel.com>2014-01-09 14:13:41 +0200
commit2170661260e8ca04217a4b01b88183866747429b (patch)
tree4dfffae65dadcbc089d6a53c1fb099f4642d988d /src
parent8d65d9c410b265c6b9d71d9a098224032f6c4b0c (diff)
shared: Fix clearing of IO handlers
If NULL callback is passed to io_set_read/write_handler don't add watch for it and just clear struct io memebers. This was resulting in write/read_callback being call in loop due to fd being never written or read.
Diffstat (limited to 'src')
-rw-r--r--src/shared/io-glib.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/shared/io-glib.c b/src/shared/io-glib.c
index 725d974c5..ea84a69a9 100644
--- a/src/shared/io-glib.c
+++ b/src/shared/io-glib.c
@@ -145,8 +145,13 @@ bool io_set_read_handler(struct io *io, io_callback_func_t callback,
if (!io)
return false;
- if (io->read_watch > 0)
+ if (io->read_watch > 0) {
g_source_remove(io->read_watch);
+ io->read_watch = 0;
+ }
+
+ if (!callback)
+ goto done;
io->read_watch = g_io_add_watch_full(io->channel, G_PRIORITY_DEFAULT,
G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
@@ -154,6 +159,7 @@ bool io_set_read_handler(struct io *io, io_callback_func_t callback,
if (io->read_watch == 0)
return false;
+done:
io->read_callback = callback;
io->read_destroy = destroy;
io->read_data = user_data;
@@ -197,8 +203,13 @@ bool io_set_write_handler(struct io *io, io_callback_func_t callback,
if (!io)
return false;
- if (io->write_watch > 0)
+ if (io->write_watch > 0) {
g_source_remove(io->write_watch);
+ io->write_watch = 0;
+ }
+
+ if (!callback)
+ goto done;
io->write_watch = g_io_add_watch_full(io->channel, G_PRIORITY_DEFAULT,
G_IO_OUT | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
@@ -206,6 +217,7 @@ bool io_set_write_handler(struct io *io, io_callback_func_t callback,
if (io->write_watch == 0)
return false;
+done:
io->write_callback = callback;
io->write_destroy = destroy;
io->write_data = user_data;