summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorstbuehler <stbuehler@152afb58-edef-0310-8abb-c4023f1b3aa9>2013-06-29 12:46:02 +0000
committerstbuehler <stbuehler@152afb58-edef-0310-8abb-c4023f1b3aa9>2013-06-29 12:46:02 +0000
commit3f5f8397ec431a4f29c5eb51b664378a54fb7973 (patch)
tree549a1d31c8410bc21f30cf8d010eb27df09d64f9
parent3bb6004025b3d79b9ce98823b4df2f6b3369b023 (diff)
downloadlighttpd-3f5f8397ec431a4f29c5eb51b664378a54fb7973.tar.gz
[network] use constants available at compile time for maximum number of chunks for writev instead of calling sysconf (fixes #2470)
git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@2885 152afb58-edef-0310-8abb-c4023f1b3aa9
-rw-r--r--NEWS1
-rw-r--r--src/network_writev.c33
2 files changed, 15 insertions, 19 deletions
diff --git a/NEWS b/NEWS
index fbe84af5..e8ad0757 100644
--- a/NEWS
+++ b/NEWS
@@ -22,6 +22,7 @@ NEWS
* [core] return 501 Not Implemented in static file mode for all methods except GET/POST/HEAD/OPTIONS
* [core] recognize more http methods to forward to backends (fixes #2346)
* [ssl] use DH only if openssl supports it (fixes #2479)
+ * [network] use constants available at compile time for maximum number of chunks for writev instead of calling sysconf (fixes #2470)
- 1.4.32 - 2012-11-21
* Code cleanup with clang/sparse (fixes #2437, thx kibi)
diff --git a/src/network_writev.c b/src/network_writev.c
index d21cc4f1..4c9cb5e3 100644
--- a/src/network_writev.c
+++ b/src/network_writev.c
@@ -30,6 +30,18 @@
#define LOCAL_BUFFERING 1
#endif
+#if defined(UIO_MAXIOV)
+# define MAX_CHUNKS UIO_MAXIOV
+#elif defined(IOV_MAX)
+/* new name for UIO_MAXIOV since IEEE Std 1003.1-2001 */
+# define MAX_CHUNKS IOV_MAX
+#elif defined(_XOPEN_IOV_MAX)
+/* minimum value for sysconf(_SC_IOV_MAX); posix requires this to be at least 16, which is good enough - no need to call sysconf() */
+# define MAX_CHUNKS _XOPEN_IOV_MAX
+#else
+# error neither UIO_MAXIOV nor IOV_MAX nor _XOPEN_IOV_MAX are defined
+#endif
+
int network_write_chunkqueue_writev(server *srv, connection *con, int fd, chunkqueue *cq, off_t max_bytes) {
chunk *c;
@@ -46,30 +58,13 @@ int network_write_chunkqueue_writev(server *srv, connection *con, int fd, chunkq
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
/* build writev list
*
- * 1. limit: num_chunks < max_chunks
+ * 1. limit: num_chunks < MAX_CHUNKS
* 2. limit: num_bytes < max_bytes
*/
- for (num_chunks = 0, tc = c; tc && tc->type == MEM_CHUNK && num_chunks < max_chunks; num_chunks++, tc = tc->next);
+ for (num_chunks = 0, tc = c; tc && tc->type == MEM_CHUNK && num_chunks < MAX_CHUNKS; num_chunks++, tc = tc->next);
chunks = calloc(num_chunks, sizeof(*chunks));