diff options
author | Luke T. Shumaker <lukeshu@lukeshu.com> | 2025-03-26 16:15:42 -0600 |
---|---|---|
committer | Luke T. Shumaker <lukeshu@lukeshu.com> | 2025-03-26 22:01:16 -0600 |
commit | 63fcccd84cb348b1b4194024a0dea4dd81941daf (patch) | |
tree | 59f0a19116791a5894892d6275330b482b92f222 /libhw_generic/include/libhw/generic/io.h | |
parent | 0378f059440d4702203f9bc005894f7b53cad889 (diff) |
libhw_generic: Re-think duplex_iovec
Diffstat (limited to 'libhw_generic/include/libhw/generic/io.h')
-rw-r--r-- | libhw_generic/include/libhw/generic/io.h | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/libhw_generic/include/libhw/generic/io.h b/libhw_generic/include/libhw/generic/io.h index a7f7378..7825c9f 100644 --- a/libhw_generic/include/libhw/generic/io.h +++ b/libhw_generic/include/libhw/generic/io.h @@ -8,6 +8,7 @@ #define _LIBHW_GENERIC_IO_H_ #include <stddef.h> /* for size_t */ +#include <stdint.h> /* for uintptr_t */ #include <sys/types.h> /* for ssize_t */ #include <libobj/obj.h> @@ -23,12 +24,35 @@ struct iovec { }; #endif +#define IOVEC_DISCARD ((void*)(~((uintptr_t)0))) + struct duplex_iovec { - void *iov_read_dst; - void *iov_write_src; + /** + * NULL is a valid pointer value in iov_read_to and + * iov_write_from. To skip a read or write, use the special + * value IOVEC_DISCARD. + */ + void *iov_read_to; + void *iov_write_from; size_t iov_len; }; +/* utilities ******************************************************************/ + +/* slice iovec lists */ +int io_slice_cnt ( const struct iovec *src, int src_cnt, size_t byte_start, size_t byte_max_cnt); +void io_slice (struct iovec *dst, const struct iovec *src, int src_cnt, size_t byte_start, size_t byte_max_cnt); +int io_duplex_slice_cnt( const struct duplex_iovec *src, int src_cnt, size_t byte_start, size_t byte_max_cnt); +void io_duplex_slice (struct duplex_iovec *dst, const struct duplex_iovec *src, int src_cnt, size_t byte_start, size_t byte_max_cnt); + +/* convert iovec lists */ +void io_rd_to_duplex(struct duplex_iovec *dst, const struct iovec *src, int iovcnt); +void io_wr_to_duplex(struct duplex_iovec *dst, const struct iovec *src, int iovcnt); + +/* slice and convert in one go */ +void io_slice_rd_to_duplex(struct duplex_iovec *dst, const struct iovec *src, int src_cnt, size_t byte_start, size_t byte_max_cnt); +void io_slice_wr_to_duplex(struct duplex_iovec *dst, const struct iovec *src, int src_cnt, size_t byte_start, size_t byte_max_cnt); + /* basic interfaces ***********************************************************/ /** |