comparison src/os/unix/ngx_linux_sendfile_chain.c @ 5915:ac3f78219f85

Moved the code for coalescing file buffers to a separate function.
author Valentin Bartenev <vbart@nginx.com>
date Wed, 13 Aug 2014 15:11:45 +0400
parents 8e903522c17a
children e044893b4587
comparison
equal deleted inserted replaced
5914:4dd67e5d958e 5915:ac3f78219f85
29 29
30 ngx_chain_t * 30 ngx_chain_t *
31 ngx_linux_sendfile_chain(ngx_connection_t *c, ngx_chain_t *in, off_t limit) 31 ngx_linux_sendfile_chain(ngx_connection_t *c, ngx_chain_t *in, off_t limit)
32 { 32 {
33 int rc, tcp_nodelay; 33 int rc, tcp_nodelay;
34 off_t size, send, prev_send, aligned, sent, fprev; 34 off_t send, prev_send, sent;
35 size_t file_size; 35 size_t file_size;
36 ngx_err_t err; 36 ngx_err_t err;
37 ngx_buf_t *file; 37 ngx_buf_t *file;
38 ngx_uint_t eintr; 38 ngx_uint_t eintr;
39 ngx_event_t *wev; 39 ngx_event_t *wev;
151 if (header.count == 0 && cl && cl->buf->in_file && send < limit) { 151 if (header.count == 0 && cl && cl->buf->in_file && send < limit) {
152 file = cl->buf; 152 file = cl->buf;
153 153
154 /* coalesce the neighbouring file bufs */ 154 /* coalesce the neighbouring file bufs */
155 155
156 do { 156 file_size = (size_t) ngx_chain_coalesce_file(&cl, limit - send);
157 size = cl->buf->file_last - cl->buf->file_pos; 157
158 158 send += file_size;
159 if (send + size > limit) {
160 size = limit - send;
161
162 aligned = (cl->buf->file_pos + size + ngx_pagesize - 1)
163 & ~((off_t) ngx_pagesize - 1);
164
165 if (aligned <= cl->buf->file_last) {
166 size = aligned - cl->buf->file_pos;
167 }
168 }
169
170 file_size += (size_t) size;
171 send += size;
172 fprev = cl->buf->file_pos + size;
173 cl = cl->next;
174
175 } while (cl
176 && cl->buf->in_file
177 && send < limit
178 && file->file->fd == cl->buf->file->fd
179 && fprev == cl->buf->file_pos);
180 } 159 }
181 160
182 if (file) { 161 if (file) {
183 #if 1 162 #if 1
184 if (file_size == 0) { 163 if (file_size == 0) {