From 0f9dfb9be6cddc09a358452ca0e15222b160c9eb Mon Sep 17 00:00:00 2001 From: Guus Sliepen Date: Sun, 3 May 2020 22:37:41 +0200 Subject: [PATCH] Don't call the poll callback with a length larger than the remaining UTCP send buffer. --- src/meshlink.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/meshlink.c b/src/meshlink.c index db958afa..80bcc970 100644 --- a/src/meshlink.c +++ b/src/meshlink.c @@ -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); -- 2.39.2