From 9bb7cc335a29c6624ccd8fd0dd32417587a95dec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nils=20O=2E=20Sel=C3=A5sdal?= Date: Sun, 29 Nov 2015 01:05:40 +0100 Subject: [PATCH] Add uc_wqueue_flush() to immedately preform mbuf writes --- include/ucore/wqueue.h | 17 +++++++++++++++++ src/wqueue.c | 11 +++++++++++ 2 files changed, 28 insertions(+) diff --git a/include/ucore/wqueue.h b/include/ucore/wqueue.h index 7e32511..3a460dd 100644 --- a/include/ucore/wqueue.h +++ b/include/ucore/wqueue.h @@ -103,4 +103,21 @@ int uc_wqueue_clear(struct UCWQueue *wqueue); */ int uc_wqueue_enqueue(struct UCWQueue *wqueue, struct MBuf *mbuf); + +/** + * Immediately write mbufs. + * This invokes the wqueue write callback immediately, just as if an + * write event from the IOMux had happened. + * + * As for a normal write event, the entire queue might not be + * written, if the associated write callback detectes it cannot write + * more data. + * + * @param wqueue + * + * return 0 if no error occured, -1 if the write callback returned + * UC_WQ_ABORT + */ +int uc_wqueue_flush(struct UCWQueue *wqueue); + #endif diff --git a/src/wqueue.c b/src/wqueue.c index 13c3067..33ccfe2 100644 --- a/src/wqueue.c +++ b/src/wqueue.c @@ -43,6 +43,8 @@ static int uc_wqueue_handle_write(struct UCWQueue *wqueue) return rc; } + + static void uc_wqueue_cb(struct IOMux *mux, struct IOMuxFD *fd, unsigned int what) { int rc = 0; @@ -110,3 +112,12 @@ int uc_wqueue_enqueue(struct UCWQueue *wqueue, struct MBuf *mbuf) return 0; } + +int uc_wqueue_flush(struct UCWQueue *wqueue) +{ + if (uc_wqueue_handle_write(wqueue) < 0) { + return -1; + } + + return 0; +}