comparison src/os/unix/ngx_linux_sendfile_chain.c @ 344:e366ba5db8f8

nginx-0.0.3-2004-06-01-10:04:46 import
author Igor Sysoev <igor@sysoev.ru>
date Tue, 01 Jun 2004 06:04:46 +0000
parents 6bdf858bff8c
children 7650aea1816f
comparison
equal deleted inserted replaced
343:6bdf858bff8c 344:e366ba5db8f8
56 iov = NULL; 56 iov = NULL;
57 57
58 /* create the iovec and coalesce the neighbouring bufs */ 58 /* create the iovec and coalesce the neighbouring bufs */
59 59
60 for (cl = in; cl && header.nelts < IOV_MAX; cl = cl->next) { 60 for (cl = in; cl && header.nelts < IOV_MAX; cl = cl->next) {
61 if (ngx_hunk_special(cl->hunk)) { 61 if (ngx_buf_special(cl->buf)) {
62 continue; 62 continue;
63 } 63 }
64 64
65 if (!ngx_hunk_in_memory_only(cl->hunk)) { 65 if (!ngx_buf_in_memory_only(cl->buf)) {
66 break; 66 break;
67 } 67 }
68 68
69 if (prev == cl->hunk->pos) { 69 if (prev == cl->buf->pos) {
70 iov->iov_len += cl->hunk->last - cl->hunk->pos; 70 iov->iov_len += cl->buf->last - cl->buf->pos;
71 71
72 } else { 72 } else {
73 ngx_test_null(iov, ngx_push_array(&header), NGX_CHAIN_ERROR); 73 ngx_test_null(iov, ngx_push_array(&header), NGX_CHAIN_ERROR);
74 iov->iov_base = (void *) cl->hunk->pos; 74 iov->iov_base = (void *) cl->buf->pos;
75 iov->iov_len = cl->hunk->last - cl->hunk->pos; 75 iov->iov_len = cl->buf->last - cl->buf->pos;
76 } 76 }
77 77
78 prev = cl->hunk->last; 78 prev = cl->buf->last;
79 } 79 }
80 80
81 /* set TCP_CORK if there is a header before a file */ 81 /* set TCP_CORK if there is a header before a file */
82 82
83 if (!c->tcp_nopush == 0 83 if (c->tcp_nopush == NGX_TCP_NOPUSH_UNSET
84 && header.nelts != 0 84 && header.nelts != 0
85 && cl 85 && cl
86 && cl->hunk->type & NGX_HUNK_FILE) 86 && cl->buf->in_file)
87 { 87 {
88 if (ngx_tcp_nopush(c->fd) == NGX_ERROR) { 88 if (ngx_tcp_nopush(c->fd) == NGX_ERROR) {
89 err = ngx_errno; 89 err = ngx_errno;
90 90
91 /* 91 /*
98 ngx_connection_error(c, err, ngx_tcp_nopush_n " failed"); 98 ngx_connection_error(c, err, ngx_tcp_nopush_n " failed");
99 return NGX_CHAIN_ERROR; 99 return NGX_CHAIN_ERROR;
100 } 100 }
101 101
102 } else { 102 } else {
103 c->tcp_nopush = 1; 103 c->tcp_nopush = NGX_TCP_NOPUSH_SET;
104
104 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, 0, 105 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, 0,
105 "tcp_nopush"); 106 "tcp_nopush");
106 } 107 }
107 } 108 }
108 109
109 if (header.nelts == 0 && cl && cl->hunk->type & NGX_HUNK_FILE) { 110 if (header.nelts == 0 && cl && cl->buf->in_file) {
110 111
111 /* get the file hunk */ 112 /* get the file buf */
112 113
113 file = cl->hunk; 114 file = cl->buf;
114 fsize = (size_t) (file->file_last - file->file_pos); 115 fsize = (size_t) (file->file_last - file->file_pos);
115 fprev = file->file_last; 116 fprev = file->file_last;
116 cl = cl->next; 117 cl = cl->next;
117 118
118 /* coalesce the neighbouring file hunks */ 119 /* coalesce the neighbouring file bufs */
119 120
120 while (cl && (cl->hunk->type & NGX_HUNK_FILE)) { 121 while (cl && (cl->buf->in_file)) {
121 if (file->file->fd != cl->hunk->file->fd 122 if (file->file->fd != cl->buf->file->fd
122 || fprev != cl->hunk->file_pos) 123 || fprev != cl->buf->file_pos)
123 { 124 {
124 break; 125 break;
125 } 126 }
126 127
127 fsize += (size_t) (cl->hunk->file_last - cl->hunk->file_pos); 128 fsize += (size_t) (cl->buf->file_last - cl->buf->file_pos);
128 fprev = cl->hunk->file_last; 129 fprev = cl->buf->file_last;
129 cl = cl->next; 130 cl = cl->next;
130 } 131 }
131 } 132 }
132 133
133 /* 134 /*
197 198
198 c->sent += sent; 199 c->sent += sent;
199 200
200 for (cl = in; cl; cl = cl->next) { 201 for (cl = in; cl; cl = cl->next) {
201 202
202 if (ngx_hunk_special(cl->hunk)) { 203 if (ngx_buf_special(cl->buf)) {
203 continue; 204 continue;
204 } 205 }
205 206
206 if (sent == 0) { 207 if (sent == 0) {
207 break; 208 break;
208 } 209 }
209 210
210 size = ngx_hunk_size(cl->hunk); 211 size = ngx_buf_size(cl->buf);
211 212
212 if (sent >= size) { 213 if (sent >= size) {
213 sent -= size; 214 sent -= size;
214 215
215 if (cl->hunk->type & NGX_HUNK_IN_MEMORY) { 216 if (ngx_buf_in_memory(cl->buf)) {
216 cl->hunk->pos = cl->hunk->last; 217 cl->buf->pos = cl->buf->last;
217 } 218 }
218 219
219 if (cl->hunk->type & NGX_HUNK_FILE) { 220 if (cl->buf->in_file) {
220 cl->hunk->file_pos = cl->hunk->file_last; 221 cl->buf->file_pos = cl->buf->file_last;
221 } 222 }
222 223
223 continue; 224 continue;
224 } 225 }
225 226
226 if (cl->hunk->type & NGX_HUNK_IN_MEMORY) { 227 if (ngx_buf_in_memory(cl->buf)) {
227 cl->hunk->pos += sent; 228 cl->buf->pos += sent;
228 } 229 }
229 230
230 if (cl->hunk->type & NGX_HUNK_FILE) { 231 if (cl->buf->in_file) {
231 cl->hunk->file_pos += sent; 232 cl->buf->file_pos += sent;
232 } 233 }
233 234
234 break; 235 break;
235 } 236 }
236 237