]> git.meshlink.io Git - utcp/commitdiff
Add fin_wanted() function that checks whether a FIN bit should be set on a packet.
authorGuus Sliepen <guus@meshlink.io>
Wed, 10 Dec 2014 10:09:59 +0000 (11:09 +0100)
committerGuus Sliepen <guus@meshlink.io>
Wed, 10 Dec 2014 10:09:59 +0000 (11:09 +0100)
utcp.c

diff --git a/utcp.c b/utcp.c
index d49c4ddcce2cfbf5822efb899b49b4cd186419c4..f062319fa33a1daa665faaa96f3c567eb488f245 100644 (file)
--- a/utcp.c
+++ b/utcp.c
@@ -103,6 +103,19 @@ static void set_state(struct utcp_connection *c, enum state state) {
        debug("%p new state: %s\n", c->utcp, strstate[state]);
 }
 
+static bool fin_wanted(struct utcp_connection *c, uint32_t seq) {
+       if(seq != c->snd.last)
+               return false;
+       switch(c->state) {
+       case FIN_WAIT_1:
+       case CLOSING:
+       case LAST_ACK:
+               return true;
+       default:
+               return false;
+       }
+}
+
 static inline void list_connections(struct utcp *utcp) {
        debug("%p has %d connections:\n", utcp, utcp->nconnections);
        for(int i = 0; i < utcp->nconnections; i++)
@@ -366,16 +379,9 @@ static void ack(struct utcp_connection *c, bool sendatleastone) {
                c->snd.nxt += seglen;
                left -= seglen;
 
-               if(c->state != ESTABLISHED && seglen && c->snd.nxt == c->snd.last) {
-                       switch(c->state) {
-                       case FIN_WAIT_1:
-                       case CLOSING:
-                               seglen--;
-                               pkt->hdr.ctl |= FIN;
-                               break;
-                       default:
-                               break;
-                       }
+               if(seglen && fin_wanted(c, c->snd.nxt)) {
+                       seglen--;
+                       pkt->hdr.ctl |= FIN;
                }
 
                print_packet(c->utcp, "send", pkt, sizeof pkt->hdr + seglen);