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/core/dialer.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) (limited to 'src/core/dialer.c') diff --git a/src/core/dialer.c b/src/core/dialer.c index 34e90891..4b2f105d 100644 --- a/src/core/dialer.c +++ b/src/core/dialer.c @@ -232,24 +232,18 @@ dialer_timer_cb(void *arg) static void dialer_connect_cb(void *arg) { - nni_dialer *d = arg; - nni_pipe * p; + nni_dialer *d = arg; nni_aio * aio = d->d_con_aio; int rv; bool synch; - if ((rv = nni_aio_result(aio)) == 0) { - void *data = nni_aio_get_output(aio, 0); - NNI_ASSERT(data != NULL); - rv = nni_pipe_create(&p, d->d_sock, d->d_tran, data); - } nni_mtx_lock(&d->d_mtx); synch = d->d_synch; nni_mtx_unlock(&d->d_mtx); - switch (rv) { + switch ((rv = nni_aio_result(aio))) { case 0: - nni_dialer_add_pipe(d, p); + nni_dialer_add_pipe(d, nni_aio_get_output(aio, 0)); break; case NNG_ECLOSED: // No further action. case NNG_ECANCELED: // No further action. -- cgit v1.2.3-70-g09d2