summaryrefslogtreecommitdiff
path: root/libhw_generic/include/libhw/generic/io.h
diff options
context:
space:
mode:
Diffstat (limited to 'libhw_generic/include/libhw/generic/io.h')
-rw-r--r--libhw_generic/include/libhw/generic/io.h34
1 files changed, 15 insertions, 19 deletions
diff --git a/libhw_generic/include/libhw/generic/io.h b/libhw_generic/include/libhw/generic/io.h
index 8b3fb9c..ebbd6cb 100644
--- a/libhw_generic/include/libhw/generic/io.h
+++ b/libhw_generic/include/libhw/generic/io.h
@@ -9,8 +9,8 @@
#include <stddef.h> /* for size_t */
#include <stdint.h> /* for uintptr_t */
-#include <sys/types.h> /* for ssize_t */
+#include <libmisc/error.h>
#include <libmisc/obj.h>
/* structs ********************************************************************/
@@ -58,20 +58,19 @@ void io_slice_wr_to_duplex(struct duplex_iovec *dst, const struct iovec *src, in
/* basic interfaces ***********************************************************/
/**
- * Return bytes-read on success, 0 on EOF, -errno on error; a short
- * read is *not* an error.
+ * Return bytes-read on success. A short read is *not* an error
+ * (unlike writev).
*
* It is invalid to call readv when the sum length of iovecs is 0.
*/
#define io_reader_LO_IFACE \
- LO_FUNC(ssize_t, readv, const struct iovec *iov, int iovcnt)
+ LO_FUNC(size_t_or_error, readv, const struct iovec *iov, int iovcnt)
LO_INTERFACE(io_reader);
#define io_readv(r, iov, iovcnt) LO_CALL(r, readv, iov, iovcnt)
#define io_read(r, buf, count) LO_CALL(r, readv, &((struct iovec){.iov_base = buf, .iov_len = count}), 1)
/**
- * Return `count` on success, -errno on error; a short write *is* an
- * error.
+ * Return bytes-written. A short write *is* an error (unlike readv)
*
* Writes are *not* guaranteed to be atomic, so if you have concurrent
* writers then you should arrange for a mutex to protect the writer.
@@ -79,38 +78,35 @@ LO_INTERFACE(io_reader);
* It is invalid to call writev when the sum length of iovecs is 0.
*/
#define io_writer_LO_IFACE \
- LO_FUNC(ssize_t, writev, const struct iovec *iov, int iovcnt)
+ LO_FUNC(size_t_and_error, writev, const struct iovec *iov, int iovcnt)
LO_INTERFACE(io_writer);
#define io_writev(w, iov, iovcnt) LO_CALL(w, writev, iov, iovcnt)
#define io_write(w, buf, count) LO_CALL(w, writev, &((struct iovec){.iov_base = buf, .iov_len = count}), 1)
-/**
- * Return 0 on success, -errno on error.
- */
#define io_closer_LO_IFACE \
- LO_FUNC(int, close)
+ LO_FUNC(error, close)
LO_INTERFACE(io_closer);
#define io_close(c) LO_CALL(c, close)
-/**
- * All methods return 0 on success, -errno on error.
- */
#define io_bidi_closer_LO_IFACE \
LO_NEST(io_closer) \
- LO_FUNC(int, close_read) \
- LO_FUNC(int, close_write)
+ LO_FUNC(error, close_read) \
+ LO_FUNC(error, close_write)
LO_INTERFACE(io_bidi_closer);
#define io_close_read(c) LO_CALL(c, close_read)
#define io_close_write(c) LO_CALL(c, close_write)
/**
- * Return bytes-read and bytes-written on success, -errno on error; a
- * short read/write *is* an error.
+ * A short read/write *is* an error (like writev and unlike readv).
+ *
+ * Reads/writes are *not* guaranteed to be atomic, so if you have
+ * concurrent readers/writers then you should arrange for a mutex to
+ * protect the duplex_readwriter.
*
* It is invalid to call readwritev when the sum length of iovecs is 0.
*/
#define io_duplex_readwriter_LO_IFACE \
- LO_FUNC(void, readwritev, const struct duplex_iovec *iov, int iovcnt)
+ LO_FUNC(size_t_and_error, readwritev, const struct duplex_iovec *iov, int iovcnt)
LO_INTERFACE(io_duplex_readwriter);
#define io_readwritev(rw, iov, iovcnt) \