|
diff -ur lighttpd-1.4.32-orig/src/network_writev.c lighttpd-1.4.32/src/network_writev.c
|
|
--- lighttpd-1.4.32-orig/src/network_writev.c 2012-08-31 14:11:20.000000000 +0000
|
|
+++ lighttpd-1.4.32/src/network_writev.c 2013-02-05 16:00:48.000000000 +0000
|
|
@@ -30,6 +30,34 @@
|
|
#define LOCAL_BUFFERING 1
|
|
#endif
|
|
|
|
+size_t network_write_get_max_chunks(void) {
|
|
+ static size_t max_chunks = 0;
|
|
+
|
|
+ /* Cache the results, since sysconf() is expensive on some platforms */
|
|
+ if (max_chunks)
|
|
+ return max_chunks;
|
|
+
|
|
+#if defined(_SC_IOV_MAX) /* IRIX, MacOS X, FreeBSD, Solaris, ... */
|
|
+ max_chunks = sysconf(_SC_IOV_MAX);
|
|
+#elif defined(IOV_MAX) /* Linux x86 (glibc-2.3.6-3) */
|
|
+ max_chunks = IOV_MAX;
|
|
+#elif defined(MAX_IOVEC) /* Linux ia64 (glibc-2.3.3-98.28) */
|
|
+ max_chunks = MAX_IOVEC;
|
|
+#elif defined(UIO_MAXIOV) /* Linux x86 (glibc-2.2.5-233) */
|
|
+ max_chunks = UIO_MAXIOV;
|
|
+#elif (defined(__FreeBSD__) && __FreeBSD_version < 500000) || defined(__DragonFly__) || defined(__APPLE__)
|
|
+ /* - FreeBSD 4.x
|
|
+ * - MacOS X 10.3.x
|
|
+ * (covered in -DKERNEL)
|
|
+ * */
|
|
+ max_chunks = 1024; /* UIO_MAXIOV value from sys/uio.h */
|
|
+#else
|
|
+#error "sysconf() doesnt return _SC_IOV_MAX, please file a bug at www.lighttpd.net"
|
|
+#endif
|
|
+
|
|
+ return max_chunks;
|
|
+}
|
|
+
|
|
int network_write_chunkqueue_writev(server *srv, connection *con, int fd, chunkqueue *cq, off_t max_bytes) {
|
|
chunk *c;
|
|
|
|
@@ -42,27 +70,12 @@
|
|
off_t toSend;
|
|
ssize_t r;
|
|
|
|
- size_t num_chunks, i;
|
|
+ size_t max_chunks, num_chunks, i;
|
|
struct iovec *chunks;
|
|
chunk *tc;
|
|
size_t num_bytes = 0;
|
|
-#if defined(_SC_IOV_MAX) /* IRIX, MacOS X, FreeBSD, Solaris, ... */
|
|
- const size_t max_chunks = sysconf(_SC_IOV_MAX);
|
|
-#elif defined(IOV_MAX) /* Linux x86 (glibc-2.3.6-3) */
|
|
- const size_t max_chunks = IOV_MAX;
|
|
-#elif defined(MAX_IOVEC) /* Linux ia64 (glibc-2.3.3-98.28) */
|
|
- const size_t max_chunks = MAX_IOVEC;
|
|
-#elif defined(UIO_MAXIOV) /* Linux x86 (glibc-2.2.5-233) */
|
|
- const size_t max_chunks = UIO_MAXIOV;
|
|
-#elif (defined(__FreeBSD__) && __FreeBSD_version < 500000) || defined(__DragonFly__) || defined(__APPLE__)
|
|
- /* - FreeBSD 4.x
|
|
- * - MacOS X 10.3.x
|
|
- * (covered in -DKERNEL)
|
|
- * */
|
|
- const size_t max_chunks = 1024; /* UIO_MAXIOV value from sys/uio.h */
|
|
-#else
|
|
-#error "sysconf() doesnt return _SC_IOV_MAX ..., check the output of 'man writev' for the EINVAL error and send the output to jan@kneschke.de"
|
|
-#endif
|
|
+
|
|
+ max_chunks = network_write_get_max_chunks();
|
|
|
|
/* build writev list
|
|
*
|