diff options
| author | Garrett D'Amore <garrett@damore.org> | 2017-01-17 20:15:23 -0800 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2017-01-17 20:15:23 -0800 |
| commit | 4707cfd45be0d807081c53d9a16cc05e1d0cf4bc (patch) | |
| tree | 21491ad897703e0073c7b648d6ab5c752391b5a7 /src/core/endpt.c | |
| parent | 5633a467a009945a4f1eb06f7ffe9f02b833567f (diff) | |
| download | nng-4707cfd45be0d807081c53d9a16cc05e1d0cf4bc.tar.gz nng-4707cfd45be0d807081c53d9a16cc05e1d0cf4bc.tar.bz2 nng-4707cfd45be0d807081c53d9a16cc05e1d0cf4bc.zip | |
Public pipe and endpoint APIs use IDs instead of pointers.
Diffstat (limited to 'src/core/endpt.c')
| -rw-r--r-- | src/core/endpt.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/core/endpt.c b/src/core/endpt.c index 09ef0884..58b30b9f 100644 --- a/src/core/endpt.c +++ b/src/core/endpt.c @@ -38,6 +38,14 @@ nni_ep_create(nni_ep **epp, nni_sock *sock, const char *addr) ep->ep_pipe = NULL; ep->ep_tran = tran; + nni_mtx_lock(nni_idlock); + rv = nni_idhash_alloc(nni_endpoints, &ep->ep_id, ep); + nni_mtx_unlock(nni_idlock); + if (rv != 0) { + NNI_FREE_STRUCT(ep); + return (rv); + } + // Make a copy of the endpoint operations. This allows us to // modify them (to override NULLs for example), and avoids an extra // dereference on hot paths. @@ -45,6 +53,9 @@ nni_ep_create(nni_ep **epp, nni_sock *sock, const char *addr) NNI_LIST_NODE_INIT(&ep->ep_node); if ((rv = nni_cv_init(&ep->ep_cv, &ep->ep_sock->s_mx)) != 0) { + nni_mtx_lock(nni_idlock); + nni_idhash_remove(nni_endpoints, ep->ep_id); + nni_mtx_unlock(nni_idlock); NNI_FREE_STRUCT(ep); return (NNG_ENOMEM); } @@ -54,6 +65,9 @@ nni_ep_create(nni_ep **epp, nni_sock *sock, const char *addr) rv = ep->ep_ops.ep_init(&ep->ep_data, addr, nni_sock_proto(sock)); if (rv != 0) { + nni_mtx_lock(nni_idlock); + nni_idhash_remove(nni_endpoints, ep->ep_id); + nni_mtx_unlock(nni_idlock); nni_cv_fini(&ep->ep_cv); NNI_FREE_STRUCT(ep); return (rv); @@ -92,6 +106,10 @@ nni_ep_close(nni_ep *ep) ep->ep_ops.ep_fini(ep->ep_data); nni_cv_fini(&ep->ep_cv); + nni_mtx_lock(nni_idlock); + nni_idhash_remove(nni_endpoints, ep->ep_id); + nni_mtx_unlock(nni_idlock); + NNI_FREE_STRUCT(ep); } |
