diff options
| author | Garrett D'Amore <garrett@damore.org> | 2017-07-13 22:29:32 -0700 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2017-07-13 22:29:32 -0700 |
| commit | 36746b4f6615607510eedb8e5d168b0fc4897ded (patch) | |
| tree | 4ff163e144ee254730a0965edba2fe2b3feaa8f0 /src/core/endpt.c | |
| parent | f7463b4bd9b549a152b28aff959113b9ab56959a (diff) | |
| download | nng-36746b4f6615607510eedb8e5d168b0fc4897ded.tar.gz nng-36746b4f6615607510eedb8e5d168b0fc4897ded.tar.bz2 nng-36746b4f6615607510eedb8e5d168b0fc4897ded.zip | |
Close a race during pipe creation.
Diffstat (limited to 'src/core/endpt.c')
| -rw-r--r-- | src/core/endpt.c | 31 |
1 files changed, 16 insertions, 15 deletions
diff --git a/src/core/endpt.c b/src/core/endpt.c index 7784de73..8eb7dd12 100644 --- a/src/core/endpt.c +++ b/src/core/endpt.c @@ -248,10 +248,19 @@ nni_ep_connect_sync(nni_ep *ep) nni_pipe *pipe; int rv; + nni_mtx_lock(&ep->ep_mtx); + if (ep->ep_closed) { + nni_mtx_unlock(&ep->ep_mtx); + return (NNG_ECLOSED); + } rv = nni_pipe_create(&pipe, ep, ep->ep_sock, ep->ep_tran); if (rv != 0) { + nni_mtx_unlock(&ep->ep_mtx); return (rv); } + nni_list_append(&ep->ep_pipes, pipe); + nni_mtx_unlock(&ep->ep_mtx); + rv = nni_ep_connect_aio(ep, &pipe->p_tran_data); if (rv != 0) { nni_pipe_stop(pipe); @@ -264,21 +273,6 @@ nni_ep_connect_sync(nni_ep *ep) return (0); } -int -nni_ep_pipe_add(nni_ep *ep, nni_pipe *pipe) -{ - nni_mtx_lock(&ep->ep_mtx); - if (ep->ep_closed) { - nni_mtx_unlock(&ep->ep_mtx); - return (NNG_ECLOSED); - } - - nni_list_append(&ep->ep_pipes, pipe); - nni_mtx_unlock(&ep->ep_mtx); - - return (0); -} - void nni_ep_pipe_remove(nni_ep *ep, nni_pipe *pipe) { @@ -426,18 +420,25 @@ nni_ep_accept_sync(nni_ep *ep) nni_pipe *pipe; int rv; + nni_mtx_lock(&ep->ep_mtx); if (ep->ep_closed) { + nni_mtx_unlock(&ep->ep_mtx); return (NNG_ECLOSED); } rv = nni_pipe_create(&pipe, ep, ep->ep_sock, ep->ep_tran); if (rv != 0) { + nni_mtx_unlock(&ep->ep_mtx); return (rv); } + nni_list_append(&ep->ep_pipes, pipe); + nni_mtx_unlock(&ep->ep_mtx); + rv = nni_ep_accept_aio(ep, &pipe->p_tran_data); if (rv != 0) { nni_pipe_stop(pipe); return (rv); } + nni_pipe_start(pipe); return (0); } |
