]> git.meshlink.io Git - meshlink/commitdiff
Clear send and receive buffers before channel close/error callbacks.
authorGuus Sliepen <guus@meshlink.io>
Thu, 29 Apr 2021 16:59:18 +0000 (18:59 +0200)
committerGuus Sliepen <guus@meshlink.io>
Thu, 29 Apr 2021 16:59:18 +0000 (18:59 +0200)
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

index 11a9eead2960ae33a7523280c950da26970b3ef4..fa45e9c625b4b4e1d28c07ea49d881dad40e2107 100644 (file)
@@ -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);
                        }