comparison src/os/unix/ngx_freebsd_sendfile_chain.c @ 343:6bdf858bff8c

nginx-0.0.3-2004-05-28-19:49:23 import; rename ngx_hunk_t to ngx_buf_t
author Igor Sysoev <igor@sysoev.ru>
date Fri, 28 May 2004 15:49:23 +0000
parents ee394e997c77
children e366ba5db8f8
comparison
equal deleted inserted replaced
342:0ee0642af5f1 343:6bdf858bff8c
37 ssize_t size; 37 ssize_t size;
38 ngx_int_t eintr, eagain; 38 ngx_int_t eintr, eagain;
39 struct iovec *iov; 39 struct iovec *iov;
40 struct sf_hdtr hdtr; 40 struct sf_hdtr hdtr;
41 ngx_err_t err; 41 ngx_err_t err;
42 ngx_hunk_t *file; 42 ngx_buf_t *file;
43 ngx_array_t header, trailer; 43 ngx_array_t header, trailer;
44 ngx_event_t *wev; 44 ngx_event_t *wev;
45 ngx_chain_t *cl, *tail; 45 ngx_chain_t *cl, *tail;
46 46
47 wev = c->write; 47 wev = c->write;
72 ngx_init_array(header, c->pool, 10, sizeof(struct iovec), 72 ngx_init_array(header, c->pool, 10, sizeof(struct iovec),
73 NGX_CHAIN_ERROR); 73 NGX_CHAIN_ERROR);
74 ngx_init_array(trailer, c->pool, 10, sizeof(struct iovec), 74 ngx_init_array(trailer, c->pool, 10, sizeof(struct iovec),
75 NGX_CHAIN_ERROR); 75 NGX_CHAIN_ERROR);
76 76
77 /* create the header iovec and coalesce the neighbouring hunks */ 77 /* create the header iovec and coalesce the neighbouring bufs */
78 78
79 prev = NULL; 79 prev = NULL;
80 iov = NULL; 80 iov = NULL;
81 81
82 for (cl = in; cl && header.nelts < IOV_MAX; cl = cl->next) { 82 for (cl = in; cl && header.nelts < IOV_MAX; cl = cl->next) {
83 if (ngx_hunk_special(cl->hunk)) { 83 if (ngx_buf_special(cl->buf)) {
84 continue; 84 continue;
85 } 85 }
86 86
87 if (!ngx_hunk_in_memory_only(cl->hunk)) { 87 if (!ngx_buf_in_memory_only(cl->buf)) {
88 break; 88 break;
89 } 89 }
90 90
91 if (prev == cl->hunk->pos) { 91 if (prev == cl->buf->pos) {
92 iov->iov_len += cl->hunk->last - cl->hunk->pos; 92 iov->iov_len += cl->buf->last - cl->buf->pos;
93 93
94 } else { 94 } else {
95 ngx_test_null(iov, ngx_push_array(&header), NGX_CHAIN_ERROR); 95 ngx_test_null(iov, ngx_push_array(&header), NGX_CHAIN_ERROR);
96 iov->iov_base = (void *) cl->hunk->pos; 96 iov->iov_base = (void *) cl->buf->pos;
97 iov->iov_len = cl->hunk->last - cl->hunk->pos; 97 iov->iov_len = cl->buf->last - cl->buf->pos;
98 } 98 }
99 99
100 prev = cl->hunk->last; 100 prev = cl->buf->last;
101 hsize += cl->hunk->last - cl->hunk->pos; 101 hsize += cl->buf->last - cl->buf->pos;
102 } 102 }
103 103
104 /* get the file hunk */ 104 /* get the file buf */
105 105
106 if (cl && (cl->hunk->type & NGX_HUNK_FILE)) { 106 if (cl && cl->buf->in_file) {
107 file = cl->hunk; 107 file = cl->buf;
108 fsize = (size_t) (file->file_last - file->file_pos); 108 fsize = (size_t) (file->file_last - file->file_pos);
109 fprev = file->file_last; 109 fprev = file->file_last;
110 cl = cl->next; 110 cl = cl->next;
111 111
112 /* coalesce the neighbouring file hunks */ 112 /* coalesce the neighbouring file bufs */
113 113
114 while (cl && (cl->hunk->type & NGX_HUNK_FILE)) { 114 while (cl && cl->buf->in_file) {
115 if (file->file->fd != cl->hunk->file->fd 115 if (file->file->fd != cl->buf->file->fd
116 || fprev != cl->hunk->file_pos) 116 || fprev != cl->buf->file_pos)
117 { 117 {
118 break; 118 break;
119 } 119 }
120 120
121 fsize += (size_t) (cl->hunk->file_last - cl->hunk->file_pos); 121 fsize += (size_t) (cl->buf->file_last - cl->buf->file_pos);
122 fprev = cl->hunk->file_last; 122 fprev = cl->buf->file_last;
123 cl = cl->next; 123 cl = cl->next;
124 } 124 }
125 } 125 }
126 126
127 if (file) { 127 if (file) {
128 /* create the tailer iovec and coalesce the neighbouring hunks */ 128 /* create the tailer iovec and coalesce the neighbouring bufs */
129 129
130 prev = NULL; 130 prev = NULL;
131 iov = NULL; 131 iov = NULL;
132 132
133 for ( /* void */; cl && trailer.nelts < IOV_MAX; cl = cl->next) { 133 for ( /* void */; cl && trailer.nelts < IOV_MAX; cl = cl->next) {
134 if (ngx_hunk_special(cl->hunk)) { 134 if (ngx_buf_special(cl->buf)) {
135 continue; 135 continue;
136 } 136 }
137 137
138 if (!ngx_hunk_in_memory_only(cl->hunk)) { 138 if (!ngx_buf_in_memory_only(cl->buf)) {
139 break; 139 break;
140 } 140 }
141 141
142 if (prev == cl->hunk->pos) { 142 if (prev == cl->buf->pos) {
143 iov->iov_len += cl->hunk->last - cl->hunk->pos; 143 iov->iov_len += cl->buf->last - cl->buf->pos;
144 144
145 } else { 145 } else {
146 ngx_test_null(iov, ngx_push_array(&trailer), 146 ngx_test_null(iov, ngx_push_array(&trailer),
147 NGX_CHAIN_ERROR); 147 NGX_CHAIN_ERROR);
148 iov->iov_base = (void *) cl->hunk->pos; 148 iov->iov_base = (void *) cl->buf->pos;
149 iov->iov_len = cl->hunk->last - cl->hunk->pos; 149 iov->iov_len = cl->buf->last - cl->buf->pos;
150 } 150 }
151 151
152 prev = cl->hunk->last; 152 prev = cl->buf->last;
153 } 153 }
154 } 154 }
155 155
156 /* 156 /*
157 * the tail is the rest of the chain that exceeded 157 * the tail is the rest of the chain that exceedes
158 * a single sendfile() capability 158 * a single sendfile() capability
159 */ 159 */
160 160
161 tail = cl; 161 tail = cl;
162 162
260 260
261 c->sent += sent; 261 c->sent += sent;
262 262
263 for (cl = in; cl; cl = cl->next) { 263 for (cl = in; cl; cl = cl->next) {
264 264
265 if (ngx_hunk_special(cl->hunk)) { 265 if (ngx_buf_special(cl->buf)) {
266 continue; 266 continue;
267 } 267 }
268 268
269 if (sent == 0) { 269 if (sent == 0) {
270 break; 270 break;
271 } 271 }
272 272
273 size = ngx_hunk_size(cl->hunk); 273 size = ngx_buf_size(cl->buf);
274 274
275 if (sent >= size) { 275 if (sent >= size) {
276 sent -= size; 276 sent -= size;
277 277
278 if (cl->hunk->type & NGX_HUNK_IN_MEMORY) { 278 if (ngx_buf_in_memory(cl->buf)) {
279 cl->hunk->pos = cl->hunk->last; 279 cl->buf->pos = cl->buf->last;
280 } 280 }
281 281
282 if (cl->hunk->type & NGX_HUNK_FILE) { 282 if (cl->buf->in_file) {
283 cl->hunk->file_pos = cl->hunk->file_last; 283 cl->buf->file_pos = cl->buf->file_last;
284 } 284 }
285 285
286 continue; 286 continue;
287 } 287 }
288 288
289 if (cl->hunk->type & NGX_HUNK_IN_MEMORY) { 289 if (ngx_buf_in_memory(cl->buf)) {
290 cl->hunk->pos += sent; 290 cl->buf->pos += sent;
291 } 291 }
292 292
293 if (cl->hunk->type & NGX_HUNK_FILE) { 293 if (cl->buf->in_file) {
294 cl->hunk->file_pos += sent; 294 cl->buf->file_pos += sent;
295 } 295 }
296 296
297 break; 297 break;
298 } 298 }
299 299