X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=src%2Futcp.c;h=20dd0aba049757ca30833779ec772c63ba685310;hb=HEAD;hp=8b3509ef0f5c376ee7b37640cb3c82dba1819df4;hpb=0f5ab29d787c7fb444908797d5ea746cb4311be4;p=meshlink diff --git a/src/utcp.c b/src/utcp.c index 8b3509ef..ca91bee2 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); @@ -2072,8 +2074,8 @@ static bool reset_connection(struct utcp_connection *c) { return false; } - c->recv = NULL; - c->poll = NULL; + buffer_clear(&c->sndbuf); + buffer_clear(&c->rcvbuf); switch(c->state) { case CLOSED: @@ -2106,6 +2108,7 @@ static bool reset_connection(struct utcp_connection *c) { hdr.ack = c->rcv.nxt; hdr.wnd = 0; hdr.ctl = RST; + hdr.aux = 0; print_packet(c, "send", &hdr, sizeof(hdr)); c->utcp->send(c->utcp, &hdr, sizeof(hdr)); @@ -2121,8 +2124,8 @@ static void set_reapable(struct utcp_connection *c) { c->reapable = true; } -// Closes all the opened connections -void utcp_abort_all_connections(struct utcp *utcp) { +// Resets all connections, but does not invalidate connection handles +void utcp_reset_all_connections(struct utcp *utcp) { if(!utcp) { errno = EINVAL; return; @@ -2135,19 +2138,16 @@ void utcp_abort_all_connections(struct utcp *utcp) { continue; } - utcp_recv_t old_recv = c->recv; - utcp_poll_t old_poll = c->poll; - - utcp_abort(c); + reset_connection(c); - if(old_recv) { + if(c->recv) { errno = 0; - old_recv(c, NULL, 0); + c->recv(c, NULL, 0); } - if(old_poll && !c->reapable) { + if(c->poll && !c->reapable) { errno = 0; - old_poll(c, 0); + c->poll(c, 0); } } @@ -2204,6 +2204,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); @@ -2306,6 +2308,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); }