]> git.meshlink.io Git - meshlink/blobdiff - src/utcp.c
The maximum unreliable packet size is 65535 bytes.
[meshlink] / src / utcp.c
index d2a929bf734a598b51ff8d2dd309b08c3383516c..c4305cd4de4978d265155f2dcb537cd746e39251 100644 (file)
@@ -719,7 +719,7 @@ static void ack(struct utcp_connection *c, bool sendatleastone) {
                        pkt->hdr.ctl |= FIN;
                }
 
-               if(!c->rtt_start.tv_sec) {
+               if(!c->rtt_start.tv_sec && is_reliable(c)) {
                        // Start RTT measurement
                        clock_gettime(UTCP_CLOCK, &c->rtt_start);
                        c->rtt_seq = pkt->hdr.seq + seglen;
@@ -1147,7 +1147,7 @@ static void handle_unreliable(struct utcp_connection *c, const struct hdr *hdr,
        }
 
        // Ensure reassembled packet are not larger than 64 kiB
-       if(hdr->wnd >= MAX_UNRELIABLE_SIZE || hdr->wnd + len > MAX_UNRELIABLE_SIZE) {
+       if(hdr->wnd > MAX_UNRELIABLE_SIZE || hdr->wnd + len > MAX_UNRELIABLE_SIZE) {
                return;
        }
 
@@ -2052,6 +2052,11 @@ void utcp_abort_all_connections(struct utcp *utcp) {
 }
 
 int utcp_close(struct utcp_connection *c) {
+       if(c->rcvbuf.used) {
+               fprintf(stderr, "UTCP channel closed with stuff in receive buffer\n");
+               return reset_connection(c) ? 0 : -1;
+       }
+
        if(utcp_shutdown(c, SHUT_RDWR) && errno != ENOTCONN) {
                return -1;
        }