aboutsummaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2017-01-17 20:15:23 -0800
committerGarrett D'Amore <garrett@damore.org>2017-01-17 20:15:23 -0800
commit4707cfd45be0d807081c53d9a16cc05e1d0cf4bc (patch)
tree21491ad897703e0073c7b648d6ab5c752391b5a7 /src/core
parent5633a467a009945a4f1eb06f7ffe9f02b833567f (diff)
downloadnng-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')
-rw-r--r--src/core/defs.h4
-rw-r--r--src/core/endpt.c18
-rw-r--r--src/core/endpt.h11
-rw-r--r--src/core/pipe.h2
4 files changed, 27 insertions, 8 deletions
diff --git a/src/core/defs.h b/src/core/defs.h
index 50540102..eb1a6475 100644
--- a/src/core/defs.h
+++ b/src/core/defs.h
@@ -23,14 +23,14 @@
// These types are common but have names shared with user space.
typedef struct nng_socket nni_sock;
-typedef struct nng_endpoint nni_ep;
-typedef struct nng_pipe nni_pipe;
typedef struct nng_msg nni_msg;
typedef struct nng_sockaddr nni_sockaddr;
typedef struct nng_event nni_event;
typedef struct nng_notify nni_notify;
// These are our own names.
+typedef struct nni_ep nni_ep;
+typedef struct nni_pipe nni_pipe;
typedef struct nni_tran nni_tran;
typedef struct nni_tran_ep nni_tran_ep;
typedef struct nni_tran_pipe nni_tran_pipe;
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);
}
diff --git a/src/core/endpt.h b/src/core/endpt.h
index bff0ec6d..a3b2ce9e 100644
--- a/src/core/endpt.h
+++ b/src/core/endpt.h
@@ -15,11 +15,12 @@
// NB: This structure is supplied here for use by the CORE. Use of this
// OUSIDE of the core is STRICTLY VERBOTEN. NO DIRECT ACCESS BY PROTOCOLS
// OR TRANSPORTS.
-struct nng_endpoint {
- nni_tran_ep ep_ops;
- nni_tran * ep_tran;
- void * ep_data; // Transport private
- nni_list_node ep_node; // Per socket list
+struct nni_ep {
+ nni_tran_ep ep_ops; // transport ops
+ nni_tran * ep_tran; // transport pointer
+ void * ep_data; // transport private
+ uint32_t ep_id; // endpoint id
+ nni_list_node ep_node; // per socket list
nni_sock * ep_sock;
char ep_addr[NNG_MAXADDRLEN];
nni_thr ep_thr;
diff --git a/src/core/pipe.h b/src/core/pipe.h
index 65d2ede5..d54f1ce7 100644
--- a/src/core/pipe.h
+++ b/src/core/pipe.h
@@ -17,7 +17,7 @@
#include "core/defs.h"
#include "core/transport.h"
-struct nng_pipe {
+struct nni_pipe {
uint32_t p_id;
nni_tran_pipe p_tran_ops;
void * p_tran_data;