mirror of
https://github.com/libevent/libevent.git
synced 2025-01-09 00:56:20 +08:00
Fix an EINVAL on evbuffer_write_iovec on OpenSolaris.
The writev() call is limited to at most IOV_MAX iovecs (or UIO_MAXIOV, depending on whom you ask). This isn't a problem anywhere we've tested except on OpenSolaris, where IOV_MAX was a mere 16. This patch makes us go from "use up to 128 iovecs when writing" to "use up to 128 iovecs when writing, or IOV_MAX/UIO_MAXIOV, whichever is less". This is still wrong if you somehow find a platform that defines IOV_MAX < UIO_MAXIOV, but I hereby claim that such a platform is too stupid to worry about for now. Found by Michael Herf.
This commit is contained in:
parent
5b7a370636
commit
fdc640b02d
13
buffer.c
13
buffer.c
@ -74,6 +74,7 @@
|
||||
#ifdef _EVENT_HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#include <limits.h>
|
||||
|
||||
#include "event2/event.h"
|
||||
#include "event2/buffer.h"
|
||||
@ -1884,7 +1885,17 @@ evbuffer_expand(struct evbuffer *buf, size_t datlen)
|
||||
#ifdef _EVENT_HAVE_SYS_UIO_H
|
||||
/* number of iovec we use for writev, fragmentation is going to determine
|
||||
* how much we end up writing */
|
||||
#define NUM_WRITE_IOVEC 128
|
||||
|
||||
#define DEFAULT_WRITE_IOVEC 128
|
||||
|
||||
#if defined(UIO_MAXIOV) && UIO_MAXIOV < DEFAULT_WRITE_IOVEC
|
||||
#define NUM_WRITE_IOVEC UIO_MAXIOV
|
||||
#elif defined(IOV_MAX) && IOV_MAX < DEFAULT_WRITE_IOVEC
|
||||
#define NUM_WRITE_IOVEC IOV_MAX
|
||||
#else
|
||||
#define NUM_WRITE_IOVEC DEFAULT_WRITE_IOVEC
|
||||
#endif
|
||||
|
||||
#define IOV_TYPE struct iovec
|
||||
#define IOV_PTR_FIELD iov_base
|
||||
#define IOV_LEN_FIELD iov_len
|
||||
|
Loading…
x
Reference in New Issue
Block a user