add resend feature for reliable stream

Signed-off-by: liuming24 <liuming24@baidu.com>
This commit is contained in:
liuming24 2024-11-15 15:59:27 +08:00
parent 0301e0dc23
commit 2de8d27e54
3 changed files with 14 additions and 0 deletions

View File

@ -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.")

View File

@ -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@

View File

@ -64,6 +64,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);
@ -164,6 +165,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;
}