aboutsummaryrefslogtreecommitdiff
path: root/src/platform/posix/posix_pipedesc.c
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2018-02-21 11:08:23 -0800
committerGarrett D'Amore <garrett@damore.org>2018-02-21 11:08:23 -0800
commita4d378030df61760ea4daa2ddbe46b1366f8e977 (patch)
tree7bd8bc37acb1aea849eee2daab429e36676fd59e /src/platform/posix/posix_pipedesc.c
parent5fe9202ffedf3a57ec789d622bc52efc3435628b (diff)
downloadnng-a4d378030df61760ea4daa2ddbe46b1366f8e977.tar.gz
nng-a4d378030df61760ea4daa2ddbe46b1366f8e977.tar.bz2
nng-a4d378030df61760ea4daa2ddbe46b1366f8e977.zip
Fixes for POSIX pollq structure.
It was possible for pollq arm to be called on a node that was removed in some circumstances -- particularly and ep that was closed in the callback. While here, lets use normal booleans for closed state, and only call the arm function (which is not free -- typicall it involves a mutex and may even involve a system call) if we are going to arm some events. We also initialize these things properly, and clean up a stale comment. This work is done to faciliate the kqueue work by @liamstask.
Diffstat (limited to 'src/platform/posix/posix_pipedesc.c')
-rw-r--r--src/platform/posix/posix_pipedesc.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/src/platform/posix/posix_pipedesc.c b/src/platform/posix/posix_pipedesc.c
index 7cbf534b..05f3f13f 100644
--- a/src/platform/posix/posix_pipedesc.c
+++ b/src/platform/posix/posix_pipedesc.c
@@ -17,6 +17,7 @@
#include <errno.h>
#include <fcntl.h>
#include <poll.h>
+#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
@@ -31,7 +32,7 @@ struct nni_posix_pipedesc {
nni_posix_pollq_node node;
nni_list readq;
nni_list writeq;
- int closed;
+ bool closed;
nni_mtx mtx;
};
@@ -48,7 +49,7 @@ nni_posix_pipedesc_doclose(nni_posix_pipedesc *pd)
nni_aio *aio;
int fd;
- pd->closed = 1;
+ pd->closed = true;
while ((aio = nni_list_first(&pd->readq)) != NULL) {
nni_posix_pipedesc_finish(aio, NNG_ECLOSED);
}
@@ -213,7 +214,7 @@ nni_posix_pipedesc_cb(void *arg)
if (!nni_list_empty(&pd->readq)) {
events |= POLLIN;
}
- if (events) {
+ if ((!pd->closed) && (events != 0)) {
nni_posix_pollq_arm(&pd->node, events);
}
}
@@ -341,7 +342,7 @@ nni_posix_pipedesc_init(nni_posix_pipedesc **pdp, int fd)
// one. For now we just have a global pollq. Note that by tying
// the pd to a single pollq we may get some kind of cache warmth.
- pd->closed = 0;
+ pd->closed = false;
pd->node.fd = fd;
pd->node.cb = nni_posix_pipedesc_cb;
pd->node.data = pd;