diff options
Diffstat (limited to 'src/core')
| -rw-r--r-- | src/core/aio.c | 30 | ||||
| -rw-r--r-- | src/core/aio.h | 11 | ||||
| -rw-r--r-- | src/core/defs.h | 13 |
3 files changed, 43 insertions, 11 deletions
diff --git a/src/core/aio.c b/src/core/aio.c index c6e0ed97..a036a606 100644 --- a/src/core/aio.c +++ b/src/core/aio.c @@ -66,8 +66,10 @@ nni_aio_init(nni_aio **aiop, nni_cb cb, void *arg) } memset(aio, 0, sizeof(*aio)); nni_cv_init(&aio->a_cv, &nni_aio_lk); - aio->a_expire = NNI_TIME_NEVER; - aio->a_timeout = NNG_DURATION_INFINITE; + aio->a_expire = NNI_TIME_NEVER; + aio->a_timeout = NNG_DURATION_INFINITE; + aio->a_iov = aio->a_iovinl; + aio->a_niovalloc = 0; if (arg == NULL) { arg = aio; } @@ -85,10 +87,34 @@ nni_aio_fini(nni_aio *aio) // At this point the AIO is done. nni_cv_fini(&aio->a_cv); + if (aio->a_niovalloc > 0) { + NNI_FREE_STRUCTS(aio->a_iov, aio->a_niovalloc); + } + NNI_FREE_STRUCT(aio); } } +int +nni_aio_set_iov(nni_aio *aio, int niov, nng_iov *iov) +{ + if ((niov > 4) && (niov > aio->a_niovalloc)) { + nni_iov *newiov = NNI_ALLOC_STRUCTS(newiov, niov); + if (newiov == NULL) { + return (NNG_ENOMEM); + } + if (aio->a_niovalloc > 0) { + NNI_FREE_STRUCTS(aio->a_iov, aio->a_niovalloc); + } + aio->a_iov = newiov; + aio->a_niovalloc = niov; + } + + memcpy(aio->a_iov, iov, niov * sizeof(nng_iov)); + aio->a_niov = niov; + return (0); +} + void nni_aio_fini_cb(nni_aio *aio) { diff --git a/src/core/aio.h b/src/core/aio.h index b5db29c9..33fe07cb 100644 --- a/src/core/aio.h +++ b/src/core/aio.h @@ -39,8 +39,10 @@ struct nni_aio { nni_task a_task; // Read/write operations. - nni_iov a_iov[4]; - int a_niov; + nni_iov *a_iov; + int a_niov; + nni_iov a_iovinl[4]; // inline IOVs - when the IOV list is short + int a_niovalloc; // number of allocated IOVs // Message operations. nni_msg *a_msg; @@ -126,6 +128,11 @@ extern void nni_aio_set_output(nni_aio *, int, void *); // nni_get_output returns an output previously stored on the AIO. extern void *nni_aio_get_output(nni_aio *, int); +// nni_aio_set_iov sets an IOV (scatter/gather vector) on the AIO. +// Up to 4 may be set without any possibility of failure, more than that +// may require an allocation and hence fail due to NNG_ENOMEM. +extern int nni_aio_set_iov(nni_aio *, int, nng_iov *); + // XXX: These should be refactored in terms of generic inputs and outputs. extern void nni_aio_set_msg(nni_aio *, nni_msg *); extern nni_msg *nni_aio_get_msg(nni_aio *); diff --git a/src/core/defs.h b/src/core/defs.h index cecb4825..fbf074b4 100644 --- a/src/core/defs.h +++ b/src/core/defs.h @@ -1,5 +1,6 @@ // -// Copyright 2017 Garrett D'Amore <garrett@damore.org> +// Copyright 2018 Staysail Systems, Inc. <info@staysail.tech> +// Copyright 2018 Capitar IT Group BV <info@capitoar.com> // // This software is supplied under the terms of the MIT License, a // copy of which should be located in the distribution where this @@ -34,6 +35,7 @@ typedef struct nng_sockaddr nni_sockaddr; typedef struct nng_event nni_event; typedef struct nng_notify nni_notify; typedef struct nng_url nni_url; +typedef struct nng_iov nni_iov; // These are our own names. typedef struct nni_socket nni_sock; @@ -64,12 +66,6 @@ typedef struct nni_aio nni_aio; typedef void (*nni_cb)(void *); -// Used by transports for scatter gather I/O. -typedef struct { - uint8_t *iov_buf; - size_t iov_len; -} nni_iov; - // Notify descriptor. typedef struct { int sn_wfd; // written to in order to flag an event @@ -134,6 +130,9 @@ typedef struct { (((uint64_t)((uint8_t)(ptr)[6])) << 8) + \ (((uint64_t)(uint8_t)(ptr)[7])) +// This increments a pointer a fixed number of byte cells. +#define NNI_INCPTR(ptr, n) ((ptr) = (void *) ((char *) (ptr) + (n))) + // A few assorted other items. #define NNI_FLAG_IPV4ONLY 1 |
