summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libhw_cr/host_net.c8
-rw-r--r--libhw_cr/rp2040_hwspi.c8
-rw-r--r--libhw_cr/w5500.c6
-rw-r--r--libhw_generic/include/libhw/generic/io.h6
4 files changed, 21 insertions, 7 deletions
diff --git a/libhw_cr/host_net.c b/libhw_cr/host_net.c
index 01f4370..d162504 100644
--- a/libhw_cr/host_net.c
+++ b/libhw_cr/host_net.c
@@ -241,6 +241,10 @@ static ssize_t hostnet_tcp_readv(struct _hostnet_tcp_conn *conn, const struct io
assert(conn);
assert(iov);
assert(iovcnt > 0);
+ size_t count = 0;
+ for (int i = 0; i < iovcnt; i++)
+ count += iov[i].iov_len;
+ assert(count);
ssize_t ret;
struct hostnet_pthread_readv_args args = {
@@ -319,6 +323,10 @@ static ssize_t hostnet_tcp_writev(struct _hostnet_tcp_conn *conn, const struct i
assert(conn);
assert(iov);
assert(iovcnt > 0);
+ size_t count = 0;
+ for (int i = 0; i < iovcnt; i++)
+ count += iov[i].iov_len;
+ assert(count);
ssize_t ret;
struct hostnet_pthread_writev_args args = {
diff --git a/libhw_cr/rp2040_hwspi.c b/libhw_cr/rp2040_hwspi.c
index c0b4fa4..ee03b03 100644
--- a/libhw_cr/rp2040_hwspi.c
+++ b/libhw_cr/rp2040_hwspi.c
@@ -158,12 +158,14 @@ static void rp2040_hwspi_readwritev(struct rp2040_hwspi *self, const struct dupl
uint8_t bogus_rx_dst;
+ size_t count = 0;
int pruned_iovcnt = 0;
- for (int i = 0; i < iovcnt; i++)
+ for (int i = 0; i < iovcnt; i++) {
+ count += iov[i].iov_len;
if (iov[i].iov_len)
pruned_iovcnt++;
- if (!pruned_iovcnt)
- return;
+ }
+ assert(count);
/* It doesn't *really* matter which aliases we choose:
*
diff --git a/libhw_cr/w5500.c b/libhw_cr/w5500.c
index e676364..cb424b0 100644
--- a/libhw_cr/w5500.c
+++ b/libhw_cr/w5500.c
@@ -608,10 +608,9 @@ static ssize_t w5500_tcp_writev(struct _w5500_socket *socket, const struct iovec
size_t count = 0;
for (int i = 0; i < iovcnt; i++)
count += iov[i].iov_len;
+ assert(count);
log_debugf("tcp_conn.write(%zu)", count);
ASSERT_SELF(stream_conn, TCP);
- if (count == 0)
- return 0;
/* What we really want is to pause until we receive an ACK for
* some data we just queued, so that we can line up some new
@@ -701,10 +700,9 @@ static ssize_t w5500_tcp_readv(struct _w5500_socket *socket, const struct iovec
size_t count = 0;
for (int i = 0; i < iovcnt; i++)
count += iov[i].iov_len;
+ assert(count);
log_debugf("tcp_conn.read(%zu)", count);
ASSERT_SELF(stream_conn, TCP);
- if (count == 0)
- return 0;
struct alarmclock_trigger trigger = {};
if (socket->read_deadline_ns)
diff --git a/libhw_generic/include/libhw/generic/io.h b/libhw_generic/include/libhw/generic/io.h
index 6adce8c..96680bb 100644
--- a/libhw_generic/include/libhw/generic/io.h
+++ b/libhw_generic/include/libhw/generic/io.h
@@ -58,6 +58,8 @@ void io_slice_wr_to_duplex(struct duplex_iovec *dst, const struct iovec *src, in
/**
* Return bytes-read on success, 0 on EOF, -errno on error; a short
* read is *not* an error.
+ *
+ * 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)
@@ -71,6 +73,8 @@ LO_INTERFACE(io_reader);
*
* Writes are *not* guaranteed to be atomic, so if you have concurrent
* writers then you should arrange for a mutex to protect the writer.
+ *
+ * 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)
@@ -100,6 +104,8 @@ LO_INTERFACE(io_bidi_closer);
/**
* Return bytes-read and bytes-written on success, -errno on error; a
* short read/write *is* an error.
+ *
+ * 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)