comparison src/os/unix/ngx_freebsd_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
31 31
32 ngx_chain_t * 32 ngx_chain_t *
33 ngx_freebsd_sendfile_chain(ngx_connection_t *c, ngx_chain_t *in, off_t limit) 33 ngx_freebsd_sendfile_chain(ngx_connection_t *c, ngx_chain_t *in, off_t limit)
34 { 34 {
35 int rc, flags; 35 int rc, flags;
36 off_t size, send, prev_send, aligned, sent, fprev; 36 off_t send, prev_send, sent;
37 size_t file_size; 37 size_t file_size;
38 ngx_uint_t eintr, eagain; 38 ngx_uint_t eintr, eagain;
39 ngx_err_t err; 39 ngx_err_t err;
40 ngx_buf_t *file; 40 ngx_buf_t *file;
41 ngx_event_t *wev; 41 ngx_event_t *wev;
97 if (cl && cl->buf->in_file && send < limit) { 97 if (cl && cl->buf->in_file && send < limit) {
98 file = cl->buf; 98 file = cl->buf;
99 99
100 /* coalesce the neighbouring file bufs */ 100 /* coalesce the neighbouring file bufs */
101 101
102 do { 102 file_size = (size_t) ngx_chain_coalesce_file(&cl, limit - send);
103 size = cl->buf->file_last - cl->buf->file_pos; 103
104 104 send += file_size;
105 if (send + size > limit) {
106 size = limit - send;
107
108 aligned = (cl->buf->file_pos + size + ngx_pagesize - 1)
109 & ~((off_t) ngx_pagesize - 1);
110
111 if (aligned <= cl->buf->file_last) {
112 size = aligned - cl->buf->file_pos;
113 }
114 }
115
116 file_size += (size_t) size;
117 send += size;
118 fprev = cl->buf->file_pos + size;
119 cl = cl->next;
120
121 } while (cl
122 && cl->buf->in_file
123 && send < limit
124 && file->file->fd == cl->buf->file->fd
125 && fprev == cl->buf->file_pos);
126 } 105 }
127 106
128 107
129 if (file) { 108 if (file) {
130 109