From: Nick Mathewson Date: Wed, 6 Oct 2010 01:34:07 +0000 (-0400) Subject: Fix an EINVAL on evbuffer_write_iovec on OpenSolaris. X-Git-Tag: release-2.0.8-rc~17^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=fdc640b02dada6d731452c5a02475a7766d1ecfa;p=libevent 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. --- diff --git a/buffer.c b/buffer.c index 7d368e6f..53a723ae 100644 --- a/buffer.c +++ b/buffer.c @@ -74,6 +74,7 @@ #ifdef _EVENT_HAVE_UNISTD_H #include #endif +#include #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