From 6ef1b39de8c0b0537da02b212acaba3242afe142 Mon Sep 17 00:00:00 2001 From: Guus Sliepen Date: Sun, 7 Jul 2019 16:54:25 +0200 Subject: [PATCH] Start the connection timeout timer when we have unACKed data. Start it when we are have some data to send, and reset it whenever some of the data is ACKed. Stop the timer if the peer has received all the data. Also ensure the poll callback is called with len = 0 when the timeout is hit. --- utcp.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/utcp.c b/utcp.c index 4875f84..f4bd7cf 100644 --- a/utcp.c +++ b/utcp.c @@ -639,6 +639,11 @@ ssize_t utcp_send(struct utcp_connection *c, const void *data, size_t len) { start_retransmit_timer(c); } + if(is_reliable(c) && !timerisset(&c->conn_timeout)) { + gettimeofday(&c->conn_timeout, NULL); + c->conn_timeout.tv_sec += c->utcp->timeout; + } + return len; } @@ -1334,12 +1339,13 @@ ssize_t utcp_recv(struct utcp *utcp, const void *data, size_t len) { // 4. Update timers if(advanced) { - timerclear(&c->conn_timeout); // It will be set anew in utcp_timeout() if c->snd.una != c->snd.nxt. - if(c->snd.una == c->snd.last) { stop_retransmit_timer(c); + timerclear(&c->conn_timeout); } else if(is_reliable(c)) { start_retransmit_timer(c); + gettimeofday(&c->conn_timeout, NULL); + c->conn_timeout.tv_sec += utcp->timeout; } } @@ -1734,6 +1740,10 @@ struct timeval utcp_timeout(struct utcp *utcp) { c->recv(c, NULL, 0); } + if(c->poll) { + c->poll(c, 0); + } + continue; } -- 2.39.2