aboutsummaryrefslogtreecommitdiff
path: root/src/core/endpt.c
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2016-12-22 23:17:12 -0800
committerGarrett D'Amore <garrett@damore.org>2016-12-22 23:17:12 -0800
commitbca0a27e2f4978a5a74748b07613c0e30014880c (patch)
treea6beea2e7e63e02be070e4b124dd40c92917dbd6 /src/core/endpt.c
parent29628309ae018c3f317eef9b03625d4ce3807a92 (diff)
downloadnng-bca0a27e2f4978a5a74748b07613c0e30014880c.tar.gz
nng-bca0a27e2f4978a5a74748b07613c0e30014880c.tar.bz2
nng-bca0a27e2f4978a5a74748b07613c0e30014880c.zip
Implemened synchronous & asynchronuos dialer, accepter. Getting close...
Diffstat (limited to 'src/core/endpt.c')
-rw-r--r--src/core/endpt.c40
1 files changed, 29 insertions, 11 deletions
diff --git a/src/core/endpt.c b/src/core/endpt.c
index fd328b0f..ad1a0b9a 100644
--- a/src/core/endpt.c
+++ b/src/core/endpt.c
@@ -49,6 +49,8 @@ nni_endpt_create(nni_endpt **epp, nni_socket *sock, const char *addr)
ep->ep_dialer = NULL;
ep->ep_listener = NULL;
ep->ep_close = 0;
+ ep->ep_start = 0;
+ ep->ep_pipe = NULL;
if ((rv = nni_mutex_init(&ep->ep_mx)) != 0) {
nni_free(ep, sizeof (*ep));
return (NNG_ENOMEM);
@@ -71,7 +73,6 @@ nni_endpt_create(nni_endpt **epp, nni_socket *sock, const char *addr)
nni_free(ep, sizeof (*ep));
return (rv);
}
- NNI_LIST_INIT(&ep->ep_pipes, nni_pipe, p_ep_node);
*epp = ep;
return (0);
}
@@ -81,17 +82,12 @@ nni_endpt_destroy(nni_endpt *ep)
{
// We should already have been closed at this point, so this
// should proceed very quickly.
- if (ep->ep_dialer) {
+ if (ep->ep_dialer != NULL) {
nni_thread_reap(ep->ep_dialer);
}
- if (ep->ep_listener) {
+ if (ep->ep_listener != NULL) {
nni_thread_reap(ep->ep_listener);
}
- nni_mutex_enter(&ep->ep_mx);
- while (nni_list_first(&ep->ep_pipes) != NULL) {
- nni_cond_wait(&ep->ep_cv);
- }
- nni_mutex_exit(&ep->ep_mx);
ep->ep_ops.ep_destroy(ep->ep_data);
@@ -103,6 +99,7 @@ nni_endpt_destroy(nni_endpt *ep)
void
nni_endpt_close(nni_endpt *ep)
{
+ nni_pipe *pipe;
nni_mutex_enter(&ep->ep_mx);
if (ep->ep_close) {
nni_mutex_exit(&ep->ep_mx);
@@ -110,6 +107,10 @@ nni_endpt_close(nni_endpt *ep)
}
ep->ep_close = 1;
ep->ep_ops.ep_close(ep->ep_data);
+ if ((pipe = ep->ep_pipe) != NULL) {
+ pipe->p_ep = NULL;
+ ep->ep_pipe = NULL;
+ }
nni_cond_broadcast(&ep->ep_cv);
nni_mutex_exit(&ep->ep_mx);
}
@@ -144,6 +145,23 @@ nni_endpt_dial(nni_endpt *ep, nni_pipe **pp)
return (0);
}
-#if 0
-int nni_endpt_accept(nni_endpt *, nni_pipe **);
-#endif
+int
+nni_endpt_accept(nni_endpt *ep, nni_pipe **pp)
+{
+ nni_pipe *pipe;
+ int rv;
+
+ if (ep->ep_close) {
+ return (NNG_ECLOSED);
+ }
+ if ((rv = nni_pipe_create(&pipe, ep->ep_ops.ep_pipe_ops)) != 0) {
+ return (rv);
+ }
+ if ((rv = ep->ep_ops.ep_accept(ep->ep_data, &pipe->p_data)) != 0) {
+ nni_pipe_destroy(pipe);
+ return (rv);
+ }
+ pipe->p_ep = ep;
+ *pp = pipe;
+ return (0);
+}