Skip to content

Commit

Permalink
FramingIO optimizations (eProsima#267)
Browse files Browse the repository at this point in the history
* FramingIO optimizations

* Fix warning

* Uncrustify

* Update src/c/profile/transport/stream_framing/stream_framing_protocol.c

Co-authored-by: Antonio Cuadros <49162117+Acuadros95@users.noreply.github.com>
Signed-off-by: Patrick Roncagliolo <ronca.pat@gmail.com>
  • Loading branch information
2 people authored and roncapat committed Nov 15, 2021
1 parent bf0cab0 commit a9b7c29
Showing 1 changed file with 46 additions and 4 deletions.
50 changes: 46 additions & 4 deletions src/c/profile/transport/stream_framing/stream_framing_protocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,8 @@ size_t uxr_framing_read_transport(
uxr_read_cb read_cb,
void* cb_arg,
int* timeout,
uint8_t* errcode)
uint8_t* errcode,
size_t max_size)
{
int64_t time_init = uxr_millis();

Expand Down Expand Up @@ -251,6 +252,18 @@ size_t uxr_framing_read_transport(
size_t bytes_read[2] = {
0
};

// Limit the reading size
if (max_size < av_len[0])
{
av_len[0] = (uint8_t)max_size;
av_len[1] = 0;
}
else if (max_size < av_len[0] + av_len[1])
{
av_len[1] = (uint8_t)(max_size - av_len[0]);
}

if (0 < av_len[0])
{
bytes_read[0] = read_cb(cb_arg, &framing_io->rb[framing_io->rb_head], av_len[0], *timeout, errcode);
Expand Down Expand Up @@ -282,9 +295,12 @@ size_t uxr_read_framed_msg(
{
size_t rv = 0;

size_t readed_bytes = uxr_framing_read_transport(framing_io, read_cb, cb_arg, timeout, errcode);
if (framing_io->rb_head == framing_io->rb_tail)
{
uxr_framing_read_transport(framing_io, read_cb, cb_arg, timeout, errcode, 5);
}

if (0 < readed_bytes || (framing_io->rb_tail != framing_io->rb_head))
if (framing_io->rb_tail != framing_io->rb_head)
{
/* State Machine. */
bool exit_cond = false;
Expand Down Expand Up @@ -317,6 +333,10 @@ size_t uxr_read_framed_msg(
if (uxr_get_next_octet(framing_io, &framing_io->src_addr))
{
framing_io->state = UXR_FRAMING_READING_DST_ADDR;
}
else if (0 < uxr_framing_read_transport(framing_io, read_cb, cb_arg, timeout, errcode, 4))
{

}
else
{
Expand All @@ -333,6 +353,10 @@ size_t uxr_read_framed_msg(
{
framing_io->state = (octet == framing_io->local_addr) ? UXR_FRAMING_READING_LEN_LSB :
UXR_FRAMING_UNINITIALIZED;
}
else if (0 < uxr_framing_read_transport(framing_io, read_cb, cb_arg, timeout, errcode, 3))
{

}
else
{
Expand All @@ -353,6 +377,10 @@ size_t uxr_read_framed_msg(
{
framing_io->msg_len = octet;
framing_io->state = UXR_FRAMING_READING_LEN_MSB;
}
else if (0 < uxr_framing_read_transport(framing_io, read_cb, cb_arg, timeout, errcode, 2))
{

}
else
{
Expand Down Expand Up @@ -383,6 +411,10 @@ size_t uxr_read_framed_msg(
{
framing_io->state = UXR_FRAMING_READING_PAYLOAD;
}
}
else if (0 < uxr_framing_read_transport(framing_io, read_cb, cb_arg, timeout, errcode, 1))
{

}
else
{
Expand Down Expand Up @@ -416,7 +448,9 @@ size_t uxr_read_framed_msg(
{
framing_io->state = UXR_FRAMING_READING_SRC_ADDR;
}
else if (0 < uxr_framing_read_transport(framing_io, read_cb, cb_arg, timeout, errcode))
else if (0 <
uxr_framing_read_transport(framing_io, read_cb, cb_arg, timeout, errcode,
(size_t)((framing_io->msg_len - framing_io->msg_pos) + 2)))
{

}
Expand All @@ -433,6 +467,10 @@ size_t uxr_read_framed_msg(
{
framing_io->msg_crc = octet;
framing_io->state = UXR_FRAMING_READING_CRC_MSB;
}
else if (0 < uxr_framing_read_transport(framing_io, read_cb, cb_arg, timeout, errcode, 2))
{

}
else
{
Expand All @@ -459,6 +497,10 @@ size_t uxr_read_framed_msg(
rv = framing_io->msg_len;
}
exit_cond = true;
}
else if (0 < uxr_framing_read_transport(framing_io, read_cb, cb_arg, timeout, errcode, 1))
{

}
else
{
Expand Down

0 comments on commit a9b7c29

Please sign in to comment.