From 7f7d4eee9a51cbe2088d465aa725aaf8f8424917 Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Wed, 9 May 2018 12:11:01 -0700 Subject: fixes #422 nng_aio_fini_cb() could go away --- src/core/aio.c | 7 ------- src/core/aio.h | 6 ------ src/transport/zerotier/zerotier.c | 24 ++++++++++-------------- 3 files changed, 10 insertions(+), 27 deletions(-) diff --git a/src/core/aio.c b/src/core/aio.c index 388e6677..3606aa14 100644 --- a/src/core/aio.c +++ b/src/core/aio.c @@ -175,13 +175,6 @@ nni_aio_set_iov(nni_aio *aio, unsigned niov, const nni_iov *iov) return (0); } -void -nni_aio_fini_cb(nni_aio *aio) -{ - nni_cv_fini(&aio->a_cv); - NNI_FREE_STRUCT(aio); -} - // nni_aio_stop cancels any oustanding operation, and waits for the // callback to complete, if still running. It also marks the AIO as // stopped, preventing further calls to nni_aio_begin from succeeding. diff --git a/src/core/aio.h b/src/core/aio.h index d23ddf5b..9b7ac46f 100644 --- a/src/core/aio.h +++ b/src/core/aio.h @@ -32,12 +32,6 @@ extern int nni_aio_init(nni_aio **, nni_cb, void *); // on zero'd memory. extern void nni_aio_fini(nni_aio *); -// nni_aio_fini_cb finalizes the aio WITHOUT waiting for it to complete. -// This is intended exclusively for finalizing an AIO from a completion -// callack for that AIO. It is important that the caller ensure that nothing -// else might be waiting for that AIO or using it. -extern void nni_aio_fini_cb(nni_aio *); - // nni_aio_stop cancels any unfinished I/O, running completion callbacks, // but also prevents any new operations from starting (nni_aio_start will // return NNG_ESTATE). This should be called before nni_aio_fini(). The diff --git a/src/transport/zerotier/zerotier.c b/src/transport/zerotier/zerotier.c index 73cddf7d..54e402be 100644 --- a/src/transport/zerotier/zerotier.c +++ b/src/transport/zerotier/zerotier.c @@ -1285,19 +1285,6 @@ typedef struct zt_send_hdr { size_t len; } zt_send_hdr; -static void -zt_wire_packet_send_cb(void *arg) -{ - // We don't actually care much about the results, we - // just need to release the resources. - nni_aio * aio = arg; - zt_send_hdr *hdr; - - hdr = nni_aio_get_data(aio, 0); - nni_free(hdr, hdr->len + sizeof(*hdr)); - nni_aio_fini_cb(aio); -} - // This function is called when ZeroTier desires to send a // physical frame. The data is a UDP payload, the rest of the // payload should be set over vanilla UDP. @@ -1345,7 +1332,7 @@ zt_wire_packet_send(ZT_Node *node, void *userptr, void *thr, int64_t socket, return (-1); } - if (nni_aio_init(&aio, zt_wire_packet_send_cb, NULL) != 0) { + if (nni_aio_init(&aio, NULL, NULL) != 0) { // Out of memory return (-1); } @@ -1371,6 +1358,15 @@ zt_wire_packet_send(ZT_Node *node, void *userptr, void *thr, int64_t socket, // not great that we're holding the lock, also not tragic. nni_plat_udp_send(udp, aio); + // UDP sending is "fast" on all platforms -- given that its + // best effort only, this will complete immediately, resulting + // in either a message on the wire, or a discarded frame. We don't + // care which. (There may be a few thread context switches, but + // none of them are going to have to wait for some unbounded time.) + nni_aio_wait(aio); + nni_aio_fini(aio); + nni_free(hdr, hdr->len + sizeof(*hdr)); + return (0); } -- cgit v1.2.3-70-g09d2