From c0edbcce58b03b89c70f1eb39cb44c74c4c7453a Mon Sep 17 00:00:00 2001 From: Igor Sysoev Date: Thu, 21 Oct 2004 15:34:38 +0000 Subject: nginx-0.1.2-RELEASE import *) Feature: the --user=USER, --group=GROUP, and --with-ld-opt=OPTIONS options in configure. *) Feature: the server_name directive supports *.domain.tld. *) Bugfix: the portability improvements. *) Bugfix: if configuration file was set in command line, the reconfiguration was impossible; the bug had appeared in 0.1.1. *) Bugfix: proxy module may get caught in an endless loop when sendfile is not used. *) Bugfix: with sendfile the response was not recoded according to the charset module directives; the bug had appeared in 0.1.1. *) Bugfix: very seldom bug in the kqueue processing. *) Bugfix: the gzip module compressed the proxied responses that was already compressed. --- src/os/unix/ngx_freebsd_sendfile_chain.c | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) (limited to 'src/os/unix/ngx_freebsd_sendfile_chain.c') diff --git a/src/os/unix/ngx_freebsd_sendfile_chain.c b/src/os/unix/ngx_freebsd_sendfile_chain.c index d29debfbc..8303c0631 100644 --- a/src/os/unix/ngx_freebsd_sendfile_chain.c +++ b/src/os/unix/ngx_freebsd_sendfile_chain.c @@ -57,7 +57,7 @@ ngx_chain_t *ngx_freebsd_sendfile_chain(ngx_connection_t *c, ngx_chain_t *in, #if (HAVE_KQUEUE) - if ((ngx_event_flags & NGX_HAVE_KQUEUE_EVENT) && wev->pending_eof) { + if ((ngx_event_flags & NGX_USE_KQUEUE_EVENT) && wev->pending_eof) { ngx_log_error(NGX_LOG_INFO, c->log, wev->kq_errno, "kevent() reported about an closed connection"); @@ -131,7 +131,6 @@ ngx_chain_t *ngx_freebsd_sendfile_chain(ngx_connection_t *c, ngx_chain_t *in, send += size; } - /* get the file buf */ if (cl && cl->buf->in_file && send < limit) { file = cl->buf; @@ -164,17 +163,18 @@ ngx_chain_t *ngx_freebsd_sendfile_chain(ngx_connection_t *c, ngx_chain_t *in, && fprev == cl->buf->file_pos); } + if (file) { + /* create the tailer iovec and coalesce the neighbouring bufs */ prev = NULL; iov = NULL; - for (/* void */; - cl && header.nelts < IOV_MAX && send < limit; - cl = cl->next) - { + while (cl && header.nelts < IOV_MAX && send < limit) { + if (ngx_buf_special(cl->buf)) { + cl = cl->next; continue; } @@ -202,6 +202,7 @@ ngx_chain_t *ngx_freebsd_sendfile_chain(ngx_connection_t *c, ngx_chain_t *in, prev = cl->buf->pos + size; send += size; + cl = cl->next; } } @@ -210,7 +211,6 @@ ngx_chain_t *ngx_freebsd_sendfile_chain(ngx_connection_t *c, ngx_chain_t *in, if (ngx_freebsd_use_tcp_nopush && c->tcp_nopush == NGX_TCP_NOPUSH_UNSET) { - if (ngx_tcp_nopush(c->fd) == NGX_ERROR) { err = ngx_errno; @@ -275,6 +275,20 @@ ngx_chain_t *ngx_freebsd_sendfile_chain(ngx_connection_t *c, ngx_chain_t *in, } } + if (rc == 0 && sent == 0) { + + /* + * rc and sent are equals to zero when someone has truncated + * the file, so the offset became beyond the end of the file + */ + + ngx_log_error(NGX_LOG_ALERT, c->log, 0, + "sendfile() reported that \"%s\" was truncated", + file->file->name.data); + + return NGX_CHAIN_ERROR; + } + ngx_log_debug4(NGX_LOG_DEBUG_EVENT, c->log, 0, "sendfile: %d, @" OFF_T_FMT " " OFF_T_FMT ":%d", rc, file->file_pos, sent, fsize + hsize); -- cgit