From 0f36bb393e49ecab387b1bfe88741a337d4a8834 Mon Sep 17 00:00:00 2001 From: Guus Sliepen Date: Sun, 13 Aug 2017 17:43:48 +0200 Subject: [PATCH] Allow timers to be reset. The function utcp_reset_timers() will reset the retransmit timers of all connections to zero, so they will fire immediately. The connection timeout will be reset to the user timeout value, and if the RTO is larger than the starting RTO, it will be set to the starting RTO. --- utcp.c | 16 ++++++++++++++++ utcp.h | 2 ++ 2 files changed, 18 insertions(+) diff --git a/utcp.c b/utcp.c index bfd9921..02d3c98 100644 --- a/utcp.c +++ b/utcp.c @@ -1512,6 +1512,22 @@ void utcp_set_mtu(struct utcp *utcp, uint16_t mtu) { utcp->mtu = mtu; } +void utcp_reset_timers(struct utcp *utcp) { + if(!utcp) + return; + struct timeval now, then; + gettimeofday(&now, NULL); + then = now; + then.tv_sec += utcp->timeout; + for(int i = 0; i < utcp->nconnections; i++) { + utcp->connections[i]->rtrx_timeout = now; + utcp->connections[i]->conn_timeout = then; + utcp->connections[i]->rtt_start.tv_sec = 0; + } + if(utcp->rto > START_RTO) + utcp->rto = START_RTO; +} + int utcp_get_user_timeout(struct utcp *u) { return u ? u->timeout : 0; } diff --git a/utcp.h b/utcp.h index 8fcb28a..f8fad0c 100644 --- a/utcp.h +++ b/utcp.h @@ -86,6 +86,8 @@ extern void utcp_set_user_timeout(struct utcp *utcp, int seconds); extern uint16_t utcp_get_mtu(struct utcp *utcp); extern void utcp_set_mtu(struct utcp *utcp, uint16_t mtu); +extern void utcp_reset_timers(struct utcp *utcp); + // Per-socket options extern size_t utcp_get_sndbuf(struct utcp_connection *connection); -- 2.39.2