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:
Fedor Indutny 2013-04-08 17:10:39 +04:00
parent f1215b7918
commit 895e77639e
2 changed files with 7 additions and 2 deletions

View File

@ -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.

View File

@ -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)