]> git.meshlink.io Git - meshlink/commitdiff
Don't call the poll callback with a length larger than the remaining UTCP send buffer.
authorGuus Sliepen <guus@meshlink.io>
Sun, 3 May 2020 20:37:41 +0000 (22:37 +0200)
committerGuus Sliepen <guus@meshlink.io>
Sun, 3 May 2020 20:44:49 +0000 (22:44 +0200)
src/meshlink.c

index db958afa037888fd4248a37f2bb84b8af543e6c5..80bcc9704480afc84c2bbffe2203db85d2a93ac3 100644 (file)
@@ -3915,7 +3915,11 @@ bool meshlink_channel_aio_send(meshlink_handle_t *mesh, meshlink_channel_t *chan
 
        /* Ensure the poll callback is set, and call it right now to push data if possible */
        utcp_set_poll_cb(channel->c, channel_poll);
-       channel_poll(channel->c, len);
+       size_t todo = MIN(len, utcp_get_rcvbuf_free(channel->c));
+
+       if(todo) {
+               channel_poll(channel->c, todo);
+       }
 
        pthread_mutex_unlock(&mesh->mutex);
 
@@ -3952,7 +3956,11 @@ bool meshlink_channel_aio_fd_send(meshlink_handle_t *mesh, meshlink_channel_t *c
 
        /* Ensure the poll callback is set, and call it right now to push data if possible */
        utcp_set_poll_cb(channel->c, channel_poll);
-       channel_poll(channel->c, len);
+       size_t left = utcp_get_rcvbuf_free(channel->c);
+
+       if(left) {
+               channel_poll(channel->c, left);
+       }
 
        pthread_mutex_unlock(&mesh->mutex);