diff options
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); } |
