From d72076207a2fad96ff014a81366868fb47a0ed1b Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Thu, 31 Aug 2017 17:59:01 -0700 Subject: Allocate AIOs dynamically. We allocate AIO structures dynamically, so that we can use them abstractly in more places without inlining them. This will be used for the ZeroTier transport to allow us to create operations consisting of just the AIO. Furthermore, we provide accessors for some of the aio members, in the hopes that we will be able to wrap these for "safe" version of the AIO capability to export to applications, and to protocol and transport implementors. While here we cleaned up the protocol details to use consistently shorter names (no nni_ prefix for static symbols needed), and we also fixed a bug in the surveyor code. --- src/core/aio.c | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 70 insertions(+), 5 deletions(-) (limited to 'src/core/aio.c') diff --git a/src/core/aio.c b/src/core/aio.c index 5b8c7970..9b308cd1 100644 --- a/src/core/aio.c +++ b/src/core/aio.c @@ -56,23 +56,34 @@ static nni_list nni_aio_expire_aios; static void nni_aio_expire_add(nni_aio *); -void -nni_aio_init(nni_aio *aio, nni_cb cb, void *arg) +int +nni_aio_init(nni_aio **aiop, nni_cb cb, void *arg) { + nni_aio *aio; + + if ((aio = NNI_ALLOC_STRUCT(aio)) == NULL) { + return (NNG_ENOMEM); + } memset(aio, 0, sizeof(*aio)); nni_cv_init(&aio->a_cv, &nni_aio_lk); aio->a_expire = NNI_TIME_NEVER; aio->a_init = 1; nni_task_init(NULL, &aio->a_task, cb, arg); + *aiop = aio; + return (0); } void nni_aio_fini(nni_aio *aio) { - nni_aio_stop(aio); + if (aio != NULL) { + nni_aio_stop(aio); - // At this point the AIO is done. - nni_cv_fini(&aio->a_cv); + // At this point the AIO is done. + nni_cv_fini(&aio->a_cv); + + NNI_FREE_STRUCT(aio); + } } // nni_aio_stop cancels any oustanding operation, and waits for the @@ -97,6 +108,60 @@ nni_aio_stop(nni_aio *aio) nni_aio_wait(aio); } +void +nni_aio_set_timeout(nni_aio *aio, nni_time when) +{ + aio->a_expire = when; +} + +void +nni_aio_set_msg(nni_aio *aio, nni_msg *msg) +{ + aio->a_msg = msg; +} + +nni_msg * +nni_aio_get_msg(nni_aio *aio) +{ + return (aio->a_msg); +} + +void +nni_aio_set_pipe(nni_aio *aio, void *p) +{ + aio->a_pipe = p; +} + +void * +nni_aio_get_pipe(nni_aio *aio) +{ + return (aio->a_pipe); +} + +void +nni_aio_set_ep(nni_aio *aio, void *ep) +{ + aio->a_endpt = ep; +} + +void * +nni_aio_get_ep(nni_aio *aio) +{ + return (aio->a_endpt); +} + +void +nni_aio_set_data(nni_aio *aio, void *data) +{ + aio->a_data = data; +} + +void * +nni_aio_get_data(nni_aio *aio) +{ + return (aio->a_data); +} + int nni_aio_result(nni_aio *aio) { -- cgit v1.2.3-70-g09d2