From 7f95fde8d752dd93c20ff0a209334f4aec549111 Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Sat, 15 Jul 2017 15:45:48 -0700 Subject: Some initial progress on *connect* async. This actually is breaking at the moment, because we don't have good integration with timeouts, and there are some frustrating races with timeouts at points that can cause apparent hangs. --- src/core/socket.c | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) (limited to 'src/core/socket.c') diff --git a/src/core/socket.c b/src/core/socket.c index 3a4f36e5..75ae8450 100644 --- a/src/core/socket.c +++ b/src/core/socket.c @@ -1,5 +1,6 @@ // // Copyright 2017 Garrett D'Amore +// Copyright 2017 Capitar IT Group BV // // This software is supplied under the terms of the MIT License, a // copy of which should be located in the distribution where this @@ -76,6 +77,27 @@ nni_sock_rele(nni_sock *sock) nni_objhash_unref(nni_socks, sock->s_id); } +int +nni_sock_pipe_init(nni_sock *sock, nni_pipe *pipe) +{ + int rv; + + // Initialize protocol pipe data. + nni_mtx_lock(&sock->s_mx); + rv = sock->s_pipe_ops.pipe_init( + &pipe->p_proto_data, pipe, sock->s_data); + if (rv != 0) { + nni_mtx_lock(&sock->s_mx); + return (rv); + } + // Save the protocol destructor. + pipe->p_proto_dtor = sock->s_pipe_ops.pipe_fini; + pipe->p_sock = sock; + nni_list_append(&sock->s_pipes, pipe); + nni_mtx_unlock(&sock->s_mx); + return (0); +} + int nni_sock_pipe_ready(nni_sock *sock, nni_pipe *pipe) { @@ -98,9 +120,6 @@ nni_sock_pipe_ready(nni_sock *sock, nni_pipe *pipe) return (rv); } - // We have claimed ownership of the pipe, so add it to the list. - // Up until this point, the caller could destroy the pipe. - nni_list_append(&sock->s_pipes, pipe); nni_mtx_unlock(&sock->s_mx); return (0); -- cgit v1.2.3-70-g09d2