Skip to content

Commit

Permalink
fix: increase buffer size with length field for stream links
Browse files Browse the repository at this point in the history
  • Loading branch information
jean-roland committed Dec 18, 2023
1 parent cd1aab1 commit 479c173
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/transport/unicast/transport.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,21 @@ int8_t _z_unicast_transport_create(_z_transport_t *zt, _z_link_t *zl, _z_transpo
if (ret == _Z_RES_OK) {
uint16_t mtu = (zl->_mtu < Z_BATCH_UNICAST_SIZE) ? zl->_mtu : Z_BATCH_UNICAST_SIZE;
size_t dbuf_size = 0;
size_t wbuf_size = 0;
size_t zbuf_size = 0;
_Bool expandable = false;

switch (zl->_cap._flow) {
case Z_LINK_CAP_FLOW_STREAM:
// Add stream length field to buffer size
wbuf_size = mtu + _Z_MSG_LEN_ENC_SIZE;
zbuf_size = Z_BATCH_UNICAST_SIZE + _Z_MSG_LEN_ENC_SIZE;
expandable = true;
break;
case Z_LINK_CAP_FLOW_DATAGRAM:
default:
wbuf_size = mtu;
zbuf_size = Z_BATCH_UNICAST_SIZE;
expandable = false;
break;
}
Expand All @@ -67,16 +74,17 @@ int8_t _z_unicast_transport_create(_z_transport_t *zt, _z_link_t *zl, _z_transpo
expandable = false;
dbuf_size = Z_FRAG_MAX_SIZE;
#endif
zt->_transport._unicast._wbuf = _z_wbuf_make(mtu, false);
zt->_transport._unicast._zbuf = _z_zbuf_make(Z_BATCH_UNICAST_SIZE);
// Initialize tx rx buffers
zt->_transport._unicast._wbuf = _z_wbuf_make(wbuf_size, false);
zt->_transport._unicast._zbuf = _z_zbuf_make(zbuf_size);

// Initialize the defragmentation buffers
zt->_transport._unicast._dbuf_reliable = _z_wbuf_make(dbuf_size, expandable);
zt->_transport._unicast._dbuf_best_effort = _z_wbuf_make(dbuf_size, expandable);

// Clean up the buffers if one of them failed to be allocated
if ((_z_wbuf_capacity(&zt->_transport._unicast._wbuf) != mtu) ||
(_z_zbuf_capacity(&zt->_transport._unicast._zbuf) != Z_BATCH_UNICAST_SIZE) ||
if ((_z_wbuf_capacity(&zt->_transport._unicast._wbuf) != wbuf_size) ||
(_z_zbuf_capacity(&zt->_transport._unicast._zbuf) != zbuf_size) ||
#if Z_FEATURE_DYNAMIC_MEMORY_ALLOCATION == 0
(_z_wbuf_capacity(&zt->_transport._unicast._dbuf_reliable) != dbuf_size) ||
(_z_wbuf_capacity(&zt->_transport._unicast._dbuf_best_effort) != dbuf_size)) {
Expand Down

0 comments on commit 479c173

Please sign in to comment.