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 | |
| 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')
| -rw-r--r-- | src/core/endpt.c | 31 | ||||
| -rw-r--r-- | src/core/endpt.h | 1 | ||||
| -rw-r--r-- | src/core/pipe.c | 5 |
3 files changed, 16 insertions, 21 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); } diff --git a/src/core/endpt.h b/src/core/endpt.h index 65eb5d57..f37ea7cc 100644 --- a/src/core/endpt.h +++ b/src/core/endpt.h @@ -55,7 +55,6 @@ extern void nni_ep_remove(nni_ep *); extern int nni_ep_dial(nni_ep *, int); extern int nni_ep_listen(nni_ep *, int); extern void nni_ep_list_init(nni_list *); -extern int nni_ep_pipe_add(nni_ep *, nni_pipe *); extern void nni_ep_pipe_remove(nni_ep *, nni_pipe *); #endif // CORE_ENDPT_H diff --git a/src/core/pipe.c b/src/core/pipe.c index aceff611..6fa9ed47 100644 --- a/src/core/pipe.c +++ b/src/core/pipe.c @@ -218,11 +218,6 @@ nni_pipe_create(nni_pipe **pp, nni_ep *ep, nni_sock *sock, nni_tran *tran) return (rv); } - if ((rv = nni_ep_pipe_add(ep, p)) != 0) { - nni_pipe_destroy(p); - return (rv); - } - *pp = p; return (0); } |
