comparison src/event/ngx_event_pipe.c @ 166:389d7ee9fa60

nginx-0.0.1-2003-10-30-11:51:06 import
author Igor Sysoev <igor@sysoev.ru>
date Thu, 30 Oct 2003 08:51:06 +0000
parents 84036764e215
children ba5dbb949603
comparison
equal deleted inserted replaced
165:894a01c6aea3 166:389d7ee9fa60
99 99
100 ngx_log_debug(p->log, "preread: %d" _ n); 100 ngx_log_debug(p->log, "preread: %d" _ n);
101 101
102 } else { 102 } else {
103 103
104 #if (HAVE_KQUEUE)
105
106 /* 104 /*
107 * kqueue notifies about the end of file or a pending error. 105 * kqueue notifies about the end of file or a pending error.
108 * This test allows not to allocate a hunk on these conditions 106 * This test allows not to allocate a hunk on these conditions
109 * and not to call ngx_recv_chain(). 107 * and not to call ngx_recv_chain().
110 */ 108 */
111 109
112 if (ngx_event_flags == NGX_HAVE_KQUEUE_EVENT) { 110 if (p->upstream->read->available == 0
113 111 && (p->upstream->read->kq_eof || p->upstream->read->aio_eof))
114 if (p->upstream->read->available == 0) { 112 {
115 if (p->upstream->read->kq_eof) { 113 p->upstream->read->ready = 0;
116 p->upstream->read->ready = 0; 114 p->upstream->read->eof = 0;
117 p->upstream->read->eof = 0; 115 p->upstream_eof = 1;
118 p->upstream_eof = 1; 116 p->read = 1;
119 p->read = 1; 117
120 118 #if (HAVE_KQUEUE)
121 if (p->upstream->read->kq_errno) {
122 p->upstream->read->error = 1;
123 p->upstream_error = 1;
124 p->upstream_eof = 0;
125
126 ngx_log_error(NGX_LOG_ERR, p->log,
127 p->upstream->read->kq_errno,
128 "readv() failed");
129 }
130
131 break;
132 }
133 }
134
135 #if 0
136 if (p->upstream->read->kq_errno) { 119 if (p->upstream->read->kq_errno) {
120 p->upstream->read->error = 1;
121 p->upstream_error = 1;
122 p->upstream_eof = 0;
123
137 ngx_log_error(NGX_LOG_ERR, p->log, 124 ngx_log_error(NGX_LOG_ERR, p->log,
138 p->upstream->read->kq_errno, 125 p->upstream->read->kq_errno,
139 "readv() failed"); 126 "readv() failed");
140 p->upstream_error = 1;
141
142 break;
143
144 } else if (p->upstream->read->kq_eof
145 && p->upstream->read->available == 0) {
146 p->upstream_eof = 1;
147 p->read = 1;
148
149 break;
150 } 127 }
151 #endif 128 #endif
152 129
153 } 130 break;
154 #endif 131 }
155 132
156 if (p->free_raw_hunks) { 133 if (p->free_raw_hunks) {
157 134
158 /* use the free hunks if they exist */ 135 /* use the free hunks if they exist */
159 136
160 chain = p->free_raw_hunks; 137 chain = p->free_raw_hunks;
161 p->free_raw_hunks = NULL; 138 if (p->single_buf) {
139 p->free_raw_hunks = p->free_raw_hunks->next;
140 chain->next = NULL;
141 } else {
142 p->free_raw_hunks = NULL;
143 }
162 144
163 } else if (p->hunks < p->bufs.num) { 145 } else if (p->hunks < p->bufs.num) {
164 146
165 /* allocate a new hunk if it's still allowed */ 147 /* allocate a new hunk if it's still allowed */
166 148
167 ngx_test_null(h, ngx_create_temp_hunk(p->pool, 149 ngx_test_null(h, ngx_create_temp_hunk(p->pool, p->bufs.size),
168 p->bufs.size, 0, 0),
169 NGX_ABORT); 150 NGX_ABORT);
170 p->hunks++; 151 p->hunks++;
171 152
172 ngx_alloc_link_and_set_hunk(tl, h, p->pool, NGX_ABORT); 153 ngx_alloc_link_and_set_hunk(tl, h, p->pool, NGX_ABORT);
173 chain = tl; 154 chain = tl;
212 if (rc != NGX_OK) { 193 if (rc != NGX_OK) {
213 return rc; 194 return rc;
214 } 195 }
215 196
216 chain = p->free_raw_hunks; 197 chain = p->free_raw_hunks;
217 p->free_raw_hunks = NULL; 198 if (p->single_buf) {
199 p->free_raw_hunks = p->free_raw_hunks->next;
200 chain->next = NULL;
201 } else {
202 p->free_raw_hunks = NULL;
203 }
218 204
219 } else { 205 } else {
220 206
221 /* if there're no hunks to read in then disable a level event */ 207 /* if there're no hunks to read in then disable a level event */
222 208
227 213
228 n = ngx_recv_chain(p->upstream, chain); 214 n = ngx_recv_chain(p->upstream, chain);
229 215
230 ngx_log_debug(p->log, "recv_chain: %d" _ n); 216 ngx_log_debug(p->log, "recv_chain: %d" _ n);
231 217
218 if (p->free_raw_hunks) {
219 chain->next = p->free_raw_hunks;
220 }
232 p->free_raw_hunks = chain; 221 p->free_raw_hunks = chain;
233 222
234 if (n == NGX_ERROR) { 223 if (n == NGX_ERROR) {
235 p->upstream_error = 1; 224 p->upstream_error = 1;
236 return NGX_ERROR; 225 return NGX_ERROR;
237 } 226 }
238 227
239 if (n == NGX_AGAIN) { 228 if (n == NGX_AGAIN) {
229 if (p->single_buf) {
230 ngx_event_pipe_remove_shadow_links(chain->hunk);
231 }
232
240 break; 233 break;
241 } 234 }
242 235
243 p->read = 1; 236 p->read = 1;
244 237
281 /* STUB */ p->free_raw_hunks->hunk->num = p->num++; 274 /* STUB */ p->free_raw_hunks->hunk->num = p->num++;
282 if (p->input_filter(p, p->free_raw_hunks->hunk) == NGX_ERROR) { 275 if (p->input_filter(p, p->free_raw_hunks->hunk) == NGX_ERROR) {
283 return NGX_ABORT; 276 return NGX_ABORT;
284 } 277 }
285 278
286 /* TODO: p->free_raw_hunk->next can be free()ed */
287 p->free_raw_hunks = p->free_raw_hunks->next; 279 p->free_raw_hunks = p->free_raw_hunks->next;
280
281 for (cl = p->free_raw_hunks; cl; cl = cl->next) {
282 ngx_pfree(p->pool, cl->hunk->start);
283 }
288 } 284 }
289 285
290 if (p->cachable && p->in) { 286 if (p->cachable && p->in) {
291 if (ngx_event_pipe_write_chain_to_temp_file(p) == NGX_ABORT) { 287 if (ngx_event_pipe_write_chain_to_temp_file(p) == NGX_ABORT) {
292 return NGX_ABORT; 288 return NGX_ABORT;