]> git.meshlink.io Git - meshlink/blobdiff - src/utcp.c
Wake up the MeshLink thread if framed channel data is pending to be flushed.
[meshlink] / src / utcp.c
index 8ef59a063fdf8f3af5a1fbb021deced7775c7e73..d6b0a590fed3670615a687ef9c01e44dab2454f1 100644 (file)
@@ -875,11 +875,19 @@ static void ack_unreliable_framed(struct utcp_connection *c) {
        if(sent_packet) {
                if(left) {
                        // We sent one packet but we have partial data left, (re)start the flush timer
+                       if(!timespec_isset(&c->rtrx_timeout)) {
+                               c->flush_needed = true;
+                       }
+
                        start_flush_timer(c);
                } else {
                        // There is no partial data in the send buffer, so stop the flush timer
                        stop_retransmit_timer(c);
                }
+       } else if(left && !timespec_isset(&c->rtrx_timeout)) {
+               // We have partial data and we didn't start the flush timer yet
+               c->flush_needed = true;
+               start_flush_timer(c);
        }
 }
 
@@ -1441,11 +1449,11 @@ static void handle_unreliable_framed(struct utcp_connection *c, const struct hdr
        buffer_clear(&c->rcvbuf);
 
        // Handle whole frames
-       while(left > 2) {
+       while(left >= 2) {
                uint16_t framelen;
                memcpy(&framelen, ptr, sizeof(framelen));
 
-               if(left <= (size_t)framelen + 2) {
+               if(left < (size_t)framelen + 2) {
                        break;
                }
 
@@ -2787,3 +2795,9 @@ int utcp_get_flush_timeout(struct utcp *utcp) {
 void utcp_set_flush_timeout(struct utcp *utcp, int milliseconds) {
        utcp->flush_timeout = milliseconds;
 }
+
+bool utcp_get_flush_needed(struct utcp_connection *c) {
+       bool value = c->flush_needed;
+       c->flush_needed = false;
+       return value;
+}