diff options
| author | Garrett D'Amore <garrett@damore.org> | 2017-07-20 14:34:51 -0700 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2017-07-20 14:34:51 -0700 |
| commit | a37093079b492e966344416445aae354b147d30e (patch) | |
| tree | 2f21fc2bc716f2423ba02f4713b25038c429ec4e /src/platform/posix/posix_pipedesc.c | |
| parent | 88fb04f61918b06e6e269c1960058c3df5e0a0ef (diff) | |
| download | nng-a37093079b492e966344416445aae354b147d30e.tar.gz nng-a37093079b492e966344416445aae354b147d30e.tar.bz2 nng-a37093079b492e966344416445aae354b147d30e.zip | |
Yet more race condition fixes.
We need to remember that protocol stops can run synchronously, and
therefore we need to wait for the aio to complete. Further, we need
to break apart shutting down aio activity from deallocation, as we need
to shut down *all* async activity before deallocating *anything*.
Noticed that we had a pipe race in the surveyor pattern too.
Diffstat (limited to 'src/platform/posix/posix_pipedesc.c')
| -rw-r--r-- | src/platform/posix/posix_pipedesc.c | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/src/platform/posix/posix_pipedesc.c b/src/platform/posix/posix_pipedesc.c index 4e61c2c4..b85e79a9 100644 --- a/src/platform/posix/posix_pipedesc.c +++ b/src/platform/posix/posix_pipedesc.c @@ -45,18 +45,21 @@ static void nni_posix_pipedesc_doclose(nni_posix_pipedesc *pd) { nni_aio *aio; + int fd; pd->closed = 1; - if (pd->node.fd != -1) { - // Let any peer know we are closing. - (void) shutdown(pd->node.fd, SHUT_RDWR); - } while ((aio = nni_list_first(&pd->readq)) != NULL) { nni_posix_pipedesc_finish(aio, NNG_ECLOSED); } while ((aio = nni_list_first(&pd->writeq)) != NULL) { nni_posix_pipedesc_finish(aio, NNG_ECLOSED); } + if ((fd = pd->node.fd) != -1) { + // Let any peer know we are closing. + pd->node.fd = -1; + (void) shutdown(fd, SHUT_RDWR); + (void) close(fd); + } } static void @@ -269,7 +272,7 @@ nni_posix_pipedesc_send(nni_posix_pipedesc *pd, nni_aio *aio) nni_mtx_unlock(&pd->mtx); return; } - if (pd->closed < 0) { + if (pd->closed) { nni_posix_pipedesc_finish(aio, NNG_ECLOSED); nni_mtx_unlock(&pd->mtx); return; |
