aboutsummaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2017-06-09 11:06:56 -0700
committerGarrett D'Amore <garrett@damore.org>2017-06-09 11:06:56 -0700
commit4cc196e94f129139d8ed0d4d176d12ef76f4c6c5 (patch)
tree4c2b7df948084944adb12321be614c2387cc3b03 /src/core
parent52432d8061f0d5fe3d9363b34cf5ffe7ad138a06 (diff)
downloadnng-4cc196e94f129139d8ed0d4d176d12ef76f4c6c5.tar.gz
nng-4cc196e94f129139d8ed0d4d176d12ef76f4c6c5.tar.bz2
nng-4cc196e94f129139d8ed0d4d176d12ef76f4c6c5.zip
Endpoint close can be moved later; add check for closed in pipe_add.
Diffstat (limited to 'src/core')
-rw-r--r--src/core/socket.c25
1 files changed, 16 insertions, 9 deletions
diff --git a/src/core/socket.c b/src/core/socket.c
index 53d7ba9c..ee653780 100644
--- a/src/core/socket.c
+++ b/src/core/socket.c
@@ -86,6 +86,11 @@ nni_sock_pipe_add(nni_sock *sock, nni_pipe *pipe)
// XXX: place a hold on the socket.
nni_mtx_lock(&sock->s_mx);
+ if (sock->s_closing) {
+ nni_mtx_unlock(&sock->s_mx);
+ sock->s_pipe_ops.pipe_fini(pdata);
+ return (NNG_ECLOSED);
+ }
nni_pipe_set_proto_data(pipe, pdata);
nni_list_append(&sock->s_pipes, pipe);
nni_mtx_unlock(&sock->s_mx);
@@ -155,7 +160,10 @@ nni_sock_pipe_rem(nni_sock *sock, nni_pipe *pipe)
void *pdata = nni_pipe_get_proto_data(pipe);
nni_mtx_lock(&sock->s_mx);
- nni_list_remove(&sock->s_pipes, pipe);
+
+ if (nni_list_active(&sock->s_pipes, pipe)) {
+ nni_list_remove(&sock->s_pipes, pipe);
+ }
if (pdata != NULL) {
sock->s_pipe_ops.pipe_fini(pdata);
@@ -529,14 +537,6 @@ nni_sock_shutdown(nni_sock *sock)
// Mark us closing, so no more EPs or changes can occur.
sock->s_closing = 1;
- // Stop all EPS. We're going to do this first, since we know
- // we're closing.
- while ((ep = nni_list_first(&sock->s_eps)) != NULL) {
- nni_mtx_unlock(&sock->s_mx);
- nni_ep_close(ep);
- nni_mtx_lock(&sock->s_mx);
- }
-
// Special optimization; if there are no pipes connected,
// then there is no reason to linger since there's nothing that
// could possibly send this data out.
@@ -574,6 +574,13 @@ nni_sock_shutdown(nni_sock *sock)
nni_msgq_close(sock->s_urq);
nni_msgq_close(sock->s_uwq);
+ // Stop all EPS.
+ while ((ep = nni_list_first(&sock->s_eps)) != NULL) {
+ nni_mtx_unlock(&sock->s_mx);
+ nni_ep_close(ep);
+ nni_mtx_lock(&sock->s_mx);
+ }
+
// For each pipe, close the underlying transport. Also move it
// to the idle list so we won't keep looping.
while ((pipe = nni_list_first(&sock->s_pipes)) != NULL) {