comparison src/event/ngx_event_pipe.c @ 293:ec3c049681fd

nginx-0.0.3-2004-03-19-08:25:53 import
author Igor Sysoev <igor@sysoev.ru>
date Fri, 19 Mar 2004 05:25:53 +0000
parents 70e1c7d2b83d
children 5cfd65b8b0a7
comparison
equal deleted inserted replaced
292:a472bfb778b3 293:ec3c049681fd
252 252
253 if (n == 0) { 253 if (n == 0) {
254 p->upstream_eof = 1; 254 p->upstream_eof = 1;
255 break; 255 break;
256 } 256 }
257
258 } 257 }
259 258
260 p->read_length += n; 259 p->read_length += n;
261 cl = chain; 260 cl = chain;
262 261
267 size = cl->hunk->end - cl->hunk->last; 266 size = cl->hunk->end - cl->hunk->last;
268 267
269 if (n >= size) { 268 if (n >= size) {
270 cl->hunk->last = cl->hunk->end; 269 cl->hunk->last = cl->hunk->end;
271 270
272 /* STUB */ cl->hunk->num = p->num++; 271 /* STUB */ cl->hunk->num = p->num++;
273 272
274 if (p->input_filter(p, cl->hunk) == NGX_ERROR) { 273 if (p->input_filter(p, cl->hunk) == NGX_ERROR) {
275 return NGX_ABORT; 274 return NGX_ABORT;
276 } 275 }
277 276
286 285
287 p->free_raw_hunks = cl; 286 p->free_raw_hunks = cl;
288 } 287 }
289 288
290 if ((p->upstream_eof || p->upstream_error) && p->free_raw_hunks) { 289 if ((p->upstream_eof || p->upstream_error) && p->free_raw_hunks) {
291 /* STUB */ p->free_raw_hunks->hunk->num = p->num++; 290
291 /* STUB */ p->free_raw_hunks->hunk->num = p->num++;
292
292 if (p->input_filter(p, p->free_raw_hunks->hunk) == NGX_ERROR) { 293 if (p->input_filter(p, p->free_raw_hunks->hunk) == NGX_ERROR) {
293 return NGX_ABORT; 294 return NGX_ABORT;
294 } 295 }
295 296
296 p->free_raw_hunks = p->free_raw_hunks->next; 297 p->free_raw_hunks = p->free_raw_hunks->next;
324 for ( ;; ) { 325 for ( ;; ) {
325 if (p->downstream_error) { 326 if (p->downstream_error) {
326 return ngx_event_pipe_drain_chains(p); 327 return ngx_event_pipe_drain_chains(p);
327 } 328 }
328 329
329 if ((p->upstream_eof || p->upstream_error || p->upstream_done) 330 if (p->upstream_eof || p->upstream_error || p->upstream_done) {
330 && p->out == NULL && p->in == NULL) 331
331 { 332 /* pass the p->out and p->in chains to the output filter */
333
334 if (p->out) {
335 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, p->log, 0,
336 "pipe write downstream flush out");
337
338 if (p->output_filter(p->output_ctx, p->out) == NGX_ERROR) {
339 p->downstream_error = 1;
340 return ngx_event_pipe_drain_chains(p);
341 }
342
343 p->out = NULL;
344 }
345
346 if (p->in) {
347 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, p->log, 0,
348 "pipe write downstream flush in");
349
350 if (p->output_filter(p->output_ctx, p->in) == NGX_ERROR) {
351 p->downstream_error = 1;
352 return ngx_event_pipe_drain_chains(p);
353 }
354
355 p->in = NULL;
356 }
357
358 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, p->log, 0,
359 "pipe write downstream done");
360
361 /* TODO: free unused hunks */
362
332 p->downstream_done = 1; 363 p->downstream_done = 1;
333 break; 364 break;
334 } 365 }
335 366
336 if (!p->downstream->write->ready) { 367 if (!p->downstream->write->ready) {
337 break; 368 break;
338 } 369 }
339 370
340 /* 371 /*
341 * bsize is the busy hunks size 372 * bsize is the size of the busy hunks,
342 * to_write is the size of data that to be written 373 * to_write is the size of data in these hunks that
374 * would be written to a socket
343 */ 375 */
344 376
345 bsize = 0; 377 bsize = 0;
346 to_write = 0; 378 to_write = 0;
347 379
388 cl->next = NULL; 420 cl->next = NULL;
389 ngx_chain_add_link(out, ll, cl); 421 ngx_chain_add_link(out, ll, cl);
390 } 422 }
391 423
392 if (out == NULL) { 424 if (out == NULL) {
425
393 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, p->log, 0, 426 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, p->log, 0,
394 "pipe busy hunk data: %d", to_write); 427 "pipe busy hunk data to write: %d", to_write);
395 428
396 if (!(p->upstream_blocked && to_write)) { 429 if (!(p->upstream_blocked && to_write)) {
397 break; 430 break;
398 } 431 }
399 432
400 /* 433 }
401 * if the upstream is blocked and there are the busy hunks 434
402 * to write then write these hunks 435 /*
403 */ 436 * if the upstream is blocked and there are the busy hunks
404 } 437 * to write then write these hunks
438 */
405 439
406 if (p->output_filter(p->output_ctx, out) == NGX_ERROR) { 440 if (p->output_filter(p->output_ctx, out) == NGX_ERROR) {
407 p->downstream_error = 1; 441 p->downstream_error = 1;
408 442 return ngx_event_pipe_drain_chains(p);
409 /* handle the downstream error at the begin of a cycle */
410
411 continue;
412 } 443 }
413 444
414 ngx_chain_update_chains(&p->free, &p->busy, &out, p->tag); 445 ngx_chain_update_chains(&p->free, &p->busy, &out, p->tag);
415 446
416 for (cl = p->free; cl; cl = cl->next) { 447 for (cl = p->free; cl; cl = cl->next) {