diff options
| author | Garrett D'Amore <garrett@damore.org> | 2024-12-21 10:55:41 -0800 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2024-12-21 10:55:41 -0800 |
| commit | 5d88c0e80556effb03bc343a1bcd6847500cdac2 (patch) | |
| tree | a2338f39d7be8903f047a1ce7ec153cc9952d0a2 | |
| parent | 20e625137a38232c87871661c684953ef2cfc5f8 (diff) | |
| download | nng-5d88c0e80556effb03bc343a1bcd6847500cdac2.tar.gz nng-5d88c0e80556effb03bc343a1bcd6847500cdac2.tar.bz2 nng-5d88c0e80556effb03bc343a1bcd6847500cdac2.zip | |
posix: fix for IPC and TCP dialing
The dialer aio needs to be set before starting the dial operation,
as the operation may complete right away.
| -rw-r--r-- | src/platform/posix/posix_ipcconn.c | 2 | ||||
| -rw-r--r-- | src/platform/posix/posix_ipcdial.c | 5 | ||||
| -rw-r--r-- | src/platform/posix/posix_tcpconn.c | 8 | ||||
| -rw-r--r-- | src/platform/posix/posix_tcpdial.c | 4 |
4 files changed, 12 insertions, 7 deletions
diff --git a/src/platform/posix/posix_ipcconn.c b/src/platform/posix/posix_ipcconn.c index 69ce2d32..224828ff 100644 --- a/src/platform/posix/posix_ipcconn.c +++ b/src/platform/posix/posix_ipcconn.c @@ -205,7 +205,7 @@ ipc_cb(void *arg, unsigned events) nni_posix_ipc_dialer_cb(arg, events); return; } - if (events & (NNI_POLL_HUP | NNI_POLL_ERR | NNI_POLL_INVAL)) { + if ((events & (NNI_POLL_HUP | NNI_POLL_ERR | NNI_POLL_INVAL)) != 0) { ipc_error(c, NNG_ECONNSHUT); return; } diff --git a/src/platform/posix/posix_ipcdial.c b/src/platform/posix/posix_ipcdial.c index ae98c4f4..25be2e81 100644 --- a/src/platform/posix/posix_ipcdial.c +++ b/src/platform/posix/posix_ipcdial.c @@ -202,6 +202,7 @@ ipc_dialer_dial(void *arg, nni_aio *aio) if ((rv = nni_aio_schedule(aio, ipc_dialer_cancel, d)) != 0) { goto error; } + c->dial_aio = aio; if (connect(fd, (void *) &ss, len) != 0) { if (errno != EINPROGRESS && errno != EAGAIN) { if (errno == ENOENT) { @@ -213,10 +214,10 @@ ipc_dialer_dial(void *arg, nni_aio *aio) goto error; } // Asynchronous connect. - c->dial_aio = aio; if ((rv = nni_posix_pfd_arm(pfd, NNI_POLL_OUT)) != 0) { goto error; } + c->dial_aio = NULL; nni_aio_set_prov_data(aio, c); nni_list_append(&d->connq, aio); nni_mtx_unlock(&d->mtx); @@ -224,6 +225,7 @@ ipc_dialer_dial(void *arg, nni_aio *aio) } // Immediate connect, cool! This probably only happens // on loop back, and probably not on every platform. + c->dial_aio = NULL; nni_aio_set_prov_data(aio, NULL); nni_mtx_unlock(&d->mtx); nni_aio_set_output(aio, 0, c); @@ -231,6 +233,7 @@ ipc_dialer_dial(void *arg, nni_aio *aio) return; error: + c->dial_aio = NULL; nni_aio_set_prov_data(aio, NULL); nni_mtx_unlock(&d->mtx); nng_stream_stop(&c->stream); diff --git a/src/platform/posix/posix_tcpconn.c b/src/platform/posix/posix_tcpconn.c index b1a2233c..c23e1840 100644 --- a/src/platform/posix/posix_tcpconn.c +++ b/src/platform/posix/posix_tcpconn.c @@ -238,14 +238,14 @@ tcp_cb(void *arg, unsigned events) { nni_tcp_conn *c = arg; - if (events & (NNI_POLL_HUP | NNI_POLL_ERR | NNI_POLL_INVAL)) { - tcp_error(c, NNG_ECONNSHUT); - return; - } if (c->dial_aio != NULL) { nni_posix_tcp_dial_cb(c, events); return; } + if ((events & (NNI_POLL_HUP | NNI_POLL_ERR | NNI_POLL_INVAL)) != 0) { + tcp_error(c, NNG_ECONNSHUT); + return; + } nni_mtx_lock(&c->mtx); if ((events & NNI_POLL_IN) != 0) { tcp_doread(c); diff --git a/src/platform/posix/posix_tcpdial.c b/src/platform/posix/posix_tcpdial.c index 442cd824..8a36bba4 100644 --- a/src/platform/posix/posix_tcpdial.c +++ b/src/platform/posix/posix_tcpdial.c @@ -229,6 +229,7 @@ nni_tcp_dial(nni_tcp_dialer *d, const nni_sockaddr *sa, nni_aio *aio) if ((rv = nni_aio_schedule(aio, tcp_dialer_cancel, d)) != 0) { goto error; } + c->dial_aio = aio; if (connect(fd, (void *) &ss, sslen) != 0) { if (errno != EINPROGRESS) { rv = nni_plat_errno(errno); @@ -238,7 +239,6 @@ nni_tcp_dial(nni_tcp_dialer *d, const nni_sockaddr *sa, nni_aio *aio) if ((rv = nni_posix_pfd_arm(&c->pfd, NNI_POLL_OUT)) != 0) { goto error; } - c->dial_aio = aio; nni_aio_set_prov_data(aio, c); nni_list_append(&d->connq, aio); nni_mtx_unlock(&d->mtx); @@ -246,6 +246,7 @@ nni_tcp_dial(nni_tcp_dialer *d, const nni_sockaddr *sa, nni_aio *aio) } // Immediate connect, cool! This probably only happens // on loop back, and probably not on every platform. + c->dial_aio = NULL; nni_aio_set_prov_data(aio, NULL); nd = d->nodelay ? 1 : 0; ka = d->keepalive ? 1 : 0; @@ -256,6 +257,7 @@ nni_tcp_dial(nni_tcp_dialer *d, const nni_sockaddr *sa, nni_aio *aio) return; error: + c->dial_aio = NULL; nni_aio_set_prov_data(aio, NULL); nni_mtx_unlock(&d->mtx); nng_stream_close(&c->stream); |
