]> git.meshlink.io Git - utcp/commitdiff
Start the connection timeout timer when we have unACKed data.
authorGuus Sliepen <guus@sliepen.org>
Sun, 7 Jul 2019 14:54:25 +0000 (16:54 +0200)
committerGuus Sliepen <guus@sliepen.org>
Sun, 7 Jul 2019 14:54:25 +0000 (16:54 +0200)
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

diff --git a/utcp.c b/utcp.c
index 4875f8405ef7799aa5a935b3d1910a88d668f2a6..f4bd7cf718c19197c00ad14efb1b322275a21739 100644 (file)
--- 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);
        }
 
                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;
 }
 
        return len;
 }
 
@@ -1334,12 +1339,13 @@ ssize_t utcp_recv(struct utcp *utcp, const void *data, size_t len) {
        // 4. Update timers
 
        if(advanced) {
        // 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);
                if(c->snd.una == c->snd.last) {
                        stop_retransmit_timer(c);
+                       timerclear(&c->conn_timeout);
                } else if(is_reliable(c)) {
                        start_retransmit_timer(c);
                } 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);
                        }
 
                                c->recv(c, NULL, 0);
                        }
 
+                       if(c->poll) {
+                               c->poll(c, 0);
+                       }
+
                        continue;
                }
 
                        continue;
                }