From d7f7c896c0ede24249ef63b1e45b1878bf4bd473 Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Tue, 31 Jul 2018 12:33:58 -0700 Subject: fixes #599 nng_dial sync should not return until added to socket fixes #208 pipe start should occur before connect / accept fixes #616 Race condition closing between header & body This refactors the transports to handle their own connection handshaking before passing the pipe to the socket. This changes and simplifies the setup. This also fixes a rather challenging race condition described by #616. --- src/platform/posix/posix_ipcconn.c | 8 ++++++++ src/platform/posix/posix_tcpconn.c | 8 ++++++++ 2 files changed, 16 insertions(+) (limited to 'src/platform') diff --git a/src/platform/posix/posix_ipcconn.c b/src/platform/posix/posix_ipcconn.c index 2b46fb12..539a00ba 100644 --- a/src/platform/posix/posix_ipcconn.c +++ b/src/platform/posix/posix_ipcconn.c @@ -47,6 +47,10 @@ ipc_conn_dowrite(nni_ipc_conn *c) int fd; if (c->closed || ((fd = nni_posix_pfd_fd(c->pfd)) < 0)) { + while ((aio = nni_list_first(&c->writeq)) != NULL) { + nni_aio_list_remove(aio); + nni_aio_finish_error(aio, NNG_ECLOSED); + } return; } @@ -129,6 +133,10 @@ ipc_conn_doread(nni_ipc_conn *c) int fd; if (c->closed || ((fd = nni_posix_pfd_fd(c->pfd)) < 0)) { + while ((aio = nni_list_first(&c->readq)) != NULL) { + nni_aio_list_remove(aio); + nni_aio_finish_error(aio, NNG_ECLOSED); + } return; } diff --git a/src/platform/posix/posix_tcpconn.c b/src/platform/posix/posix_tcpconn.c index c0352c55..cf85e8e8 100644 --- a/src/platform/posix/posix_tcpconn.c +++ b/src/platform/posix/posix_tcpconn.c @@ -43,6 +43,10 @@ tcp_conn_dowrite(nni_tcp_conn *c) int fd; if (c->closed || ((fd = nni_posix_pfd_fd(c->pfd)) < 0)) { + while ((aio = nni_list_first(&c->writeq)) != NULL) { + nni_aio_list_remove(aio); + nni_aio_finish_error(aio, NNG_ECLOSED); + } return; } @@ -125,6 +129,10 @@ tcp_conn_doread(nni_tcp_conn *c) int fd; if (c->closed || ((fd = nni_posix_pfd_fd(c->pfd)) < 0)) { + while ((aio = nni_list_first(&c->readq)) != NULL) { + nni_aio_list_remove(aio); + nni_aio_finish_error(aio, NNG_ECLOSED); + } return; } -- cgit v1.2.3-70-g09d2