Skip to content

Commit

Permalink
feat: get is express status directly in tx
Browse files Browse the repository at this point in the history
  • Loading branch information
jean-roland committed Jan 7, 2025
1 parent fb34c35 commit 3843b90
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
2 changes: 2 additions & 0 deletions include/zenoh-pico/protocol/definitions/network.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ extern "C" {

typedef _z_qos_t _z_n_qos_t;

#define _Z_N_QOS_IS_EXPRESS_FLAG (1 << 4)

static inline _z_qos_t _z_n_qos_create(bool express, z_congestion_control_t congestion_control, z_priority_t priority) {
_z_n_qos_t ret;
bool nodrop = congestion_control == Z_CONGESTION_CONTROL_DROP ? 0 : 1;
Expand Down
29 changes: 24 additions & 5 deletions src/transport/common/tx.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,25 @@

/*------------------ Transmission helper ------------------*/

static bool _z_transport_tx_get_express_status(const _z_network_message_t *msg) {
switch (msg->_tag) {
case _Z_N_DECLARE: {
return _Z_HAS_FLAG(msg->_body._declare._ext_qos._val, _Z_N_QOS_IS_EXPRESS_FLAG);
} break;
case _Z_N_PUSH: {
return _Z_HAS_FLAG(msg->_body._push._qos._val, _Z_N_QOS_IS_EXPRESS_FLAG);
} break;
case _Z_N_REQUEST: {
return _Z_HAS_FLAG(msg->_body._request._ext_qos._val, _Z_N_QOS_IS_EXPRESS_FLAG);
} break;
case _Z_N_RESPONSE: {
return _Z_HAS_FLAG(msg->_body._response._ext_qos._val, _Z_N_QOS_IS_EXPRESS_FLAG);
} break;
default:
return false;
}
}

static _z_zint_t _z_transport_tx_get_sn(_z_transport_common_t *ztc, z_reliability_t reliability) {
_z_zint_t sn;
if (reliability == Z_RELIABILITY_RELIABLE) {
Expand All @@ -45,7 +64,7 @@ static z_result_t _z_transport_tx_send_fragment_inner(_z_transport_common_t *ztc
bool is_first = true;
_z_zint_t sn = first_sn;
// Encode message on temp buffer
_Z_RETURN_IF_ERR(_z_network_message_encode(frag_buff, n_msg, NULL));
_Z_RETURN_IF_ERR(_z_network_message_encode(frag_buff, n_msg));
// Fragment message
while (_z_wbuf_len(frag_buff) > 0) {
// Get fragment sequence number
Expand Down Expand Up @@ -139,8 +158,8 @@ static z_result_t _z_transport_tx_batch_overflow(_z_transport_common_t *ztc, con
_z_transport_message_t t_msg = _z_t_msg_make_frame_header(sn, reliability);
_Z_RETURN_IF_ERR(_z_transport_message_encode(&ztc->_wbuf, &t_msg));
// Retry encode
bool is_express = false;
z_result_t ret = _z_network_message_encode(&ztc->_wbuf, n_msg, &is_express);
bool is_express = _z_transport_tx_get_express_status(n_msg);
z_result_t ret = _z_network_message_encode(&ztc->_wbuf, n_msg);
if (ret != _Z_RES_OK) {
// Message still doesn't fit in buffer, send as fragments
return _z_transport_tx_send_fragment(ztc, n_msg, reliability, sn);
Expand Down Expand Up @@ -186,8 +205,8 @@ static z_result_t _z_transport_tx_send_n_msg_inner(_z_transport_common_t *ztc, c
}
// Try encoding the network message
size_t prev_wpos = _z_transport_tx_save_wpos(&ztc->_wbuf);
bool is_express = false;
z_result_t ret = _z_network_message_encode(&ztc->_wbuf, n_msg, &is_express);
bool is_express = _z_transport_tx_get_express_status(n_msg);
z_result_t ret = _z_network_message_encode(&ztc->_wbuf, n_msg);
if (ret == _Z_RES_OK) {
if (is_express) {
// Send immediately
Expand Down

0 comments on commit 3843b90

Please sign in to comment.