diff options
| author | Garrett D'Amore <garrett@damore.org> | 2024-12-26 14:32:34 -0800 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2024-12-26 15:57:48 -0800 |
| commit | c8b58f9128dd1e4b9424d79d22f5ae50a8bff54a (patch) | |
| tree | 73d1d368a67cce45eec797704f85d9e3545ef93b /src/platform/posix/posix_udp.c | |
| parent | 1ad7f88e0c58285c9e1cad9448d5a1fcfa7a07f1 (diff) | |
| download | nng-c8b58f9128dd1e4b9424d79d22f5ae50a8bff54a.tar.gz nng-c8b58f9128dd1e4b9424d79d22f5ae50a8bff54a.tar.bz2 nng-c8b58f9128dd1e4b9424d79d22f5ae50a8bff54a.zip | |
udp: use nni_aio_start
This also moves the close of the UDP socket later, to avoid a
potential use after free while the aio's are still in-flight.
Unfortunately we cannot unbind cleanly without a hard close.
Diffstat (limited to 'src/platform/posix/posix_udp.c')
| -rw-r--r-- | src/platform/posix/posix_udp.c | 14 |
1 files changed, 4 insertions, 10 deletions
diff --git a/src/platform/posix/posix_udp.c b/src/platform/posix/posix_udp.c index ade9e02e..4bb50656 100644 --- a/src/platform/posix/posix_udp.c +++ b/src/platform/posix/posix_udp.c @@ -298,13 +298,10 @@ void nni_plat_udp_recv(nni_plat_udp *udp, nni_aio *aio) { int rv; - if (nni_aio_begin(aio) != 0) { - return; - } + nni_aio_reset(aio); nni_mtx_lock(&udp->udp_mtx); - if ((rv = nni_aio_schedule(aio, nni_plat_udp_cancel, udp)) != 0) { + if (!nni_aio_start(aio, nni_plat_udp_cancel, udp)) { nni_mtx_unlock(&udp->udp_mtx); - nni_aio_finish_error(aio, rv); return; } nni_list_append(&udp->udp_recvq, aio); @@ -322,13 +319,10 @@ void nni_plat_udp_send(nni_plat_udp *udp, nni_aio *aio) { int rv; - if (nni_aio_begin(aio) != 0) { - return; - } + nni_aio_reset(aio); nni_mtx_lock(&udp->udp_mtx); - if ((rv = nni_aio_schedule(aio, nni_plat_udp_cancel, udp)) != 0) { + if (!nni_aio_start(aio, nni_plat_udp_cancel, udp)) { nni_mtx_unlock(&udp->udp_mtx); - nni_aio_finish_error(aio, rv); return; } nni_list_append(&udp->udp_sendq, aio); |
