aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2017-06-06 22:30:57 -0700
committerGarrett D'Amore <garrett@damore.org>2017-06-06 22:30:57 -0700
commitcff5dd2669031498fec9e3757c986d2fc99228e2 (patch)
tree5b7d6cd16cab5317132fbf6ed2b7120b1b53d5a4
parentbf2eb2eed3232cb9f3872d46c5e6bca8855840be (diff)
downloadnng-cff5dd2669031498fec9e3757c986d2fc99228e2.tar.gz
nng-cff5dd2669031498fec9e3757c986d2fc99228e2.tar.bz2
nng-cff5dd2669031498fec9e3757c986d2fc99228e2.zip
More endpoint plumbing before pipes move to objhash.
-rw-r--r--src/core/endpt.c43
-rw-r--r--src/core/endpt.h3
2 files changed, 46 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
diff --git a/src/core/endpt.h b/src/core/endpt.h
index a9029cc9..7991a916 100644
--- a/src/core/endpt.h
+++ b/src/core/endpt.h
@@ -33,6 +33,7 @@ struct nni_ep {
nni_mtx ep_mtx;
nni_cv ep_cv;
nni_pipe * ep_pipe; // Connected pipe (dialers only)
+ nni_list ep_pipes;
};
#define NNI_EP_MODE_IDLE 0
@@ -50,5 +51,7 @@ extern void nni_ep_close(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_add_pipe(nni_ep *, nni_pipe *);
+extern void nni_ep_rem_pipe(nni_ep *, nni_pipe *);
#endif // CORE_ENDPT_H