summaryrefslogtreecommitdiffstats
path: root/src/vpp-api
diff options
context:
space:
mode:
authorDau Do <daudo@yahoo.com>2024-06-10 19:55:19 -0700
committerMatthew Smith <mgsmith@netgate.com>2024-06-14 19:16:18 +0000
commit10dbb372ccc83d87c6a6cd6898c24c436613e1e5 (patch)
treea3cdbfdcc03ac31504504f40861bdb317b046371 /src/vpp-api
parent4677d920c0b0ff1f1aae81fb2f0052d939a2e89c (diff)
vapi: Add option to dispatch with timeout
Type: improvement Change-Id: I606efc90d9b1b8e2a2590a8b4e0021e2508642b2 Signed-off-by: Dau Do <daudo@yahoo.com>
Diffstat (limited to 'src/vpp-api')
-rw-r--r--src/vpp-api/vapi/vapi.c13
-rw-r--r--src/vpp-api/vapi/vapi.h22
2 files changed, 27 insertions, 8 deletions
diff --git a/src/vpp-api/vapi/vapi.c b/src/vpp-api/vapi/vapi.c
index 022f023aeb0..26c5708342f 100644
--- a/src/vpp-api/vapi/vapi.c
+++ b/src/vpp-api/vapi/vapi.c
@@ -1792,14 +1792,15 @@ vapi_verify_msg_size (vapi_msg_id_t id, void *buf, uword buf_size)
}
vapi_error_e
-vapi_dispatch_one (vapi_ctx_t ctx)
+vapi_dispatch_one_timedwait (vapi_ctx_t ctx, u32 wait_time)
{
VAPI_DBG ("vapi_dispatch_one()");
void *msg;
uword size;
svm_q_conditional_wait_t cond =
- vapi_is_nonblocking (ctx) ? SVM_Q_NOWAIT : SVM_Q_WAIT;
- vapi_error_e rv = vapi_recv (ctx, &msg, &size, cond, 0);
+ vapi_is_nonblocking (ctx) ? (wait_time ? SVM_Q_TIMEDWAIT : SVM_Q_NOWAIT) :
+ SVM_Q_WAIT;
+ vapi_error_e rv = vapi_recv (ctx, &msg, &size, cond, wait_time);
if (VAPI_OK != rv)
{
VAPI_DBG ("vapi_recv failed with rv=%d", rv);
@@ -1847,6 +1848,12 @@ done:
}
vapi_error_e
+vapi_dispatch_one (vapi_ctx_t ctx)
+{
+ return vapi_dispatch_one_timedwait (ctx, 0);
+}
+
+vapi_error_e
vapi_dispatch (vapi_ctx_t ctx)
{
vapi_error_e rv = VAPI_OK;
diff --git a/src/vpp-api/vapi/vapi.h b/src/vpp-api/vapi/vapi.h
index 970c5080667..8f092eed1c2 100644
--- a/src/vpp-api/vapi/vapi.h
+++ b/src/vpp-api/vapi/vapi.h
@@ -225,6 +225,18 @@ vapi_error_e vapi_wait (vapi_ctx_t ctx);
/**
* @brief pick next message sent by vpp and call the appropriate callback
*
+ * @note if using block mode, it will be blocked indefinitely until the next
+ * msg available. If using non-blocking mode, it will block for time_wait
+ * seconds until the next msg available if time_wait > 0, or does not block if
+ * time_wait == 0.
+ *
+ * @return VAPI_OK on success, other error code on error
+ */
+vapi_error_e vapi_dispatch_one_timedwait (vapi_ctx_t ctx, u32 wait_time);
+
+/**
+ * @brief pick next message sent by vpp and call the appropriate callback
+ *
* @return VAPI_OK on success, other error code on error
*/
vapi_error_e vapi_dispatch_one (vapi_ctx_t ctx);
@@ -235,11 +247,11 @@ vapi_error_e vapi_dispatch_one (vapi_ctx_t ctx);
*
* @note the dispatch loop is interrupted if any error is encountered or
* returned from the callback, in which case this error is returned as the
- * result of vapi_dispatch. In this case it might be necessary to call dispatch
- * again to process the remaining messages. Returning VAPI_EUSER from
- * a callback allows the user to break the dispatch loop (and distinguish
- * this case in the calling code from other failures). VAPI never returns
- * VAPI_EUSER on its own.
+ * result of vapi_dispatch. In this case it might be necessary to call
+ * dispatch again to process the remaining messages. Returning VAPI_EUSER
+ * from a callback allows the user to break the dispatch loop (and
+ * distinguish this case in the calling code from other failures). VAPI never
+ * returns VAPI_EUSER on its own.
*
* @return VAPI_OK on success, other error code on error
*/