diff options
| author | Garrett D'Amore <garrett@damore.org> | 2017-10-30 13:33:27 -0700 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2017-10-30 13:33:27 -0700 |
| commit | 296d74dc8dbe880072c07f52365bbf43ed5684fa (patch) | |
| tree | 543c189dff3113d63dfc7f3ab912b39f8e54152e /src/platform | |
| parent | 3a6542ba7b620f83499eed6b584dec0d6b4cc787 (diff) | |
| download | nng-296d74dc8dbe880072c07f52365bbf43ed5684fa.tar.gz nng-296d74dc8dbe880072c07f52365bbf43ed5684fa.tar.bz2 nng-296d74dc8dbe880072c07f52365bbf43ed5684fa.zip | |
Simplify pollq_add, use SO_NOSIGNAL option on macOS.
Diffstat (limited to 'src/platform')
| -rw-r--r-- | src/platform/posix/posix_pipedesc.c | 6 | ||||
| -rw-r--r-- | src/platform/posix/posix_pollq_poll.c | 26 |
2 files changed, 12 insertions, 20 deletions
diff --git a/src/platform/posix/posix_pipedesc.c b/src/platform/posix/posix_pipedesc.c index a025f83c..e3ef5290 100644 --- a/src/platform/posix/posix_pipedesc.c +++ b/src/platform/posix/posix_pipedesc.c @@ -333,6 +333,12 @@ nni_posix_pipedesc_init(nni_posix_pipedesc **pdp, int fd) (void) fcntl(fd, F_SETFL, O_NONBLOCK); +#ifdef SO_NOSIGNAL + // Darwin lacks MSG_NOSIGNAL, but has a socket option. + int one = 1; + (void) setsockopt(fd, SOL_SOCKET, SO_NOSIGNAL, &one, sizeof(one)); +#endif + nni_mtx_init(&pd->mtx); nni_aio_list_init(&pd->readq); nni_aio_list_init(&pd->writeq); diff --git a/src/platform/posix/posix_pollq_poll.c b/src/platform/posix/posix_pollq_poll.c index e6abd2d2..80bb81ee 100644 --- a/src/platform/posix/posix_pollq_poll.c +++ b/src/platform/posix/posix_pollq_poll.c @@ -188,41 +188,27 @@ nni_posix_poll_thr(void *arg) nni_mtx_unlock(&pollq->mtx); } -// nni_posix_pollq_add_cb is intended to be uesd during endpoint -// operations that create new pollq nodes in callbacks. The lock -// for the pollq must be held. int -nni_posix_pollq_add_cb(nni_posix_pollq *pq, nni_posix_pollq_node *node) +nni_posix_pollq_add(nni_posix_pollq *pq, nni_posix_pollq_node *node) { int rv; NNI_ASSERT(!nni_list_node_active(&node->node)); + nni_mtx_lock(&pq->mtx); if (pq->close) { // This shouldn't happen! + nni_mtx_unlock(&pq->mtx); return (NNG_ECLOSED); } node->pq = pq; if ((rv = nni_posix_pollq_poll_grow(pq)) != 0) { + nni_mtx_unlock(&pq->mtx); return (rv); } pq->nnodes++; - if (node->events != 0) { - nni_list_append(&pq->armed, node); - } else { - nni_list_append(&pq->idle, node); - } - return (0); -} - -int -nni_posix_pollq_add(nni_posix_pollq *pq, nni_posix_pollq_node *node) -{ - int rv; - - nni_mtx_lock(&pq->mtx); - rv = nni_posix_pollq_add_cb(pq, node); + nni_list_append(&pq->idle, node); nni_mtx_unlock(&pq->mtx); - return (rv); + return (0); } void |
