aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2017-07-13 17:00:18 -0700
committerGarrett D'Amore <garrett@damore.org>2017-07-13 17:00:18 -0700
commit722cd0deed891bfcb3f1e9866655cc5a41b2111e (patch)
tree309f753ecd27d866bfca219db8ed943dd8c1e5ca /src
parent14c7b4c358d783d1969edb230f02e9e034565b7b (diff)
downloadnng-722cd0deed891bfcb3f1e9866655cc5a41b2111e.tar.gz
nng-722cd0deed891bfcb3f1e9866655cc5a41b2111e.tar.bz2
nng-722cd0deed891bfcb3f1e9866655cc5a41b2111e.zip
Close at least one of the race conditions in ipc closing.
Diffstat (limited to 'src')
-rw-r--r--src/transport/ipc/ipc.c27
1 files changed, 26 insertions, 1 deletions
diff --git a/src/transport/ipc/ipc.c b/src/transport/ipc/ipc.c
index 56ce5ecd..a019dfbc 100644
--- a/src/transport/ipc/ipc.c
+++ b/src/transport/ipc/ipc.c
@@ -1,5 +1,6 @@
//
// Copyright 2017 Garrett D'Amore <garrett@damore.org>
+// Copyright 2017 Capitar IT Group BV <info@capitar.com>
//
// This software is supplied under the terms of the MIT License, a
// copy of which should be located in the distribution where this
@@ -504,15 +505,26 @@ nni_ipc_ep_close(void *arg)
{
nni_ipc_ep *ep = arg;
+ nni_mtx_lock(&ep->mtx);
+ ep->closed = 1;
nni_plat_ipc_ep_close(ep->iep);
+ nni_mtx_unlock(&ep->mtx);
}
static int
nni_ipc_ep_bind(void *arg)
{
nni_ipc_ep *ep = arg;
+ int rv;
- return (nni_plat_ipc_ep_listen(ep->iep));
+ nni_mtx_lock(&ep->mtx);
+ if (ep->closed) {
+ rv = NNG_ECLOSED;
+ } else {
+ rv = nni_plat_ipc_ep_listen(ep->iep);
+ }
+ nni_mtx_unlock(&ep->mtx);
+ return (rv);
}
static void
@@ -576,6 +588,12 @@ nni_ipc_ep_accept(void *arg, nni_aio *aio)
nni_mtx_lock(&ep->mtx);
NNI_ASSERT(ep->user_aio == NULL);
+
+ if (ep->closed) {
+ nni_aio_finish(aio, NNG_ECLOSED, 0);
+ nni_mtx_unlock(&ep->mtx);
+ return;
+ }
ep->user_aio = aio;
// If we can't start, then its dying and we can't report either,
@@ -597,6 +615,13 @@ nni_ipc_ep_connect(void *arg, nni_aio *aio)
nni_mtx_lock(&ep->mtx);
NNI_ASSERT(ep->user_aio == NULL);
+
+ if (ep->closed) {
+ nni_aio_finish(aio, NNG_ECLOSED, 0);
+ nni_mtx_unlock(&ep->mtx);
+ return;
+ }
+
ep->user_aio = aio;
// If we can't start, then its dying and we can't report either,