comparison src/os/unix/ngx_darwin_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_darwin_sendfile_chain(ngx_connection_t *c, ngx_chain_t *in, off_t limit) 31 ngx_darwin_sendfile_chain(ngx_connection_t *c, ngx_chain_t *in, off_t limit)
32 { 32 {
33 int rc; 33 int rc;
34 off_t size, send, prev_send, aligned, sent, fprev; 34 off_t send, prev_send, sent;
35 off_t file_size; 35 off_t file_size;
36 ngx_uint_t eintr; 36 ngx_uint_t eintr;
37 ngx_err_t err; 37 ngx_err_t err;
38 ngx_buf_t *file; 38 ngx_buf_t *file;
39 ngx_event_t *wev; 39 ngx_event_t *wev;
93 if (cl && cl->buf->in_file && send < limit) { 93 if (cl && cl->buf->in_file && send < limit) {
94 file = cl->buf; 94 file = cl->buf;
95 95
96 /* coalesce the neighbouring file bufs */ 96 /* coalesce the neighbouring file bufs */
97 97
98 do { 98 file_size = ngx_chain_coalesce_file(&cl, limit - send);
99 size = cl->buf->file_last - cl->buf->file_pos; 99
100 100 send += file_size;
101 if (send + size > limit) {
102 size = limit - send;
103
104 aligned = (cl->buf->file_pos + size + ngx_pagesize - 1)
105 & ~((off_t) ngx_pagesize - 1);
106
107 if (aligned <= cl->buf->file_last) {
108 size = aligned - cl->buf->file_pos;
109 }
110 }
111
112 file_size += size;
113 send += size;
114 fprev = cl->buf->file_pos + size;
115 cl = cl->next;
116
117 } while (cl
118 && cl->buf->in_file
119 && send < limit
120 && file->file->fd == cl->buf->file->fd
121 && fprev == cl->buf->file_pos);
122 } 101 }
123 102
124 if (file && header.count == 0) { 103 if (file && header.count == 0) {
125 104
126 /* create the trailer iovec and coalesce the neighbouring bufs */ 105 /* create the trailer iovec and coalesce the neighbouring bufs */