From 052e37eebb6b34c37997f46813689f8bbba92c18 Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Fri, 23 Dec 2016 00:41:43 -0800 Subject: Initial tests -- open & close work (no pipes or endpoints yet). --- src/core/socket.c | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) (limited to 'src/core') diff --git a/src/core/socket.c b/src/core/socket.c index 1b3bcf56..99573a2f 100644 --- a/src/core/socket.c +++ b/src/core/socket.c @@ -57,14 +57,27 @@ 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); + if (((rv = nni_msgqueue_create(&sock->s_uwq, 1)) != 0) || + ((rv = nni_msgqueue_create(&sock->s_urq, 1)) != 0)) { + goto fail; + } + if ((rv = sock->s_ops.proto_create(&sock->s_data, sock)) != 0) { - nni_cond_fini(&sock->s_cv); - nni_mutex_fini(&sock->s_mx); - nni_free(sock, sizeof (*sock)); - return (rv); + goto fail; } *sockp = sock; return (0); +fail: + if (sock->s_urq != NULL) { + nni_msgqueue_destroy(sock->s_urq); + } + if (sock->s_uwq != NULL) { + nni_msgqueue_destroy(sock->s_uwq); + } + nni_cond_fini(&sock->s_cv); + nni_mutex_fini(&sock->s_mx); + nni_free(sock, sizeof (*sock)); + return (rv); } @@ -76,7 +89,6 @@ nni_socket_close(nni_socket *sock) nni_endpt *ep; nni_time linger; - nni_mutex_enter(&sock->s_mx); // Mark us closing, so no more EPs or changes can occur. sock->s_closing = 1; @@ -117,7 +129,6 @@ nni_socket_close(nni_socket *sock) nni_msgqueue_close(sock->s_urq); // Go through and close all the pipes. - nni_mutex_enter(&sock->s_mx); NNI_LIST_FOREACH (&sock->s_pipes, pipe) { nni_pipe_close(pipe); } @@ -142,15 +153,13 @@ nni_socket_close(nni_socket *sock) nni_mutex_exit(&sock->s_mx); // At this point nothing else should be referencing us. - // The protocol needs to clean up its state. - sock->s_ops.proto_destroy(&sock->s_data); + sock->s_ops.proto_destroy(sock->s_data); // And we need to clean up *our* state. nni_cond_fini(&sock->s_cv); nni_mutex_fini(&sock->s_mx); nni_free(sock, sizeof (*sock)); - return (0); } -- cgit v1.2.3-70-g09d2