comparison 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
comparison
equal deleted inserted replaced
3:8beaf7b3241f 4:4b2dafa26fe2
55 return in; 55 return in;
56 } 56 }
57 57
58 #if (HAVE_KQUEUE) 58 #if (HAVE_KQUEUE)
59 59
60 if ((ngx_event_flags & NGX_HAVE_KQUEUE_EVENT) && wev->pending_eof) { 60 if ((ngx_event_flags & NGX_USE_KQUEUE_EVENT) && wev->pending_eof) {
61 ngx_log_error(NGX_LOG_INFO, c->log, wev->kq_errno, 61 ngx_log_error(NGX_LOG_INFO, c->log, wev->kq_errno,
62 "kevent() reported about an closed connection"); 62 "kevent() reported about an closed connection");
63 63
64 wev->error = 1; 64 wev->error = 1;
65 return NGX_CHAIN_ERROR; 65 return NGX_CHAIN_ERROR;
129 prev = cl->buf->pos + size; 129 prev = cl->buf->pos + size;
130 hsize += size; 130 hsize += size;
131 send += size; 131 send += size;
132 } 132 }
133 133
134 /* get the file buf */
135 134
136 if (cl && cl->buf->in_file && send < limit) { 135 if (cl && cl->buf->in_file && send < limit) {
137 file = cl->buf; 136 file = cl->buf;
138 137
139 /* coalesce the neighbouring file bufs */ 138 /* coalesce the neighbouring file bufs */
162 && send < limit 161 && send < limit
163 && file->file->fd == cl->buf->file->fd 162 && file->file->fd == cl->buf->file->fd
164 && fprev == cl->buf->file_pos); 163 && fprev == cl->buf->file_pos);
165 } 164 }
166 165
166
167 if (file) { 167 if (file) {
168
168 /* create the tailer iovec and coalesce the neighbouring bufs */ 169 /* create the tailer iovec and coalesce the neighbouring bufs */
169 170
170 prev = NULL; 171 prev = NULL;
171 iov = NULL; 172 iov = NULL;
172 173
173 for (/* void */; 174 while (cl && header.nelts < IOV_MAX && send < limit) {
174 cl && header.nelts < IOV_MAX && send < limit; 175
175 cl = cl->next)
176 {
177 if (ngx_buf_special(cl->buf)) { 176 if (ngx_buf_special(cl->buf)) {
177 cl = cl->next;
178 continue; 178 continue;
179 } 179 }
180 180
181 if (!ngx_buf_in_memory_only(cl->buf)) { 181 if (!ngx_buf_in_memory_only(cl->buf)) {
182 break; 182 break;
200 iov->iov_len = size; 200 iov->iov_len = size;
201 } 201 }
202 202
203 prev = cl->buf->pos + size; 203 prev = cl->buf->pos + size;
204 send += size; 204 send += size;
205 cl = cl->next;
205 } 206 }
206 } 207 }
207 208
208 if (file) { 209 if (file) {
209 210
210 if (ngx_freebsd_use_tcp_nopush 211 if (ngx_freebsd_use_tcp_nopush
211 && c->tcp_nopush == NGX_TCP_NOPUSH_UNSET) 212 && c->tcp_nopush == NGX_TCP_NOPUSH_UNSET)
212 { 213 {
213
214 if (ngx_tcp_nopush(c->fd) == NGX_ERROR) { 214 if (ngx_tcp_nopush(c->fd) == NGX_ERROR) {
215 err = ngx_errno; 215 err = ngx_errno;
216 216
217 /* 217 /*
218 * there is a tiny chance to be interrupted, however 218 * there is a tiny chance to be interrupted, however
271 } else { 271 } else {
272 wev->error = 1; 272 wev->error = 1;
273 ngx_connection_error(c, err, "sendfile() failed"); 273 ngx_connection_error(c, err, "sendfile() failed");
274 return NGX_CHAIN_ERROR; 274 return NGX_CHAIN_ERROR;
275 } 275 }
276 }
277
278 if (rc == 0 && sent == 0) {
279
280 /*
281 * rc and sent are equals to zero when someone has truncated
282 * the file, so the offset became beyond the end of the file
283 */
284
285 ngx_log_error(NGX_LOG_ALERT, c->log, 0,
286 "sendfile() reported that \"%s\" was truncated",
287 file->file->name.data);
288
289 return NGX_CHAIN_ERROR;
276 } 290 }
277 291
278 ngx_log_debug4(NGX_LOG_DEBUG_EVENT, c->log, 0, 292 ngx_log_debug4(NGX_LOG_DEBUG_EVENT, c->log, 0,
279 "sendfile: %d, @" OFF_T_FMT " " OFF_T_FMT ":%d", 293 "sendfile: %d, @" OFF_T_FMT " " OFF_T_FMT ":%d",
280 rc, file->file_pos, sent, fsize + hsize); 294 rc, file->file_pos, sent, fsize + hsize);