From 578c02f3a1fda0ad43277af2af022c24f2e74104 Mon Sep 17 00:00:00 2001 From: Maxim Dounin Date: Tue, 17 Apr 2012 09:13:15 +0000 Subject: IOV_MAX handling microoptimization. We now stop on IOV_MAX iovec entries only if we are going to add new one, i.e. next buffer can't be coalesced into last iovec. This also fixes incorrect checks for trailer creation on FreeBSD and Mac OS X, header.nelts was checked instead of trailer.nelts. --- src/os/unix/ngx_linux_sendfile_chain.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src/os/unix/ngx_linux_sendfile_chain.c') diff --git a/src/os/unix/ngx_linux_sendfile_chain.c b/src/os/unix/ngx_linux_sendfile_chain.c index 4f6fdf587..e8f3d5a89 100644 --- a/src/os/unix/ngx_linux_sendfile_chain.c +++ b/src/os/unix/ngx_linux_sendfile_chain.c @@ -89,10 +89,8 @@ ngx_linux_sendfile_chain(ngx_connection_t *c, ngx_chain_t *in, off_t limit) /* create the iovec and coalesce the neighbouring bufs */ - for (cl = in; - cl && header.nelts < IOV_MAX && send < limit; - cl = cl->next) - { + for (cl = in; cl && send < limit; cl = cl->next) { + if (ngx_buf_special(cl->buf)) { continue; } @@ -132,6 +130,10 @@ ngx_linux_sendfile_chain(ngx_connection_t *c, ngx_chain_t *in, off_t limit) iov->iov_len += (size_t) size; } else { + if (header.nelts >= IOV_MAX) { + break; + } + iov = ngx_array_push(&header); if (iov == NULL) { return NGX_CHAIN_ERROR; -- cgit v1.2.3