From 8ae18a10d6c7c94fbb4fa04a64c6fa1e2a38fe16 Mon Sep 17 00:00:00 2001 From: Igor Sysoev Date: Wed, 18 Feb 2004 15:45:21 +0000 Subject: nginx-0.0.2-2004-02-18-18:45:21 import --- src/os/unix/ngx_freebsd_config.h | 6 ++++++ src/os/unix/ngx_freebsd_sendfile_chain.c | 4 ++-- src/os/unix/ngx_linux_config.h | 1 + src/os/unix/ngx_linux_sendfile_chain.c | 2 +- src/os/unix/ngx_solaris_config.h | 1 + src/os/unix/ngx_solaris_sendfilev_chain.c | 15 ++++++++++++--- 6 files changed, 23 insertions(+), 6 deletions(-) (limited to 'src/os/unix') diff --git a/src/os/unix/ngx_freebsd_config.h b/src/os/unix/ngx_freebsd_config.h index 3d53d2026..e447340a8 100644 --- a/src/os/unix/ngx_freebsd_config.h +++ b/src/os/unix/ngx_freebsd_config.h @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -71,6 +72,11 @@ #endif +#ifndef IOV_MAX +#define IOV_MAX 1024 +#endif + + #ifndef HAVE_INHERITED_NONBLOCK #define HAVE_INHERITED_NONBLOCK 1 #endif diff --git a/src/os/unix/ngx_freebsd_sendfile_chain.c b/src/os/unix/ngx_freebsd_sendfile_chain.c index f784b1f1d..d5e1831bc 100644 --- a/src/os/unix/ngx_freebsd_sendfile_chain.c +++ b/src/os/unix/ngx_freebsd_sendfile_chain.c @@ -73,7 +73,7 @@ ngx_chain_t *ngx_freebsd_sendfile_chain(ngx_connection_t *c, ngx_chain_t *in) prev = NULL; iov = NULL; - for (cl = in; cl; cl = cl->next) { + for (cl = in; cl && header.nelts < IOV_MAX; cl = cl->next) { if (ngx_hunk_special(cl->hunk)) { continue; } @@ -123,7 +123,7 @@ ngx_chain_t *ngx_freebsd_sendfile_chain(ngx_connection_t *c, ngx_chain_t *in) prev = NULL; iov = NULL; - for ( /* void */; cl; cl = cl->next) { + for ( /* void */; cl && trailer.nelts < IOV_MAX; cl = cl->next) { if (ngx_hunk_special(cl->hunk)) { continue; } diff --git a/src/os/unix/ngx_linux_config.h b/src/os/unix/ngx_linux_config.h index 1ca1c1f0d..23745df07 100644 --- a/src/os/unix/ngx_linux_config.h +++ b/src/os/unix/ngx_linux_config.h @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include diff --git a/src/os/unix/ngx_linux_sendfile_chain.c b/src/os/unix/ngx_linux_sendfile_chain.c index 39c2e831d..4fa8f835c 100644 --- a/src/os/unix/ngx_linux_sendfile_chain.c +++ b/src/os/unix/ngx_linux_sendfile_chain.c @@ -52,7 +52,7 @@ ngx_chain_t *ngx_linux_sendfile_chain(ngx_connection_t *c, ngx_chain_t *in) /* create the iovec and coalesce the neighbouring hunks */ - for (cl = in; cl; cl = cl->next) { + for (cl = in; cl && header.nelts < IOV_MAX; cl = cl->next) { if (ngx_hunk_special(cl->hunk)) { continue; } diff --git a/src/os/unix/ngx_solaris_config.h b/src/os/unix/ngx_solaris_config.h index f4f8df2af..db74aebe5 100644 --- a/src/os/unix/ngx_solaris_config.h +++ b/src/os/unix/ngx_solaris_config.h @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include diff --git a/src/os/unix/ngx_solaris_sendfilev_chain.c b/src/os/unix/ngx_solaris_sendfilev_chain.c index a5b741f27..9cd1618a3 100644 --- a/src/os/unix/ngx_solaris_sendfilev_chain.c +++ b/src/os/unix/ngx_solaris_sendfilev_chain.c @@ -16,7 +16,7 @@ ngx_chain_t *ngx_solaris_sendfilev_chain(ngx_connection_t *c, ngx_chain_t *in) sendfilevec_t *sfv; ngx_array_t vec; ngx_event_t *wev; - ngx_chain_t *cl; + ngx_chain_t *cl, *tail; wev = c->write; @@ -37,7 +37,7 @@ ngx_chain_t *ngx_solaris_sendfilev_chain(ngx_connection_t *c, ngx_chain_t *in) /* create the sendfilevec and coalesce the neighbouring hunks */ - for (cl = in; cl; cl = cl->next) { + for (cl = in; cl && vec.nelts < IOV_MAX; cl = cl->next) { if (ngx_hunk_special(cl->hunk)) { continue; } @@ -77,6 +77,13 @@ ngx_chain_t *ngx_solaris_sendfilev_chain(ngx_connection_t *c, ngx_chain_t *in) } } + /* + * the tail is the rest of the chain that exceeded a single + * sendfilev() capability, IOV_MAX in Solaris is only 16 + */ + + tail = cl; + n = sendfilev(c->fd, vec.elts, vec.nelts, &sent); if (n == -1) { @@ -142,7 +149,9 @@ ngx_chain_t *ngx_solaris_sendfilev_chain(ngx_connection_t *c, ngx_chain_t *in) in = cl; - } while (eintr); + /* "tail == in" means that a single sendfilev() is complete */ + + } while ((tail && tail == in) || eintr); if (in) { wev->ready = 0; -- cgit