diff --git a/src/unix/stream.c b/src/unix/stream.c index d95fa0db..bc9d4f1b 100644 --- a/src/unix/stream.c +++ b/src/unix/stream.c @@ -33,6 +33,7 @@ #include #include #include +#include /* IOV_MAX */ #if defined(__APPLE__) # include @@ -742,6 +743,10 @@ start: iov = (struct iovec*) &(req->bufs[req->write_index]); iovcnt = req->bufcnt - req->write_index; + /* Limit iov count to avoid EINVALs from writev() */ + if (iovcnt > IOV_MAX) + iovcnt = IOV_MAX; + /* * Now do the actual writev. Note that we've been updating the pointers * inside the iov each time we write. So there is no need to offset it. diff --git a/test/test-tcp-writealot.c b/test/test-tcp-writealot.c index 3ddcd6d2..ab8c46ad 100644 --- a/test/test-tcp-writealot.c +++ b/test/test-tcp-writealot.c @@ -26,8 +26,8 @@ #define WRITES 3 -#define CHUNKS_PER_WRITE 3 -#define CHUNK_SIZE 10485760 /* 10 MB */ +#define CHUNKS_PER_WRITE 4096 +#define CHUNK_SIZE 10024 /* 10 kb */ #define TOTAL_BYTES (WRITES * CHUNKS_PER_WRITE * CHUNK_SIZE)