Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add resend feature for reliable stream #392

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ set(UCLIENT_MAX_INPUT_RELIABLE_STREAMS 1 CACHE STRING "Set the maximum number of
set(UCLIENT_MAX_SESSION_CONNECTION_ATTEMPTS 10 CACHE STRING "Set the number of connection attemps.")
set(UCLIENT_MIN_SESSION_CONNECTION_INTERVAL 1000 CACHE STRING "Set the connection interval in milliseconds.")
set(UCLIENT_MIN_HEARTBEAT_TIME_INTERVAL 100 CACHE STRING "Set the time interval between heartbeats in milliseconds.")
set(UCLIENT_RELIABLE_RESENT_TIME 100 CACHE STRING "Set the time for reliable stream resend in milliseconds.")
set(UCLIENT_UDP_TRANSPORT_MTU 512 CACHE STRING "Set the UDP transport MTU.")
set(UCLIENT_TCP_TRANSPORT_MTU 512 CACHE STRING "Set the TCP transport MTU.")
set(UCLIENT_SERIAL_TRANSPORT_MTU 512 CACHE STRING "Set the Serial transport MTU.")
Expand Down
1 change: 1 addition & 0 deletions include/uxr/client/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
#define UXR_CONFIG_MAX_SESSION_CONNECTION_ATTEMPTS @UCLIENT_MAX_SESSION_CONNECTION_ATTEMPTS@
#define UXR_CONFIG_MIN_SESSION_CONNECTION_INTERVAL @UCLIENT_MIN_SESSION_CONNECTION_INTERVAL@
#define UXR_CONFIG_MIN_HEARTBEAT_TIME_INTERVAL @UCLIENT_MIN_HEARTBEAT_TIME_INTERVAL@
#define UXR_CONFIG_RELIABLE_RESENT_TIME @UCLIENT_RELIABLE_RESENT_TIME@

#ifdef UCLIENT_PROFILE_UDP
#define UXR_CONFIG_UDP_TRANSPORT_MTU @UCLIENT_UDP_TRANSPORT_MTU@
Expand Down
13 changes: 13 additions & 0 deletions src/c/core/session/stream/output_reliable_stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "./common_reliable_stream_internal.h"
#include "../submessage_internal.h"
#include <uxr/client/profile/multithread/multithread.h>
#include <uxr/client/util/time.h>

#define MIN_HEARTBEAT_TIME_INTERVAL ((int64_t) UXR_CONFIG_MIN_HEARTBEAT_TIME_INTERVAL) // ms

Expand Down Expand Up @@ -64,6 +65,7 @@ bool uxr_prepare_reliable_buffer_to_write(

uint16_t available_block_size = (uint16_t)(buffer_capacity - (uint16_t)(stream->offset + SUBHEADER_SIZE));
size_t remaining_blocks = get_available_free_slots(stream);
static int64_t reliable_ackend_ts = 0x0;

// Aligment required for inserting an XRCE subheader
buffer_size += ucdr_alignment(buffer_size, 4);
Expand Down Expand Up @@ -164,6 +166,17 @@ bool uxr_prepare_reliable_buffer_to_write(
}
}

if (available_to_write == false) {
if (reliable_ackend_ts == 0x0) {
reliable_ackend_ts = uxr_millis() + UXR_CONFIG_RELIABLE_RESENT_TIME;
} else if (reliable_ackend_ts <= uxr_millis()) {
stream->last_sent = uxr_seq_num_sub(stream->last_sent, 1);
reliable_ackend_ts = uxr_millis() + UXR_CONFIG_RELIABLE_RESENT_TIME;
}
} else {
reliable_ackend_ts = 0x0;
}

return available_to_write;
}

Expand Down
5 changes: 5 additions & 0 deletions test/shared_memory/SharedMemory.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
extern "C"
{
#include <c/util/time.c>
}

#include <gtest/gtest.h>
#include <uxr/client/client.h>

Expand Down
1 change: 1 addition & 0 deletions test/unitary/session/streams/OutputReliableStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ extern "C"
#include <c/core/serialization/xrce_subheader.c>
#include <c/core/session/submessage.c>
#include <c/core/serialization/xrce_header.c>
#include <c/util/time.c>
}

#define BUFFER_SIZE size_t(128)
Expand Down