From 41240a36a2e5ac62912dee8bcaad0d92aa1a0e17 Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Mon, 8 Dec 2014 11:02:28 +0200 Subject: [PATCH] shared/mgmt: Add synchronous write support --- src/shared/mgmt.c | 14 ++++++++++++++ src/shared/mgmt.h | 2 ++ 2 files changed, 16 insertions(+) diff --git a/src/shared/mgmt.c b/src/shared/mgmt.c index 6330c6f7e..e57699096 100644 --- a/src/shared/mgmt.c +++ b/src/shared/mgmt.c @@ -45,6 +45,7 @@ struct mgmt { bool close_on_unref; struct io *io; bool writer_active; + bool sync_write; struct queue *request_queue; struct queue *reply_queue; struct queue *pending_list; @@ -210,6 +211,8 @@ static bool can_write_data(struct io *io, void *user_data) static void wakeup_writer(struct mgmt *mgmt) { + while (mgmt->sync_write && can_write_data(mgmt->io, mgmt)); + if (!queue_isempty(mgmt->pending_list)) { /* only queued reply commands trigger wakeup */ if (queue_isempty(mgmt->reply_queue)) @@ -461,6 +464,7 @@ struct mgmt *mgmt_new(int fd) } mgmt->writer_active = false; + mgmt->sync_write = false; return mgmt_ref(mgmt); } @@ -575,6 +579,16 @@ bool mgmt_set_close_on_unref(struct mgmt *mgmt, bool do_close) return true; } +bool mgmt_set_sync_write(struct mgmt *mgmt, bool sync_write) +{ + if (!mgmt) + return false; + + mgmt->sync_write = sync_write; + + return true; +} + static struct mgmt_request *create_request(uint16_t opcode, uint16_t index, uint16_t length, const void *param, mgmt_request_func_t callback, diff --git a/src/shared/mgmt.h b/src/shared/mgmt.h index 626a6992a..49c8c9981 100644 --- a/src/shared/mgmt.h +++ b/src/shared/mgmt.h @@ -43,6 +43,8 @@ bool mgmt_set_debug(struct mgmt *mgmt, mgmt_debug_func_t callback, bool mgmt_set_close_on_unref(struct mgmt *mgmt, bool do_close); +bool mgmt_set_sync_write(struct mgmt *mgmt, bool sync_write); + typedef void (*mgmt_request_func_t)(uint8_t status, uint16_t length, const void *param, void *user_data); -- 2.47.3