aboutsummaryrefslogtreecommitdiff
path: root/src/protocol/pair1/pair.c
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2018-07-06 14:42:53 -0700
committerGarrett D'Amore <garrett@damore.org>2018-07-06 18:57:29 -0700
commit953ca274ae57f8edd12536a3dd15d134aa6e5576 (patch)
tree7a0e889fbae7b525befefedcb5cb8f10820e7a47 /src/protocol/pair1/pair.c
parent89cba92d13fbc5e059336fd054be30e50d8a2621 (diff)
downloadnng-953ca274ae57f8edd12536a3dd15d134aa6e5576.tar.gz
nng-953ca274ae57f8edd12536a3dd15d134aa6e5576.tar.bz2
nng-953ca274ae57f8edd12536a3dd15d134aa6e5576.zip
fixes #568 Want a single reader/write lock on socket child objects
fixes #170 Make more use of reaper This is a complete restructure/rethink of how child objects interact with the socket. (This also backs out #576 as it turns out not to be needed.) While 568 says reader/writer lock, for now we have settled for a single writer lock. Its likely that this is sufficient. Essentially we use the single socket lock to guard lists of the socket children. We also use deferred deletion in the idhash to facilitate teardown, which means endpoint closes are no longer synchronous. We use the reaper to clean up objects when the reference count drops to zero. We make a special exception for pipes, since they really are not reference counted by their parents, and they are leaf objects anyway. We believe this addresses the main outstanding race conditions in a much more correct and holistic way. Note that endpoint shutdown is a little tricky, as it makes use of atomic flags to guard against double entry, and against recursive lock entry. This is something that would be nice to make a bit more obvious, but what we have is safe, and the complexity is at least confined to one place.
Diffstat (limited to 'src/protocol/pair1/pair.c')
-rw-r--r--src/protocol/pair1/pair.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/src/protocol/pair1/pair.c b/src/protocol/pair1/pair.c
index 0c6a4867..dc250943 100644
--- a/src/protocol/pair1/pair.c
+++ b/src/protocol/pair1/pair.c
@@ -244,7 +244,7 @@ pair1_pipe_recv_cb(void *arg)
int rv;
if (nni_aio_result(p->aio_recv) != 0) {
- nni_pipe_stop(p->npipe);
+ nni_pipe_close(p->npipe);
return;
}
@@ -257,13 +257,13 @@ pair1_pipe_recv_cb(void *arg)
// If the message is missing the hop count header, scrap it.
if (nni_msg_len(msg) < sizeof(uint32_t)) {
nni_msg_free(msg);
- nni_pipe_stop(npipe);
+ nni_pipe_close(npipe);
return;
}
hdr = nni_msg_trim_u32(msg);
if (hdr & 0xffffff00) {
nni_msg_free(msg);
- nni_pipe_stop(npipe);
+ nni_pipe_close(npipe);
return;
}
@@ -343,7 +343,7 @@ pair1_pipe_putq_cb(void *arg)
if (nni_aio_result(p->aio_putq) != 0) {
nni_msg_free(nni_aio_get_msg(p->aio_putq));
nni_aio_set_msg(p->aio_putq, NULL);
- nni_pipe_stop(p->npipe);
+ nni_pipe_close(p->npipe);
return;
}
nni_pipe_recv(p->npipe, p->aio_recv);
@@ -358,7 +358,7 @@ pair1_pipe_getq_cb(void *arg)
uint32_t hops;
if (nni_aio_result(p->aio_getq) != 0) {
- nni_pipe_stop(p->npipe);
+ nni_pipe_close(p->npipe);
return;
}
@@ -405,7 +405,7 @@ pair1_pipe_send_cb(void *arg)
if (nni_aio_result(p->aio_send) != 0) {
nni_msg_free(nni_aio_get_msg(p->aio_send));
nni_aio_set_msg(p->aio_send, NULL);
- nni_pipe_stop(p->npipe);
+ nni_pipe_close(p->npipe);
return;
}