aboutsummaryrefslogtreecommitdiff
path: root/src/sp
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2021-10-16 23:27:35 -0700
committerGarrett D'Amore <garrett@damore.org>2021-10-16 23:27:35 -0700
commit9248ed7426e24443b42438797adcfa6d4714efe8 (patch)
treef0b4659264c73272cfaae47247a2f58563ef34b4 /src/sp
parent8d7dcb68d90524a316d2df99d4043a83ce72d6ea (diff)
downloadnng-9248ed7426e24443b42438797adcfa6d4714efe8.tar.gz
nng-9248ed7426e24443b42438797adcfa6d4714efe8.tar.bz2
nng-9248ed7426e24443b42438797adcfa6d4714efe8.zip
fixes #1518 Disconnect during negotiation breaks listener
Diffstat (limited to 'src/sp')
-rw-r--r--src/sp/transport/ipc/ipc.c21
-rw-r--r--src/sp/transport/tcp/tcp.c14
-rw-r--r--src/sp/transport/tls/tls.c13
3 files changed, 33 insertions, 15 deletions
diff --git a/src/sp/transport/ipc/ipc.c b/src/sp/transport/ipc/ipc.c
index 8ed4ac94..df27ad23 100644
--- a/src/sp/transport/ipc/ipc.c
+++ b/src/sp/transport/ipc/ipc.c
@@ -1,5 +1,5 @@
//
-// Copyright 2020 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2021 Staysail Systems, Inc. <info@staysail.tech>
// Copyright 2018 Capitar IT Group BV <info@capitar.com>
// Copyright 2019 Devolutions <info@devolutions.net>
//
@@ -10,7 +10,6 @@
//
#include <stdio.h>
-#include <stdlib.h>
#include "core/nng_impl.h"
@@ -251,8 +250,8 @@ ipc_pipe_neg_cb(void *arg)
nni_mtx_unlock(&p->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->rx_head[0] != 0) || (p->rx_head[1] != 'S') ||
(p->rx_head[2] != 'P') || (p->rx_head[3] != 0) ||
(p->rx_head[6] != 0) || (p->rx_head[7] != 0)) {
@@ -262,7 +261,7 @@ ipc_pipe_neg_cb(void *arg)
NNI_GET16(&p->rx_head[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->neg_pipes, p);
nni_list_append(&ep->wait_pipes, p);
@@ -272,7 +271,13 @@ ipc_pipe_neg_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 we are waiting to negotiate on a client side, then a failure
// here has to be passed to the user app.
@@ -347,7 +352,7 @@ ipc_pipe_recv_cb(void *arg)
if ((rv = nni_aio_result(rx_aio)) != 0) {
// Error on receive. This has to cause an error back
- // to the user. Also, if we had allocated an rx_msg, lets
+ // to the user. Also, if we had an allocated rx_msg, lets
// toss it.
goto error;
}
@@ -406,7 +411,7 @@ ipc_pipe_recv_cb(void *arg)
}
}
- // Otherwise we got a message read completely. Let the user know the
+ // Otherwise, we got a message read completely. Let the user know the
// good news.
aio = nni_list_first(&p->recv_q);
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 <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -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) {
diff --git a/src/sp/transport/tls/tls.c b/src/sp/transport/tls/tls.c
index 75858839..4db9170d 100644
--- a/src/sp/transport/tls/tls.c
+++ b/src/sp/transport/tls/tls.c
@@ -258,8 +258,8 @@ tlstran_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)) {
@@ -269,7 +269,7 @@ tlstran_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);
@@ -280,6 +280,13 @@ tlstran_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->tls);
if ((uaio = ep->useraio) != NULL) {