diff --git a/src/shared/io-glib.c b/src/shared/io-glib.c
index 010dc71..725d974 100644
--- a/src/shared/io-glib.c
+++ b/src/shared/io-glib.c
gpointer user_data)
{
struct io *io = user_data;
+ bool result;
if (cond & (G_IO_HUP | G_IO_ERR | G_IO_NVAL))
return FALSE;
if (io->read_callback)
- io->read_callback(io, io->read_data);
+ result = io->read_callback(io, io->read_data);
+ else
+ result = false;
- return TRUE;
+ return result ? TRUE : FALSE;
}
bool io_set_read_handler(struct io *io, io_callback_func_t callback,
gpointer user_data)
{
struct io *io = user_data;
+ bool result;
if (cond & (G_IO_HUP | G_IO_ERR | G_IO_NVAL))
return FALSE;
if (io->write_callback)
- io->write_callback(io, io->write_data);
+ result = io->write_callback(io, io->write_data);
+ else
+ result = false;
- return TRUE;
+ return result ? TRUE : FALSE;
}
bool io_set_write_handler(struct io *io, io_callback_func_t callback,
diff --git a/src/shared/io.h b/src/shared/io.h
index c48a7ab..2c47e39 100644
--- a/src/shared/io.h
+++ b/src/shared/io.h
struct io;
-typedef void (*io_callback_func_t) (struct io *io, void *user_data);
-
struct io *io_new(int fd);
void io_destroy(struct io *io);
int io_get_fd(struct io *io);
bool io_set_close_on_destroy(struct io *io, bool do_close);
-typedef void (*io_callback_func_t)(struct io *io, void *user_data);
+typedef bool (*io_callback_func_t)(struct io *io, void *user_data);
bool io_set_read_handler(struct io *io, io_callback_func_t callback,
void *user_data, io_destroy_func_t destroy);
diff --git a/src/shared/mgmt.c b/src/shared/mgmt.c
index b499c71..2a2c2a3 100644
--- a/src/shared/mgmt.c
+++ b/src/shared/mgmt.c
mgmt->writer_active = false;
}
-static void can_write_data(struct io *io, void *user_data)
+static bool can_write_data(struct io *io, void *user_data)
{
struct mgmt *mgmt = user_data;
struct mgmt_request *request;
if (!request) {
/* only reply commands can jump the queue */
if (!queue_isempty(mgmt->pending_list))
- goto done;
+ return false;
request = queue_pop_head(mgmt->request_queue);
if (!request)
- goto done;
+ return false;
}
bytes_written = write(mgmt->fd, request->buf, request->len);
request->callback(MGMT_STATUS_FAILED, 0, NULL,
request->user_data);
destroy_request(request);
- return;
+ return true;
}
util_debug(mgmt->debug_callback, mgmt->debug_data,
queue_push_tail(mgmt->pending_list, request);
-done:
- io_set_write_handler(mgmt->io, NULL, NULL, NULL);
+ return false;
}
static void wakeup_writer(struct mgmt *mgmt)
free(mgmt);
}
-static void data_ready(struct io *io, void *user_data)
+static bool can_read_data(struct io *io, void *user_data)
{
struct mgmt *mgmt = user_data;
struct mgmt_hdr *hdr;
bytes_read = read(mgmt->fd, mgmt->buf, mgmt->len);
if (bytes_read < 0)
- return;
+ return false;
util_hexdump('>', mgmt->buf, bytes_read,
mgmt->debug_callback, mgmt->debug_data);
if (bytes_read < MGMT_HDR_SIZE)
- return;
+ return true;
hdr = mgmt->buf;
event = btohs(hdr->opcode);
length = btohs(hdr->len);
if (bytes_read < length + MGMT_HDR_SIZE)
- return ;
+ return true;
switch (event) {
case MGMT_EV_CMD_COMPLETE:
}
if (mgmt->destroyed)
- io_set_read_handler(mgmt->io, NULL, NULL, NULL);
+ return false;
+
+ return true;
}
struct mgmt *mgmt_new(int fd)
return NULL;
}
- if (!io_set_read_handler(mgmt->io, data_ready, mgmt,
- read_watch_destroy)) {
+ if (!io_set_read_handler(mgmt->io, can_read_data, mgmt,
+ read_watch_destroy)) {
queue_destroy(mgmt->notify_list, NULL);
queue_destroy(mgmt->pending_list, NULL);
queue_destroy(mgmt->reply_queue, NULL);