diff --git a/include/zenoh-pico/api/primitives.h b/include/zenoh-pico/api/primitives.h index b28f3ec6c..3da9ab8f0 100644 --- a/include/zenoh-pico/api/primitives.h +++ b/include/zenoh-pico/api/primitives.h @@ -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. @@ -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. diff --git a/src/api/api.c b/src/api/api.c index 40f3e5ed3..c4b827209 100644 --- a/src/api/api.c +++ b/src/api/api.c @@ -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)) {