From 9248ed7426e24443b42438797adcfa6d4714efe8 Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Sat, 16 Oct 2021 23:27:35 -0700 Subject: fixes #1518 Disconnect during negotiation breaks listener --- src/sp/transport/tcp/tcp.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'src/sp/transport/tcp') diff --git a/src/sp/transport/tcp/tcp.c b/src/sp/transport/tcp/tcp.c index e2e7fbce..624403a7 100644 --- a/src/sp/transport/tcp/tcp.c +++ b/src/sp/transport/tcp/tcp.c @@ -9,7 +9,6 @@ // found online at https://opensource.org/licenses/MIT. // -#include #include #include @@ -259,8 +258,8 @@ tcptran_pipe_nego_cb(void *arg) nni_mtx_unlock(&ep->mtx); return; } - // We have both sent and received the headers. Lets check the - // receive side header. + // We have both sent and received the headers. Let's check the + // receiver. if ((p->rxlen[0] != 0) || (p->rxlen[1] != 'S') || (p->rxlen[2] != 'P') || (p->rxlen[3] != 0) || (p->rxlen[6] != 0) || (p->rxlen[7] != 0)) { @@ -270,7 +269,7 @@ tcptran_pipe_nego_cb(void *arg) NNI_GET16(&p->rxlen[4], p->peer); - // We are all ready now. We put this in the wait list, and + // We are ready now. We put this in the wait list, and // then try to run the matcher. nni_list_remove(&ep->negopipes, p); nni_list_append(&ep->waitpipes, p); @@ -281,6 +280,13 @@ tcptran_pipe_nego_cb(void *arg) return; error: + // If the connection is closed, we need to pass back a different + // error code. This is necessary to avoid a problem where the + // closed status is confused with the accept file descriptor + // being closed. + if (rv == NNG_ECLOSED) { + rv = NNG_ECONNSHUT; + } nng_stream_close(p->conn); if ((uaio = ep->useraio) != NULL) { -- cgit v1.2.3-70-g09d2