Skip to content

Commit

Permalink
feat: add zp_batch_flush
Browse files Browse the repository at this point in the history
  • Loading branch information
jean-roland committed Nov 19, 2024
1 parent 45343b3 commit 9489266
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
19 changes: 15 additions & 4 deletions include/zenoh-pico/api/primitives.h
Original file line number Diff line number Diff line change
Expand Up @@ -2063,9 +2063,9 @@ const z_loaned_keyexpr_t *z_subscriber_keyexpr(const z_loaned_subscriber_t *subs
#ifdef Z_FEATURE_UNSTABLE_API
#if Z_FEATURE_BATCHING == 1
/**
* Activate the batching mechanism.
* Any message that would have been sent on the network by a subsequent api call (e.g z_put, z_get)
* will be instead stored until the batch is full or batching is stopped with :c:func:`zp_batch_stop`.
* Activate the batching mechanism, any message that would have been sent on the network by a subsequent api call (e.g
* z_put, z_get) will be instead stored until the batch is full, flushed with :c:func:`zp_batch_flush` or batching is
* stopped with :c:func:`zp_batch_stop`.
*
* Parameters:
* zs: Pointer to a :c:type:`z_loaned_session_t` that will start batching messages.
Expand All @@ -2076,7 +2076,18 @@ const z_loaned_keyexpr_t *z_subscriber_keyexpr(const z_loaned_subscriber_t *subs
z_result_t zp_batch_start(const z_loaned_session_t *zs);

/**
* Deactivate the batching mechanism and flush the remaining messages.
* Send the currently batched messages on the network.
*
* Parameters:
* zs: Pointer to a :c:type:`z_loaned_session_t` that will send its batched messages.
*
* Return:
* ``0`` if batch successfully sent, ``negative value`` otherwise.
*/
z_result_t zp_batch_flush(const z_loaned_session_t *zs);

/**
* Deactivate the batching mechanism and send the currently batched on the network.
*
* Parameters:
* zs: Pointer to a :c:type:`z_loaned_session_t` that will stop batching messages.
Expand Down
9 changes: 9 additions & 0 deletions src/api/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -1432,6 +1432,15 @@ z_result_t zp_batch_start(const z_loaned_session_t *zs) {
return _z_transport_start_batching(&session->_tp) ? _Z_RES_OK : _Z_ERR_GENERIC;
}

z_result_t zp_batch_flush(const z_loaned_session_t *zs) {
_z_session_t *session = _Z_RC_IN_VAL(zs);
if (_Z_RC_IS_NULL(zs)) {
return _Z_ERR_SESSION_CLOSED;
}
// Send current batch
return _z_send_n_batch(session, Z_CONGESTION_CONTROL_DEFAULT);
}

z_result_t zp_batch_stop(const z_loaned_session_t *zs) {
_z_session_t *session = _Z_RC_IN_VAL(zs);
if (_Z_RC_IS_NULL(zs)) {
Expand Down

0 comments on commit 9489266

Please sign in to comment.