aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2016-12-23 00:41:43 -0800
committerGarrett D'Amore <garrett@damore.org>2016-12-23 00:41:43 -0800
commit052e37eebb6b34c37997f46813689f8bbba92c18 (patch)
tree5edf27eab39dbfc3275c49998986a4607a7f91f9 /src
parent236781a2c13feb96a6dd56f762b2df6fec1dfee5 (diff)
downloadnng-052e37eebb6b34c37997f46813689f8bbba92c18.tar.gz
nng-052e37eebb6b34c37997f46813689f8bbba92c18.tar.bz2
nng-052e37eebb6b34c37997f46813689f8bbba92c18.zip
Initial tests -- open & close work (no pipes or endpoints yet).
Diffstat (limited to 'src')
-rw-r--r--src/core/socket.c27
-rw-r--r--src/platform/posix/posix_synch.c1
2 files changed, 18 insertions, 10 deletions
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);
}
diff --git a/src/platform/posix/posix_synch.c b/src/platform/posix/posix_synch.c
index 3d91ee3d..d4c4d6ac 100644
--- a/src/platform/posix/posix_synch.c
+++ b/src/platform/posix/posix_synch.c
@@ -35,7 +35,6 @@ void
nni_mutex_fini(nni_mutex *mp)
{
int rv;
-
if ((rv = pthread_mutex_destroy(&mp->mx)) != 0) {
nni_panic("pthread_mutex_destroy failed: %s", strerror(rv));
}