unix: don't write more than IOV_MAX iovecs
Write no more than `IOV_MAX` chunks with `writev()` at once, otherwise `writev()` returns EINVAL.
This commit is contained in:
parent
f1215b7918
commit
895e77639e
@ -33,6 +33,7 @@
|
||||
#include <sys/uio.h>
|
||||
#include <sys/un.h>
|
||||
#include <unistd.h>
|
||||
#include <limits.h> /* IOV_MAX */
|
||||
|
||||
#if defined(__APPLE__)
|
||||
# include <sys/event.h>
|
||||
@ -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.
|
||||
|
||||
@ -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)
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user