]> git.meshlink.io Git - utcp/commitdiff
Call the receive callback for unclosed channels during utcp_exit().
authorGuus Sliepen <guus@meshlink.io>
Sun, 13 Aug 2017 19:46:24 +0000 (21:46 +0200)
committerGuus Sliepen <guus@meshlink.io>
Sun, 13 Aug 2017 19:46:24 +0000 (21:46 +0200)
This allows the application to clean up any resources associated with
these UTCP connections.

utcp.c

diff --git a/utcp.c b/utcp.c
index 340b059a6917e2738242b4292439a407924cc003..57b98135ad482b5cb29dbe6f9549db6ac6adaeaa 100644 (file)
--- a/utcp.c
+++ b/utcp.c
@@ -1555,11 +1555,13 @@ void utcp_exit(struct utcp *utcp) {
        if(!utcp)
                return;
        for(int i = 0; i < utcp->nconnections; i++) {
-               if(!utcp->connections[i]->reapable)
-                       debug("Warning, freeing unclosed connection %p\n", utcp->connections[i]);
-               buffer_exit(&utcp->connections[i]->rcvbuf);
-               buffer_exit(&utcp->connections[i]->sndbuf);
-               free(utcp->connections[i]);
+               struct utcp_connection *c = utcp->connections[i];
+               if(!c->reapable)
+                       if(c->recv)
+                               c->recv(c, NULL, 0);
+               buffer_exit(&c->rcvbuf);
+               buffer_exit(&c->sndbuf);
+               free(c);
        }
        free(utcp->connections);
        free(utcp);