aboutsummaryrefslogtreecommitdiff
path: root/src/core/socket.c
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2016-12-22 21:15:53 -0800
committerGarrett D'Amore <garrett@damore.org>2016-12-22 21:15:53 -0800
commit32cfbaccd7ac89c00207e5d1345d23abf455ce16 (patch)
tree4c119268c9d12dd0072d44d0d74c9176356df8ca /src/core/socket.c
parentee45cbf4498a3c1d1868469bdb0c767d66c278e4 (diff)
downloadnng-32cfbaccd7ac89c00207e5d1345d23abf455ce16.tar.gz
nng-32cfbaccd7ac89c00207e5d1345d23abf455ce16.tar.bz2
nng-32cfbaccd7ac89c00207e5d1345d23abf455ce16.zip
Implemented dialer core.
Diffstat (limited to 'src/core/socket.c')
-rw-r--r--src/core/socket.c43
1 files changed, 37 insertions, 6 deletions
diff --git a/src/core/socket.c b/src/core/socket.c
index 70029278..fb56a0bf 100644
--- a/src/core/socket.c
+++ b/src/core/socket.c
@@ -55,6 +55,7 @@ nni_socket_create(nni_socket **sockp, uint16_t proto)
NNI_LIST_INIT(&sock->s_pipes, nni_pipe, p_sock_node);
NNI_LIST_INIT(&sock->s_eps, nni_endpt, ep_sock_node);
+ NNI_LIST_INIT(&sock->s_reap_eps, nni_endpt, ep_sock_node);
if ((rv = sock->s_ops.proto_create(&sock->s_data, sock)) != 0) {
nni_cond_fini(&sock->s_cv);
@@ -315,8 +316,8 @@ nni_socket_add_pipe(nni_socket *sock, nni_pipe *pipe)
}
-void
-nni_sock_dialer(void *arg)
+static void
+nni_socket_dialer(void *arg)
{
nni_endpt *ep = arg;
nni_socket *sock = ep->ep_sock;
@@ -327,7 +328,7 @@ nni_sock_dialer(void *arg)
nni_mutex_enter(&ep->ep_mx);
while ((!ep->ep_close) &&
(nni_list_first(&ep->ep_pipes) != NULL)) {
- nni_cond_wait(&ep->ep_cv);
+ nni_cond_wait(&ep->ep_cv);
}
if (ep->ep_close) {
nni_mutex_exit(&ep->ep_mx);
@@ -337,19 +338,49 @@ nni_sock_dialer(void *arg)
pipe = NULL;
- if (((rv = nni_endpt_dial(ep, pipe)) != 0) ||
+ if (((rv = nni_endpt_dial(ep, &pipe)) != 0) ||
((rv = nni_socket_add_pipe(sock, pipe)) != 0)) {
if (rv == NNG_ECLOSED) {
- return;
+ break;
}
if (pipe != NULL) {
nni_pipe_destroy(pipe);
}
+ // XXX: Publish connection error event...
// XXX: Inject a wait for reconnect...
continue;
}
+ }
+}
+
+
+int
+nni_socket_dial(nni_socket *sock, nni_endpt *ep)
+{
+ int rv = 0;
+ nni_mutex_enter(&sock->s_mx);
+ nni_mutex_enter(&ep->ep_mx);
+ if ((ep->ep_dialer != NULL) || (ep->ep_listener != NULL)) {
+ rv = NNG_EBUSY;
+ goto out;
+ }
+ if (ep->ep_sock != sock) { // Should never happen
+ rv = NNG_EINVAL;
+ goto out;
+ }
+ if (sock->s_closing) {
+ rv = NNG_ECLOSED;
+ goto out;
}
+ if (nni_thread_create(&ep->ep_dialer, nni_socket_dialer, ep) != 0) {
+ rv = NNG_ENOMEM;
+ goto out;
+ }
+ nni_list_append(&sock->s_eps, ep);
+out:
+ nni_mutex_exit(&ep->ep_mx);
+ nni_mutex_exit(&sock->s_mx);
- // XXX: move the endpoint to the sockets reap list
+ return (rv);
}