Mercurial > hg > nginx
comparison src/event/ngx_event_proxy.c @ 77:57c2e18d3572
nginx-0.0.1-2003-04-17-21:59:35 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Thu, 17 Apr 2003 17:59:35 +0000 |
parents | 6127d7075471 |
children | 9f81437e0ad3 |
comparison
equal
deleted
inserted
replaced
76:6127d7075471 | 77:57c2e18d3572 |
---|---|
29 | 29 |
30 ngx_log_debug(p->log, "read upstream"); | 30 ngx_log_debug(p->log, "read upstream"); |
31 | 31 |
32 for ( ;; ) { | 32 for ( ;; ) { |
33 | 33 |
34 /* use the free hunks if they exist */ | 34 /* use the pre-read hunks if they exist */ |
35 | 35 |
36 if (p->free_hunks) { | 36 if (p->preread_hunks) { |
37 chain = p->free_hunks; | 37 chain = p->preread_hunks; |
38 p->free_hunks = NULL; | 38 p->preread_hunks = NULL; |
39 n = p->preread_size; | |
40 | |
41 } else { | |
42 | |
43 /* use the free hunks if they exist */ | |
44 | |
45 if (p->free_hunks) { | |
46 chain = p->free_hunks; | |
47 p->free_hunks = NULL; | |
39 | 48 |
40 ngx_log_debug(p->log, "free hunk: %08X:%d" _ chain->hunk _ | 49 ngx_log_debug(p->log, "free hunk: %08X:%d" _ chain->hunk _ |
41 chain->hunk->end - chain->hunk->last); | 50 chain->hunk->end - chain->hunk->last); |
42 | 51 |
43 /* allocate a new hunk if it's still allowed */ | 52 /* allocate a new hunk if it's still allowed */ |
44 | 53 |
45 } else if (p->allocated < p->max_block_size) { | 54 } else if (p->allocated < p->max_block_size) { |
46 ngx_test_null(h, | 55 ngx_test_null(h, |
47 ngx_create_temp_hunk(p->pool, p->block_size, 20, 20), | 56 ngx_create_temp_hunk(p->pool, |
48 NGX_ERROR); | 57 p->block_size, 20, 20), |
49 | 58 NGX_ERROR); |
50 p->allocated += p->block_size; | 59 |
51 | 60 p->allocated += p->block_size; |
52 ngx_test_null(temp, ngx_alloc_chain_entry(p->pool), NGX_ERROR); | 61 |
53 temp->hunk = h; | 62 ngx_test_null(temp, ngx_alloc_chain_entry(p->pool), NGX_ERROR); |
54 temp->next = NULL; | 63 temp->hunk = h; |
55 chain = temp; | 64 temp->next = NULL; |
65 chain = temp; | |
56 | 66 |
57 ngx_log_debug(p->log, "new hunk: %08X" _ chain->hunk); | 67 ngx_log_debug(p->log, "new hunk: %08X" _ chain->hunk); |
58 | 68 |
59 /* use the shadow hunks if they exist */ | 69 /* use the shadow hunks if they exist */ |
60 | 70 |
61 } else if (p->shadow_hunks) { | 71 } else if (p->shadow_hunks) { |
62 chain = p->shadow_hunks; | 72 chain = p->shadow_hunks; |
63 p->shadow_hunks = NULL; | 73 p->shadow_hunks = NULL; |
64 | 74 |
65 ngx_log_debug(p->log, "shadow hunk: %08X" _ chain->hunk _ | 75 ngx_log_debug(p->log, "shadow hunk: %08X" _ chain->hunk _ |
66 chain->hunk->end - chain->hunk->last); | 76 chain->hunk->end - chain->hunk->last); |
67 | 77 |
68 /* if it's allowed then save the incoming hunks to a temporary file, | 78 /* if the hunks is not needed to be saved in a cache and |
69 move the saved hunks to a shadow chain, | 79 a downstream is ready then write the hunks to a downstream */ |
70 and add the file hunks to an outgoing chain */ | 80 |
71 | 81 } else if (p->cachable == 0 && p->downstream->write->ready) { |
72 } else if (p->temp_offset < p->max_temp_size) { | 82 |
73 rc = ngx_event_proxy_write_chain_to_temp_file(p); | 83 rc = ngx_event_proxy_write_to_downstream(p); |
84 | |
85 continue; | |
86 | |
87 /* if it's allowed then save the incoming hunks | |
88 to a temporary file, move the saved hunks to a shadow chain, | |
89 and add the file hunks to an outgoing chain */ | |
90 | |
91 } else if (p->temp_offset < p->max_temp_file_size) { | |
92 rc = ngx_event_proxy_write_chain_to_temp_file(p); | |
74 | 93 |
75 ngx_log_debug(p->log, "temp offset: %d" _ p->temp_offset); | 94 ngx_log_debug(p->log, "temp offset: %d" _ p->temp_offset); |
76 | 95 |
77 if (rc != NGX_OK) { | 96 if (rc != NGX_OK) { |
78 return rc; | 97 return rc; |
79 } | 98 } |
80 | 99 |
81 chain = p->shadow_hunks; | 100 chain = p->shadow_hunks; |
82 p->shadow_hunks = NULL; | 101 p->shadow_hunks = NULL; |
83 | 102 |
84 ngx_log_debug(p->log, "new shadow hunk: %08X:%d" _ chain->hunk _ | 103 ngx_log_debug(p->log, "new shadow hunk: %08X:%d" _ chain->hunk _ |
85 chain->hunk->end - chain->hunk->last); | 104 chain->hunk->end - chain->hunk->last); |
86 | 105 |
87 /* if there're no hunks to read in then disable a level event */ | 106 /* if there're no hunks to read in then disable a level event */ |
88 | 107 |
89 } else { | 108 } else { |
90 if (ngx_event_flags & NGX_USE_LEVEL_EVENT) { | 109 if (ngx_event_flags & NGX_USE_LEVEL_EVENT) { |
91 p->block_upstream = 1; | 110 p->block_upstream = 1; |
92 } | 111 } |
93 | 112 |
94 break; | 113 break; |
95 } | 114 } |
96 | 115 |
97 n = ngx_recv_chain(p->upstream, chain); | 116 n = ngx_recv_chain(p->upstream, chain); |
117 | |
118 } | |
98 | 119 |
99 ngx_log_debug(p->log, "recv_chain: %d" _ n); | 120 ngx_log_debug(p->log, "recv_chain: %d" _ n); |
100 | 121 |
101 if (n == NGX_ERROR) { | 122 if (n == NGX_ERROR) { |
102 p->upstream_error = 1; | 123 p->upstream_error = 1; |
110 return NGX_ERROR; | 131 return NGX_ERROR; |
111 } | 132 } |
112 p->upstream->read->blocked = 0; | 133 p->upstream->read->blocked = 0; |
113 } | 134 } |
114 | 135 |
115 return NGX_AGAIN; | 136 break; |
116 } | 137 } |
117 | 138 |
118 if (n == 0) { | 139 if (n == 0) { |
119 if (chain->hunk->shadow == NULL) { | 140 if (chain->hunk->shadow == NULL) { |
120 p->free_hunks = chain; | 141 p->free_hunks = chain; |
177 /* the inline copy input filter */ | 198 /* the inline copy input filter */ |
178 | 199 |
179 ngx_test_null(h, ngx_alloc_hunk(p->pool), NGX_ERROR); | 200 ngx_test_null(h, ngx_alloc_hunk(p->pool), NGX_ERROR); |
180 ngx_memcpy(h, entry->hunk, sizeof(ngx_hunk_t)); | 201 ngx_memcpy(h, entry->hunk, sizeof(ngx_hunk_t)); |
181 h->shadow = entry->hunk; | 202 h->shadow = entry->hunk; |
182 h->type |= NGX_HUNK_LAST_SHADOW; | 203 h->type |= NGX_HUNK_LAST_SHADOW|NGX_HUNK_RECYCLED; |
183 entry->hunk->shadow = h; | 204 entry->hunk->shadow = h; |
184 | 205 |
185 ngx_test_null(temp, ngx_alloc_chain_entry(p->pool), | 206 ngx_test_null(temp, ngx_alloc_chain_entry(p->pool), |
186 NGX_ERROR); | 207 NGX_ERROR); |
187 temp->hunk = h; | 208 temp->hunk = h; |
305 if (rc != NGX_OK) { | 326 if (rc != NGX_OK) { |
306 return rc; | 327 return rc; |
307 } | 328 } |
308 } | 329 } |
309 | 330 |
310 if (p->out_hunks && p->client->write->ready) { | 331 if (p->out_hunks && p->downstream->write->ready) { |
311 rc = ngx_event_proxy_write_to_client(p); | 332 rc = ngx_event_proxy_write_to_downstream(p); |
312 } | 333 } |
313 | 334 |
314 } else if ((p->out_hunks || p->in_hunks) && p->client->write->ready) { | 335 } else if ((p->out_hunks || p->in_hunks) && p->downstream->write->ready) { |
315 rc = ngx_event_proxy_write_to_client(p); | 336 rc = ngx_event_proxy_write_to_downstream(p); |
316 } | 337 } |
317 | 338 |
318 p->level--; | 339 p->level--; |
319 | 340 |
320 ngx_log_debug(p->log, "level: %d" _ p->level); | 341 ngx_log_debug(p->log, "level: %d" _ p->level); |
334 return NGX_AGAIN; | 355 return NGX_AGAIN; |
335 } | 356 } |
336 } | 357 } |
337 | 358 |
338 | 359 |
339 int ngx_event_proxy_write_to_client(ngx_event_proxy_t *p) | 360 int ngx_event_proxy_write_to_downstream(ngx_event_proxy_t *p) |
340 { | 361 { |
341 int rc; | 362 int rc; |
342 ngx_hunk_t *h; | 363 ngx_hunk_t *h; |
343 ngx_chain_t *entry; | 364 ngx_chain_t *entry; |
344 | 365 |
345 ngx_log_debug(p->log, "write to client"); | 366 ngx_log_debug(p->log, "write to downstream"); |
346 | 367 |
347 h = p->busy_hunk; | 368 h = p->busy_hunk; |
348 | 369 |
349 for ( ;; ) { | 370 for ( ;; ) { |
350 | 371 |
489 entry = p->read_hunks; | 510 entry = p->read_hunks; |
490 size = 0; | 511 size = 0; |
491 | 512 |
492 do { | 513 do { |
493 size += entry->hunk->last - entry->hunk->pos; | 514 size += entry->hunk->last - entry->hunk->pos; |
494 if (size >= p->file_block_size) { | 515 if (size >= p->temp_file_write_size) { |
495 break; | 516 break; |
496 } | 517 } |
497 entry = entry->next; | 518 entry = entry->next; |
498 | 519 |
499 } while (entry); | 520 } while (entry); |
536 h->file_last = p->temp_offset; | 557 h->file_last = p->temp_offset; |
537 | 558 |
538 ngx_log_debug(p->log, "event proxy file hunk: %08X:%08X" _ h _ h->shadow); | 559 ngx_log_debug(p->log, "event proxy file hunk: %08X:%08X" _ h _ h->shadow); |
539 | 560 |
540 if (h->type & NGX_HUNK_LAST_SHADOW) { | 561 if (h->type & NGX_HUNK_LAST_SHADOW) { |
562 #if 0 | |
541 h->shadow->last = h->shadow->pos; | 563 h->shadow->last = h->shadow->pos; |
564 #else | |
565 h->shadow->last = h->shadow->pos = h->shadow->start; | |
566 #endif | |
542 } | 567 } |
543 | 568 |
544 if (p->out_hunks) { | 569 if (p->out_hunks) { |
545 p->last_out_hunk->next = entry; | 570 p->last_out_hunk->next = entry; |
546 | 571 |
589 | 614 |
590 for (entry = chain; entry; entry = entry->next) { | 615 for (entry = chain; entry; entry = entry->next) { |
591 ngx_test_null(h, ngx_alloc_hunk(p->pool), NGX_ERROR); | 616 ngx_test_null(h, ngx_alloc_hunk(p->pool), NGX_ERROR); |
592 ngx_memcpy(h, entry->hunk, sizeof(ngx_hunk_t)); | 617 ngx_memcpy(h, entry->hunk, sizeof(ngx_hunk_t)); |
593 h->shadow = entry->hunk; | 618 h->shadow = entry->hunk; |
594 h->type |= NGX_HUNK_LAST_SHADOW; | 619 h->type |= NGX_HUNK_LAST_SHADOW|NGX_HUNK_RECYCLED; |
595 entry->hunk->shadow = h; | 620 entry->hunk->shadow = h; |
596 | 621 |
597 ngx_test_null(temp, ngx_alloc_chain_entry(p->pool), NGX_ERROR); | 622 ngx_test_null(temp, ngx_alloc_chain_entry(p->pool), NGX_ERROR); |
598 temp->hunk = h; | 623 temp->hunk = h; |
599 temp->next = NULL; | 624 temp->next = NULL; |