diff options
| author | Garrett D'Amore <garrett@damore.org> | 2017-06-06 22:30:57 -0700 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2017-06-06 22:30:57 -0700 |
| commit | cff5dd2669031498fec9e3757c986d2fc99228e2 (patch) | |
| tree | 5b7d6cd16cab5317132fbf6ed2b7120b1b53d5a4 /src/core/endpt.c | |
| parent | bf2eb2eed3232cb9f3872d46c5e6bca8855840be (diff) | |
| download | nng-cff5dd2669031498fec9e3757c986d2fc99228e2.tar.gz nng-cff5dd2669031498fec9e3757c986d2fc99228e2.tar.bz2 nng-cff5dd2669031498fec9e3757c986d2fc99228e2.zip | |
More endpoint plumbing before pipes move to objhash.
Diffstat (limited to 'src/core/endpt.c')
| -rw-r--r-- | src/core/endpt.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/core/endpt.c b/src/core/endpt.c index d598caa2..91ddb318 100644 --- a/src/core/endpt.c +++ b/src/core/endpt.c @@ -52,6 +52,13 @@ nni_ep_hold(nni_ep **epp, uint32_t id) if (rv != 0) { return (NNG_ECLOSED); } + nni_mtx_lock(&ep->ep_mtx); + if (ep->ep_close) { + nni_mtx_unlock(&ep->ep_mtx); + nni_objhash_unref(nni_eps, id); + return (NNG_ECLOSED); + } + nni_mtx_unlock(&ep->ep_mtx); if (epp != NULL) { *epp = ep; } @@ -90,6 +97,8 @@ nni_ep_ctor(uint32_t id) NNI_LIST_NODE_INIT(&ep->ep_node); + nni_pipe_ep_list_init(&ep->ep_pipes); + if ((rv = nni_mtx_init(&ep->ep_mtx)) != 0) { NNI_FREE_STRUCT(ep); return (NULL); @@ -214,6 +223,40 @@ nni_ep_connect(nni_ep *ep, nni_pipe **pp) } +int +nni_ep_add_pipe(nni_ep *ep, nni_pipe *pipe) +{ + int rv; + + if ((rv = nni_ep_hold(NULL, ep->ep_id)) != 0) { + return (rv); + } + nni_mtx_lock(&ep->ep_mtx); + if (ep->ep_close) { + nni_mtx_unlock(&ep->ep_mtx); + nni_ep_rele(ep); + } + nni_list_append(&ep->ep_pipes, pipe); + nni_mtx_unlock(&ep->ep_mtx); + + return (0); +} + + +void +nni_ep_rem_pipe(nni_ep *ep, nni_pipe *pipe) +{ + nni_mtx_lock(&ep->ep_mtx); + if (!nni_list_active(&ep->ep_pipes, pipe)) { + nni_mtx_unlock(&ep->ep_mtx); + return; + } + nni_list_remove(&ep->ep_pipes, pipe); + nni_mtx_unlock(&ep->ep_mtx); + nni_ep_rele(ep); +} + + // nni_dial_once just does a single dial call, so it can be used // for synchronous dialing. static int |
