From 32ab3f06ce82167e2670bd9c7c58a0c21a2550c2 Mon Sep 17 00:00:00 2001 From: Guus Sliepen Date: Thu, 29 Apr 2021 18:59:18 +0200 Subject: [PATCH] Clear send and receive buffers before channel close/error callbacks. When there is an error that would cause the poll callback to be called with length zero, make sure we drop the buffers first, so that calls to meshlink_channel_get_sendq() will also return zero. This allows poll callbacks that wait for the send buffer to be emptied to work correctly. --- src/utcp.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/utcp.c b/src/utcp.c index 11a9eead..fa45e9c6 100644 --- a/src/utcp.c +++ b/src/utcp.c @@ -1600,6 +1600,8 @@ synack: // The peer has aborted our connection. set_state(c, CLOSED); errno = ECONNRESET; + buffer_clear(&c->sndbuf); + buffer_clear(&c->rcvbuf); if(c->recv) { c->recv(c, NULL, 0); @@ -2208,6 +2210,8 @@ struct timespec utcp_timeout(struct utcp *utcp) { if(timespec_isset(&c->conn_timeout) && timespec_lt(&c->conn_timeout, &now)) { errno = ETIMEDOUT; c->state = CLOSED; + buffer_clear(&c->sndbuf); + buffer_clear(&c->rcvbuf); if(c->recv) { c->recv(c, NULL, 0); @@ -2310,6 +2314,9 @@ void utcp_exit(struct utcp *utcp) { struct utcp_connection *c = utcp->connections[i]; if(!c->reapable) { + buffer_clear(&c->sndbuf); + buffer_clear(&c->rcvbuf); + if(c->recv) { c->recv(c, NULL, 0); } -- 2.39.2