diff src/os/unix/ngx_freebsd_sendfile_chain.c @ 4:4b2dafa26fe2 NGINX_0_1_2

nginx 0.1.2 *) 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; bug 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; bug 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.
author Igor Sysoev <http://sysoev.ru>
date Thu, 21 Oct 2004 00:00:00 +0400
parents f0b350454894
children 46833bd150cb
line wrap: on
line diff
--- 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(
 
 #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(
             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(
                      && 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(
 
                 prev = cl->buf->pos + size;
                 send += size;
+                cl = cl->next;
             }
         }
 
@@ -210,7 +211,6 @@ ngx_chain_t *ngx_freebsd_sendfile_chain(
             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(
                 }
             }
 
+            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);