diff options
| author | Garrett D'Amore <garrett@damore.org> | 2017-07-16 12:36:32 -0700 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2017-07-16 12:36:32 -0700 |
| commit | 09b31812fa2af4e67d9d9193aaae0d7111ded15f (patch) | |
| tree | cc0b1fce9c5ce181ac86430e2c49f11ae63714c0 /src/core/socket.c | |
| parent | b48b18b6be688d9611b71ca60d51491c5b5127c6 (diff) | |
| download | nng-09b31812fa2af4e67d9d9193aaae0d7111ded15f.tar.gz nng-09b31812fa2af4e67d9d9193aaae0d7111ded15f.tar.bz2 nng-09b31812fa2af4e67d9d9193aaae0d7111ded15f.zip | |
Fix locking errors in endpoints, and simplify some logic.
This cleans up the pipe creation logic greatly, and eliminates
a nasty potential deadlock (lock-order incorrect.) It also
adds a corret binary exponential and randomized backoff on both
accept and connect.
Diffstat (limited to 'src/core/socket.c')
| -rw-r--r-- | src/core/socket.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/core/socket.c b/src/core/socket.c index 75ae8450..ecddf5dd 100644 --- a/src/core/socket.c +++ b/src/core/socket.c @@ -757,6 +757,11 @@ nni_sock_dial(nni_sock *sock, const char *addr, nni_ep **epp, int flags) return (rv); } nni_list_append(&sock->s_eps, ep); + // Put a hold on the endpoint, for now. + nni_mtx_lock(&ep->ep_mtx); + ep->ep_refcnt++; + ep->ep_started = 1; + nni_mtx_unlock(&ep->ep_mtx); nni_mtx_unlock(&sock->s_mx); if ((rv = nni_ep_dial(ep, flags)) != 0) { @@ -765,6 +770,15 @@ nni_sock_dial(nni_sock *sock, const char *addr, nni_ep **epp, int flags) *epp = ep; } + // Drop our endpoint hold. + nni_mtx_lock(&ep->ep_mtx); + if (rv != 0) { + ep->ep_started = 0; + } + ep->ep_refcnt--; + nni_cv_wake(&ep->ep_cv); + nni_mtx_unlock(&ep->ep_mtx); + return (rv); } @@ -779,7 +793,12 @@ nni_sock_listen(nni_sock *sock, const char *addr, nni_ep **epp, int flags) nni_mtx_unlock(&sock->s_mx); return (rv); } + nni_list_append(&sock->s_eps, ep); + nni_mtx_lock(&ep->ep_mtx); + ep->ep_refcnt++; + ep->ep_started = 1; + nni_mtx_unlock(&ep->ep_mtx); nni_mtx_unlock(&sock->s_mx); if ((rv = nni_ep_listen(ep, flags)) != 0) { @@ -788,6 +807,15 @@ nni_sock_listen(nni_sock *sock, const char *addr, nni_ep **epp, int flags) *epp = ep; } + // Drop our endpoint hold. + nni_mtx_lock(&ep->ep_mtx); + if (rv != 0) { + ep->ep_started = 0; + } + ep->ep_refcnt--; + nni_cv_wake(&ep->ep_cv); + nni_mtx_unlock(&ep->ep_mtx); + return (rv); } |
