annotate src/event/ngx_event_pipe.c @ 376:d13234035cad NGINX_0_6_32

nginx 0.6.32 *) Change: the "none" parameter in the "ssl_session_cache" directive; now this is default parameter. Thanks to Rob Mueller. *) Change: now the 0x00-0x1F, '"' and '\' characters are escaped as \xXX in an access_log. Thanks to Maxim Dounin. *) Change: now nginx allows several "Host" request header line. *) Feature: the "modified" flag in the "expires" directive. *) Feature: the $uid_got and $uid_set variables may be used at any request processing stage. *) Feature: the $hostname variable. Thanks to Andrei Nigmatulin. *) Feature: DESTDIR support. Thanks to Todd A. Fisher and Andras Voroskoi. *) Bugfix: if sub_filter and SSI were used together, then responses might were transferred incorrectly. *) Bugfix: large SSI inclusions might be truncated. *) Bugfix: the "proxy_pass" directive did not work with the HTTPS protocol; the bug had appeared in 0.6.9. *) Bugfix: worker processes might not catch reconfiguration and log rotation signals. *) Bugfix: nginx could not be built on latest Fedora 9 Linux. Thanks to Roxis. *) Bugfix: a segmentation fault might occur in worker process on Linux, if keepalive was enabled.
author Igor Sysoev <http://sysoev.ru>
date Mon, 07 Jul 2008 00:00:00 +0400
parents 05693816539c
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2 /*
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
3 * Copyright (C) Igor Sysoev
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
4 */
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
5
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
6
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
7 #include <ngx_config.h>
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
8 #include <ngx_core.h>
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
9 #include <ngx_event.h>
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
10 #include <ngx_event_pipe.h>
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
11
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
12
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
13 static ngx_int_t ngx_event_pipe_read_upstream(ngx_event_pipe_t *p);
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
14 static ngx_int_t ngx_event_pipe_write_to_downstream(ngx_event_pipe_t *p);
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
15
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
16 static ngx_int_t ngx_event_pipe_write_chain_to_temp_file(ngx_event_pipe_t *p);
16
74b1868dd3cd nginx 0.1.8
Igor Sysoev <http://sysoev.ru>
parents: 10
diff changeset
17 static ngx_inline void ngx_event_pipe_remove_shadow_links(ngx_buf_t *buf);
74b1868dd3cd nginx 0.1.8
Igor Sysoev <http://sysoev.ru>
parents: 10
diff changeset
18 static ngx_inline void ngx_event_pipe_free_shadow_raw_buf(ngx_chain_t **free,
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
19 ngx_buf_t *buf);
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
20 static ngx_int_t ngx_event_pipe_drain_chains(ngx_event_pipe_t *p);
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
21
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
22
126
df17fbafec8f nginx 0.3.10
Igor Sysoev <http://sysoev.ru>
parents: 76
diff changeset
23 ngx_int_t
344
eae74a780a84 nginx 0.6.16
Igor Sysoev <http://sysoev.ru>
parents: 340
diff changeset
24 ngx_event_pipe(ngx_event_pipe_t *p, ngx_int_t do_write)
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
25 {
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
26 u_int flags;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
27 ngx_event_t *rev, *wev;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
28
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
29 for ( ;; ) {
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
30 if (do_write) {
32
da8c190bdaba nginx 0.1.16
Igor Sysoev <http://sysoev.ru>
parents: 28
diff changeset
31 p->log->action = "sending to client";
da8c190bdaba nginx 0.1.16
Igor Sysoev <http://sysoev.ru>
parents: 28
diff changeset
32
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
33 if (ngx_event_pipe_write_to_downstream(p) == NGX_ABORT) {
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
34 return NGX_ABORT;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
35 }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
36 }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
37
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
38 p->read = 0;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
39 p->upstream_blocked = 0;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
40
32
da8c190bdaba nginx 0.1.16
Igor Sysoev <http://sysoev.ru>
parents: 28
diff changeset
41 p->log->action = "reading upstream";
da8c190bdaba nginx 0.1.16
Igor Sysoev <http://sysoev.ru>
parents: 28
diff changeset
42
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
43 if (ngx_event_pipe_read_upstream(p) == NGX_ABORT) {
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
44 return NGX_ABORT;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
45 }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
46
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
47 if (!p->read && !p->upstream_blocked) {
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
48 break;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
49 }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
50
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
51 do_write = 1;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
52 }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
53
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
54 if (p->upstream->fd != -1) {
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
55 rev = p->upstream->read;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
56
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
57 flags = (rev->eof || rev->error) ? NGX_CLOSE_EVENT : 0;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
58
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
59 if (ngx_handle_read_event(rev, flags) == NGX_ERROR) {
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
60 return NGX_ABORT;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
61 }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
62
162
6be073125f2e nginx 0.3.28
Igor Sysoev <http://sysoev.ru>
parents: 136
diff changeset
63 if (rev->active && !rev->ready) {
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
64 ngx_add_timer(rev, p->read_timeout);
162
6be073125f2e nginx 0.3.28
Igor Sysoev <http://sysoev.ru>
parents: 136
diff changeset
65
6be073125f2e nginx 0.3.28
Igor Sysoev <http://sysoev.ru>
parents: 136
diff changeset
66 } else if (rev->timer_set) {
6be073125f2e nginx 0.3.28
Igor Sysoev <http://sysoev.ru>
parents: 136
diff changeset
67 ngx_del_timer(rev);
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
68 }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
69 }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
70
58
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 56
diff changeset
71 if (p->downstream->fd != -1 && p->downstream->data == p->output_ctx) {
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
72 wev = p->downstream->write;
2
cc9f381affaa nginx 0.1.1
Igor Sysoev <http://sysoev.ru>
parents: 0
diff changeset
73 if (ngx_handle_write_event(wev, p->send_lowat) == NGX_ERROR) {
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
74 return NGX_ABORT;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
75 }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
76
162
6be073125f2e nginx 0.3.28
Igor Sysoev <http://sysoev.ru>
parents: 136
diff changeset
77 if (!wev->delayed) {
6be073125f2e nginx 0.3.28
Igor Sysoev <http://sysoev.ru>
parents: 136
diff changeset
78 if (wev->active && !wev->ready) {
6be073125f2e nginx 0.3.28
Igor Sysoev <http://sysoev.ru>
parents: 136
diff changeset
79 ngx_add_timer(wev, p->send_timeout);
6be073125f2e nginx 0.3.28
Igor Sysoev <http://sysoev.ru>
parents: 136
diff changeset
80
6be073125f2e nginx 0.3.28
Igor Sysoev <http://sysoev.ru>
parents: 136
diff changeset
81 } else if (wev->timer_set) {
6be073125f2e nginx 0.3.28
Igor Sysoev <http://sysoev.ru>
parents: 136
diff changeset
82 ngx_del_timer(wev);
6be073125f2e nginx 0.3.28
Igor Sysoev <http://sysoev.ru>
parents: 136
diff changeset
83 }
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
84 }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
85 }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
86
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
87 return NGX_OK;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
88 }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
89
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
90
126
df17fbafec8f nginx 0.3.10
Igor Sysoev <http://sysoev.ru>
parents: 76
diff changeset
91 static ngx_int_t
df17fbafec8f nginx 0.3.10
Igor Sysoev <http://sysoev.ru>
parents: 76
diff changeset
92 ngx_event_pipe_read_upstream(ngx_event_pipe_t *p)
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
93 {
10
46833bd150cb nginx 0.1.5
Igor Sysoev <http://sysoev.ru>
parents: 6
diff changeset
94 ssize_t n, size;
46833bd150cb nginx 0.1.5
Igor Sysoev <http://sysoev.ru>
parents: 6
diff changeset
95 ngx_int_t rc;
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
96 ngx_buf_t *b;
56
3050baa54a26 nginx 0.1.28
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
97 ngx_chain_t *chain, *cl, *ln;
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
98
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
99 if (p->upstream_eof || p->upstream_error || p->upstream_done) {
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
100 return NGX_OK;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
101 }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
102
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
103 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, p->log, 0,
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
104 "pipe read upstream: %d", p->upstream->read->ready);
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
105
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
106 for ( ;; ) {
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
107
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
108 if (p->upstream_eof || p->upstream_error || p->upstream_done) {
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
109 break;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
110 }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
111
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
112 if (p->preread_bufs == NULL && !p->upstream->read->ready) {
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
113 break;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
114 }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
115
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
116 if (p->preread_bufs) {
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
117
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
118 /* use the pre-read bufs if they exist */
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
119
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
120 chain = p->preread_bufs;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
121 p->preread_bufs = NULL;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
122 n = p->preread_size;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
123
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
124 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, p->log, 0,
10
46833bd150cb nginx 0.1.5
Igor Sysoev <http://sysoev.ru>
parents: 6
diff changeset
125 "pipe preread: %z", n);
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
126
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
127 if (n) {
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
128 p->read = 1;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
129 }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
130
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
131 } else {
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
132
130
82d695e3d662 nginx 0.3.12
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
133 #if (NGX_HAVE_KQUEUE)
82d695e3d662 nginx 0.3.12
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
134
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
135 /*
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
136 * kqueue notifies about the end of file or a pending error.
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
137 * This test allows not to allocate a buf on these conditions
126
df17fbafec8f nginx 0.3.10
Igor Sysoev <http://sysoev.ru>
parents: 76
diff changeset
138 * and not to call c->recv_chain().
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
139 */
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
140
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
141 if (p->upstream->read->available == 0
136
3656228c0b56 nginx 0.3.15
Igor Sysoev <http://sysoev.ru>
parents: 132
diff changeset
142 && p->upstream->read->pending_eof)
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
143 {
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
144 p->upstream->read->ready = 0;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
145 p->upstream->read->eof = 0;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
146 p->upstream_eof = 1;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
147 p->read = 1;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
148
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
149 if (p->upstream->read->kq_errno) {
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
150 p->upstream->read->error = 1;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
151 p->upstream_error = 1;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
152 p->upstream_eof = 0;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
153
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
154 ngx_log_error(NGX_LOG_ERR, p->log,
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
155 p->upstream->read->kq_errno,
130
82d695e3d662 nginx 0.3.12
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
156 "kevent() reported that upstream "
82d695e3d662 nginx 0.3.12
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
157 "closed connection");
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
158 }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
159
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
160 break;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
161 }
130
82d695e3d662 nginx 0.3.12
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
162 #endif
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
163
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
164 if (p->free_raw_bufs) {
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
165
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
166 /* use the free bufs if they exist */
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
167
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
168 chain = p->free_raw_bufs;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
169 if (p->single_buf) {
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
170 p->free_raw_bufs = p->free_raw_bufs->next;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
171 chain->next = NULL;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
172 } else {
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
173 p->free_raw_bufs = NULL;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
174 }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
175
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
176 } else if (p->allocated < p->bufs.num) {
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
177
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
178 /* allocate a new buf if it's still allowed */
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
179
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents: 32
diff changeset
180 b = ngx_create_temp_buf(p->pool, p->bufs.size);
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents: 32
diff changeset
181 if (b == NULL) {
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
182 return NGX_ABORT;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
183 }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
184
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
185 p->allocated++;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
186
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents: 32
diff changeset
187 chain = ngx_alloc_chain_link(p->pool);
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents: 32
diff changeset
188 if (chain == NULL) {
32
da8c190bdaba nginx 0.1.16
Igor Sysoev <http://sysoev.ru>
parents: 28
diff changeset
189 return NGX_ABORT;
da8c190bdaba nginx 0.1.16
Igor Sysoev <http://sysoev.ru>
parents: 28
diff changeset
190 }
da8c190bdaba nginx 0.1.16
Igor Sysoev <http://sysoev.ru>
parents: 28
diff changeset
191
da8c190bdaba nginx 0.1.16
Igor Sysoev <http://sysoev.ru>
parents: 28
diff changeset
192 chain->buf = b;
da8c190bdaba nginx 0.1.16
Igor Sysoev <http://sysoev.ru>
parents: 28
diff changeset
193 chain->next = NULL;
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
194
340
10cc350ed8a1 nginx 0.6.14
Igor Sysoev <http://sysoev.ru>
parents: 284
diff changeset
195 } else if (!p->cacheable
58
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 56
diff changeset
196 && p->downstream->data == p->output_ctx
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents: 70
diff changeset
197 && p->downstream->write->ready
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents: 70
diff changeset
198 && !p->downstream->write->delayed)
58
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 56
diff changeset
199 {
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
200 /*
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
201 * if the bufs are not needed to be saved in a cache and
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
202 * a downstream is ready then write the bufs to a downstream
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
203 */
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
204
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
205 p->upstream_blocked = 1;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
206
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
207 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, p->log, 0,
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
208 "pipe downstream ready");
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
209
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
210 break;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
211
340
10cc350ed8a1 nginx 0.6.14
Igor Sysoev <http://sysoev.ru>
parents: 284
diff changeset
212 } else if (p->cacheable
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
213 || p->temp_file->offset < p->max_temp_file_size)
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
214 {
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
215
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
216 /*
32
da8c190bdaba nginx 0.1.16
Igor Sysoev <http://sysoev.ru>
parents: 28
diff changeset
217 * if it is allowed, then save some bufs from r->in
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
218 * to a temporary file, and add them to a r->out chain
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
219 */
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
220
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
221 rc = ngx_event_pipe_write_chain_to_temp_file(p);
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
222
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
223 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, p->log, 0,
10
46833bd150cb nginx 0.1.5
Igor Sysoev <http://sysoev.ru>
parents: 6
diff changeset
224 "pipe temp offset: %O", p->temp_file->offset);
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
225
70
8ad297c88dcb nginx 0.1.35
Igor Sysoev <http://sysoev.ru>
parents: 58
diff changeset
226 if (rc == NGX_BUSY) {
8ad297c88dcb nginx 0.1.35
Igor Sysoev <http://sysoev.ru>
parents: 58
diff changeset
227 break;
8ad297c88dcb nginx 0.1.35
Igor Sysoev <http://sysoev.ru>
parents: 58
diff changeset
228 }
8ad297c88dcb nginx 0.1.35
Igor Sysoev <http://sysoev.ru>
parents: 58
diff changeset
229
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
230 if (rc == NGX_AGAIN) {
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
231 if (ngx_event_flags & NGX_USE_LEVEL_EVENT
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
232 && p->upstream->read->active
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
233 && p->upstream->read->ready)
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
234 {
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
235 if (ngx_del_event(p->upstream->read, NGX_READ_EVENT, 0)
126
df17fbafec8f nginx 0.3.10
Igor Sysoev <http://sysoev.ru>
parents: 76
diff changeset
236 == NGX_ERROR)
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
237 {
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
238 return NGX_ABORT;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
239 }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
240 }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
241 }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
242
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
243 if (rc != NGX_OK) {
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
244 return rc;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
245 }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
246
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
247 chain = p->free_raw_bufs;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
248 if (p->single_buf) {
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
249 p->free_raw_bufs = p->free_raw_bufs->next;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
250 chain->next = NULL;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
251 } else {
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
252 p->free_raw_bufs = NULL;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
253 }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
254
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
255 } else {
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
256
32
da8c190bdaba nginx 0.1.16
Igor Sysoev <http://sysoev.ru>
parents: 28
diff changeset
257 /* there are no bufs to read in */
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
258
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
259 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, p->log, 0,
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
260 "no pipe bufs to read in");
126
df17fbafec8f nginx 0.3.10
Igor Sysoev <http://sysoev.ru>
parents: 76
diff changeset
261
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
262 break;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
263 }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
264
126
df17fbafec8f nginx 0.3.10
Igor Sysoev <http://sysoev.ru>
parents: 76
diff changeset
265 n = p->upstream->recv_chain(p->upstream, chain);
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
266
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
267 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, p->log, 0,
10
46833bd150cb nginx 0.1.5
Igor Sysoev <http://sysoev.ru>
parents: 6
diff changeset
268 "pipe recv chain: %z", n);
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
269
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
270 if (p->free_raw_bufs) {
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
271 chain->next = p->free_raw_bufs;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
272 }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
273 p->free_raw_bufs = chain;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
274
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
275 if (n == NGX_ERROR) {
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
276 p->upstream_error = 1;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
277 return NGX_ERROR;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
278 }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
279
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
280 if (n == NGX_AGAIN) {
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
281 if (p->single_buf) {
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
282 ngx_event_pipe_remove_shadow_links(chain->buf);
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
283 }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
284
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
285 break;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
286 }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
287
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
288 p->read = 1;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
289
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
290 if (n == 0) {
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
291 p->upstream_eof = 1;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
292 break;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
293 }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
294 }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
295
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
296 p->read_length += n;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
297 cl = chain;
258
6ae1357b7b7c nginx 0.4.14
Igor Sysoev <http://sysoev.ru>
parents: 256
diff changeset
298 p->free_raw_bufs = NULL;
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
299
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
300 while (cl && n > 0) {
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
301
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
302 ngx_event_pipe_remove_shadow_links(cl->buf);
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
303
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
304 size = cl->buf->end - cl->buf->last;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
305
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
306 if (n >= size) {
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
307 cl->buf->last = cl->buf->end;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
308
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
309 /* STUB */ cl->buf->num = p->num++;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
310
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
311 if (p->input_filter(p, cl->buf) == NGX_ERROR) {
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
312 return NGX_ABORT;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
313 }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
314
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
315 n -= size;
56
3050baa54a26 nginx 0.1.28
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
316 ln = cl;
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
317 cl = cl->next;
56
3050baa54a26 nginx 0.1.28
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
318 ngx_free_chain(p->pool, ln);
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
319
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
320 } else {
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
321 cl->buf->last += n;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
322 n = 0;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
323 }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
324 }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
325
258
6ae1357b7b7c nginx 0.4.14
Igor Sysoev <http://sysoev.ru>
parents: 256
diff changeset
326 if (cl) {
6ae1357b7b7c nginx 0.4.14
Igor Sysoev <http://sysoev.ru>
parents: 256
diff changeset
327 for (ln = cl; ln->next; ln = ln->next) { /* void */ }
6ae1357b7b7c nginx 0.4.14
Igor Sysoev <http://sysoev.ru>
parents: 256
diff changeset
328
6ae1357b7b7c nginx 0.4.14
Igor Sysoev <http://sysoev.ru>
parents: 256
diff changeset
329 ln->next = p->free_raw_bufs;
6ae1357b7b7c nginx 0.4.14
Igor Sysoev <http://sysoev.ru>
parents: 256
diff changeset
330 p->free_raw_bufs = cl;
6ae1357b7b7c nginx 0.4.14
Igor Sysoev <http://sysoev.ru>
parents: 256
diff changeset
331 }
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
332 }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
333
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
334 #if (NGX_DEBUG)
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
335
2
cc9f381affaa nginx 0.1.1
Igor Sysoev <http://sysoev.ru>
parents: 0
diff changeset
336 for (cl = p->busy; cl; cl = cl->next) {
32
da8c190bdaba nginx 0.1.16
Igor Sysoev <http://sysoev.ru>
parents: 28
diff changeset
337 ngx_log_debug8(NGX_LOG_DEBUG_EVENT, p->log, 0,
da8c190bdaba nginx 0.1.16
Igor Sysoev <http://sysoev.ru>
parents: 28
diff changeset
338 "pipe buf busy s:%d t:%d f:%d "
da8c190bdaba nginx 0.1.16
Igor Sysoev <http://sysoev.ru>
parents: 28
diff changeset
339 "%p, pos %p, size: %z "
da8c190bdaba nginx 0.1.16
Igor Sysoev <http://sysoev.ru>
parents: 28
diff changeset
340 "file: %O, size: %z",
da8c190bdaba nginx 0.1.16
Igor Sysoev <http://sysoev.ru>
parents: 28
diff changeset
341 (cl->buf->shadow ? 1 : 0),
da8c190bdaba nginx 0.1.16
Igor Sysoev <http://sysoev.ru>
parents: 28
diff changeset
342 cl->buf->temporary, cl->buf->in_file,
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
343 cl->buf->start, cl->buf->pos,
32
da8c190bdaba nginx 0.1.16
Igor Sysoev <http://sysoev.ru>
parents: 28
diff changeset
344 cl->buf->last - cl->buf->pos,
da8c190bdaba nginx 0.1.16
Igor Sysoev <http://sysoev.ru>
parents: 28
diff changeset
345 cl->buf->file_pos,
da8c190bdaba nginx 0.1.16
Igor Sysoev <http://sysoev.ru>
parents: 28
diff changeset
346 cl->buf->file_last - cl->buf->file_pos);
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
347 }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
348
2
cc9f381affaa nginx 0.1.1
Igor Sysoev <http://sysoev.ru>
parents: 0
diff changeset
349 for (cl = p->out; cl; cl = cl->next) {
32
da8c190bdaba nginx 0.1.16
Igor Sysoev <http://sysoev.ru>
parents: 28
diff changeset
350 ngx_log_debug8(NGX_LOG_DEBUG_EVENT, p->log, 0,
da8c190bdaba nginx 0.1.16
Igor Sysoev <http://sysoev.ru>
parents: 28
diff changeset
351 "pipe buf out s:%d t:%d f:%d "
da8c190bdaba nginx 0.1.16
Igor Sysoev <http://sysoev.ru>
parents: 28
diff changeset
352 "%p, pos %p, size: %z "
da8c190bdaba nginx 0.1.16
Igor Sysoev <http://sysoev.ru>
parents: 28
diff changeset
353 "file: %O, size: %z",
da8c190bdaba nginx 0.1.16
Igor Sysoev <http://sysoev.ru>
parents: 28
diff changeset
354 (cl->buf->shadow ? 1 : 0),
da8c190bdaba nginx 0.1.16
Igor Sysoev <http://sysoev.ru>
parents: 28
diff changeset
355 cl->buf->temporary, cl->buf->in_file,
da8c190bdaba nginx 0.1.16
Igor Sysoev <http://sysoev.ru>
parents: 28
diff changeset
356 cl->buf->start, cl->buf->pos,
da8c190bdaba nginx 0.1.16
Igor Sysoev <http://sysoev.ru>
parents: 28
diff changeset
357 cl->buf->last - cl->buf->pos,
da8c190bdaba nginx 0.1.16
Igor Sysoev <http://sysoev.ru>
parents: 28
diff changeset
358 cl->buf->file_pos,
da8c190bdaba nginx 0.1.16
Igor Sysoev <http://sysoev.ru>
parents: 28
diff changeset
359 cl->buf->file_last - cl->buf->file_pos);
2
cc9f381affaa nginx 0.1.1
Igor Sysoev <http://sysoev.ru>
parents: 0
diff changeset
360 }
cc9f381affaa nginx 0.1.1
Igor Sysoev <http://sysoev.ru>
parents: 0
diff changeset
361
cc9f381affaa nginx 0.1.1
Igor Sysoev <http://sysoev.ru>
parents: 0
diff changeset
362 for (cl = p->in; cl; cl = cl->next) {
32
da8c190bdaba nginx 0.1.16
Igor Sysoev <http://sysoev.ru>
parents: 28
diff changeset
363 ngx_log_debug8(NGX_LOG_DEBUG_EVENT, p->log, 0,
da8c190bdaba nginx 0.1.16
Igor Sysoev <http://sysoev.ru>
parents: 28
diff changeset
364 "pipe buf in s:%d t:%d f:%d "
da8c190bdaba nginx 0.1.16
Igor Sysoev <http://sysoev.ru>
parents: 28
diff changeset
365 "%p, pos %p, size: %z "
da8c190bdaba nginx 0.1.16
Igor Sysoev <http://sysoev.ru>
parents: 28
diff changeset
366 "file: %O, size: %z",
da8c190bdaba nginx 0.1.16
Igor Sysoev <http://sysoev.ru>
parents: 28
diff changeset
367 (cl->buf->shadow ? 1 : 0),
da8c190bdaba nginx 0.1.16
Igor Sysoev <http://sysoev.ru>
parents: 28
diff changeset
368 cl->buf->temporary, cl->buf->in_file,
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
369 cl->buf->start, cl->buf->pos,
32
da8c190bdaba nginx 0.1.16
Igor Sysoev <http://sysoev.ru>
parents: 28
diff changeset
370 cl->buf->last - cl->buf->pos,
da8c190bdaba nginx 0.1.16
Igor Sysoev <http://sysoev.ru>
parents: 28
diff changeset
371 cl->buf->file_pos,
da8c190bdaba nginx 0.1.16
Igor Sysoev <http://sysoev.ru>
parents: 28
diff changeset
372 cl->buf->file_last - cl->buf->file_pos);
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
373 }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
374
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
375 for (cl = p->free_raw_bufs; cl; cl = cl->next) {
32
da8c190bdaba nginx 0.1.16
Igor Sysoev <http://sysoev.ru>
parents: 28
diff changeset
376 ngx_log_debug8(NGX_LOG_DEBUG_EVENT, p->log, 0,
da8c190bdaba nginx 0.1.16
Igor Sysoev <http://sysoev.ru>
parents: 28
diff changeset
377 "pipe buf free s:%d t:%d f:%d "
da8c190bdaba nginx 0.1.16
Igor Sysoev <http://sysoev.ru>
parents: 28
diff changeset
378 "%p, pos %p, size: %z "
da8c190bdaba nginx 0.1.16
Igor Sysoev <http://sysoev.ru>
parents: 28
diff changeset
379 "file: %O, size: %z",
da8c190bdaba nginx 0.1.16
Igor Sysoev <http://sysoev.ru>
parents: 28
diff changeset
380 (cl->buf->shadow ? 1 : 0),
da8c190bdaba nginx 0.1.16
Igor Sysoev <http://sysoev.ru>
parents: 28
diff changeset
381 cl->buf->temporary, cl->buf->in_file,
da8c190bdaba nginx 0.1.16
Igor Sysoev <http://sysoev.ru>
parents: 28
diff changeset
382 cl->buf->start, cl->buf->pos,
da8c190bdaba nginx 0.1.16
Igor Sysoev <http://sysoev.ru>
parents: 28
diff changeset
383 cl->buf->last - cl->buf->pos,
da8c190bdaba nginx 0.1.16
Igor Sysoev <http://sysoev.ru>
parents: 28
diff changeset
384 cl->buf->file_pos,
da8c190bdaba nginx 0.1.16
Igor Sysoev <http://sysoev.ru>
parents: 28
diff changeset
385 cl->buf->file_last - cl->buf->file_pos);
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
386 }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
387
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
388 #endif
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
389
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
390 if ((p->upstream_eof || p->upstream_error) && p->free_raw_bufs) {
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
391
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
392 /* STUB */ p->free_raw_bufs->buf->num = p->num++;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
393
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
394 if (p->input_filter(p, p->free_raw_bufs->buf) == NGX_ERROR) {
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
395 return NGX_ABORT;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
396 }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
397
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
398 p->free_raw_bufs = p->free_raw_bufs->next;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
399
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
400 if (p->free_bufs) {
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
401 for (cl = p->free_raw_bufs; cl; cl = cl->next) {
2
cc9f381affaa nginx 0.1.1
Igor Sysoev <http://sysoev.ru>
parents: 0
diff changeset
402 if (cl->buf->shadow == NULL) {
126
df17fbafec8f nginx 0.3.10
Igor Sysoev <http://sysoev.ru>
parents: 76
diff changeset
403 ngx_pfree(p->pool, cl->buf->start);
2
cc9f381affaa nginx 0.1.1
Igor Sysoev <http://sysoev.ru>
parents: 0
diff changeset
404 }
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
405 }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
406 }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
407 }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
408
340
10cc350ed8a1 nginx 0.6.14
Igor Sysoev <http://sysoev.ru>
parents: 284
diff changeset
409 if (p->cacheable && p->in) {
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
410 if (ngx_event_pipe_write_chain_to_temp_file(p) == NGX_ABORT) {
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
411 return NGX_ABORT;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
412 }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
413 }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
414
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
415 return NGX_OK;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
416 }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
417
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
418
126
df17fbafec8f nginx 0.3.10
Igor Sysoev <http://sysoev.ru>
parents: 76
diff changeset
419 static ngx_int_t
df17fbafec8f nginx 0.3.10
Igor Sysoev <http://sysoev.ru>
parents: 76
diff changeset
420 ngx_event_pipe_write_to_downstream(ngx_event_pipe_t *p)
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
421 {
284
3dbecd747fbb nginx 0.5.12
Igor Sysoev <http://sysoev.ru>
parents: 276
diff changeset
422 u_char *prev;
132
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 130
diff changeset
423 size_t bsize;
346
05693816539c nginx 0.6.17
Igor Sysoev <http://sysoev.ru>
parents: 344
diff changeset
424 ngx_int_t rc;
276
c5c2b2883984 nginx 0.5.8
Igor Sysoev <http://sysoev.ru>
parents: 274
diff changeset
425 ngx_uint_t flush, prev_last_shadow;
132
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 130
diff changeset
426 ngx_chain_t *out, **ll, *cl;
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 130
diff changeset
427 ngx_connection_t *downstream;
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 130
diff changeset
428
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 130
diff changeset
429 downstream = p->downstream;
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
430
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
431 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, p->log, 0,
132
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 130
diff changeset
432 "pipe write downstream: %d", downstream->write->ready);
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
433
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
434 for ( ;; ) {
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
435 if (p->downstream_error) {
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
436 return ngx_event_pipe_drain_chains(p);
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
437 }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
438
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
439 if (p->upstream_eof || p->upstream_error || p->upstream_done) {
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
440
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
441 /* pass the p->out and p->in chains to the output filter */
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
442
58
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 56
diff changeset
443 for (cl = p->busy; cl; cl = cl->next) {
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 56
diff changeset
444 cl->buf->recycled = 0;
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 56
diff changeset
445 }
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 56
diff changeset
446
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
447 if (p->out) {
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
448 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, p->log, 0,
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
449 "pipe write downstream flush out");
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
450
58
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 56
diff changeset
451 for (cl = p->out; cl; cl = cl->next) {
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 56
diff changeset
452 cl->buf->recycled = 0;
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 56
diff changeset
453 }
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 56
diff changeset
454
346
05693816539c nginx 0.6.17
Igor Sysoev <http://sysoev.ru>
parents: 344
diff changeset
455 rc = p->output_filter(p->output_ctx, p->out);
05693816539c nginx 0.6.17
Igor Sysoev <http://sysoev.ru>
parents: 344
diff changeset
456
05693816539c nginx 0.6.17
Igor Sysoev <http://sysoev.ru>
parents: 344
diff changeset
457 if (downstream->destroyed) {
05693816539c nginx 0.6.17
Igor Sysoev <http://sysoev.ru>
parents: 344
diff changeset
458 return NGX_ABORT;
05693816539c nginx 0.6.17
Igor Sysoev <http://sysoev.ru>
parents: 344
diff changeset
459 }
05693816539c nginx 0.6.17
Igor Sysoev <http://sysoev.ru>
parents: 344
diff changeset
460
05693816539c nginx 0.6.17
Igor Sysoev <http://sysoev.ru>
parents: 344
diff changeset
461 if (rc == NGX_ERROR) {
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
462 p->downstream_error = 1;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
463 return ngx_event_pipe_drain_chains(p);
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
464 }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
465
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
466 p->out = NULL;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
467 }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
468
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
469 if (p->in) {
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
470 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, p->log, 0,
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
471 "pipe write downstream flush in");
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
472
58
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 56
diff changeset
473 for (cl = p->in; cl; cl = cl->next) {
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 56
diff changeset
474 cl->buf->recycled = 0;
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 56
diff changeset
475 }
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 56
diff changeset
476
346
05693816539c nginx 0.6.17
Igor Sysoev <http://sysoev.ru>
parents: 344
diff changeset
477 rc = p->output_filter(p->output_ctx, p->in);
132
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 130
diff changeset
478
346
05693816539c nginx 0.6.17
Igor Sysoev <http://sysoev.ru>
parents: 344
diff changeset
479 if (downstream->destroyed) {
05693816539c nginx 0.6.17
Igor Sysoev <http://sysoev.ru>
parents: 344
diff changeset
480 return NGX_ABORT;
05693816539c nginx 0.6.17
Igor Sysoev <http://sysoev.ru>
parents: 344
diff changeset
481 }
132
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 130
diff changeset
482
346
05693816539c nginx 0.6.17
Igor Sysoev <http://sysoev.ru>
parents: 344
diff changeset
483 if (rc == NGX_ERROR) {
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
484 p->downstream_error = 1;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
485 return ngx_event_pipe_drain_chains(p);
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
486 }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
487
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
488 p->in = NULL;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
489 }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
490
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
491 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, p->log, 0,
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
492 "pipe write downstream done");
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
493
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
494 /* TODO: free unused bufs */
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
495
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
496 p->downstream_done = 1;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
497 break;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
498 }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
499
132
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 130
diff changeset
500 if (downstream->data != p->output_ctx
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 130
diff changeset
501 || !downstream->write->ready
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 130
diff changeset
502 || downstream->write->delayed)
58
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 56
diff changeset
503 {
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
504 break;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
505 }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
506
28
7ca9bdc82b3f nginx 0.1.14
Igor Sysoev <http://sysoev.ru>
parents: 22
diff changeset
507 /* bsize is the size of the busy recycled bufs */
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
508
284
3dbecd747fbb nginx 0.5.12
Igor Sysoev <http://sysoev.ru>
parents: 276
diff changeset
509 prev = NULL;
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
510 bsize = 0;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
511
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
512 for (cl = p->busy; cl; cl = cl->next) {
284
3dbecd747fbb nginx 0.5.12
Igor Sysoev <http://sysoev.ru>
parents: 276
diff changeset
513
28
7ca9bdc82b3f nginx 0.1.14
Igor Sysoev <http://sysoev.ru>
parents: 22
diff changeset
514 if (cl->buf->recycled) {
284
3dbecd747fbb nginx 0.5.12
Igor Sysoev <http://sysoev.ru>
parents: 276
diff changeset
515 if (prev == cl->buf->start) {
3dbecd747fbb nginx 0.5.12
Igor Sysoev <http://sysoev.ru>
parents: 276
diff changeset
516 continue;
3dbecd747fbb nginx 0.5.12
Igor Sysoev <http://sysoev.ru>
parents: 276
diff changeset
517 }
3dbecd747fbb nginx 0.5.12
Igor Sysoev <http://sysoev.ru>
parents: 276
diff changeset
518
28
7ca9bdc82b3f nginx 0.1.14
Igor Sysoev <http://sysoev.ru>
parents: 22
diff changeset
519 bsize += cl->buf->end - cl->buf->start;
284
3dbecd747fbb nginx 0.5.12
Igor Sysoev <http://sysoev.ru>
parents: 276
diff changeset
520 prev = cl->buf->start;
28
7ca9bdc82b3f nginx 0.1.14
Igor Sysoev <http://sysoev.ru>
parents: 22
diff changeset
521 }
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
522 }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
523
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
524 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, p->log, 0,
28
7ca9bdc82b3f nginx 0.1.14
Igor Sysoev <http://sysoev.ru>
parents: 22
diff changeset
525 "pipe write busy: %uz", bsize);
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
526
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
527 out = NULL;
284
3dbecd747fbb nginx 0.5.12
Igor Sysoev <http://sysoev.ru>
parents: 276
diff changeset
528
3dbecd747fbb nginx 0.5.12
Igor Sysoev <http://sysoev.ru>
parents: 276
diff changeset
529 if (bsize >= (size_t) p->busy_size) {
3dbecd747fbb nginx 0.5.12
Igor Sysoev <http://sysoev.ru>
parents: 276
diff changeset
530 flush = 1;
3dbecd747fbb nginx 0.5.12
Igor Sysoev <http://sysoev.ru>
parents: 276
diff changeset
531 goto flush;
3dbecd747fbb nginx 0.5.12
Igor Sysoev <http://sysoev.ru>
parents: 276
diff changeset
532 }
3dbecd747fbb nginx 0.5.12
Igor Sysoev <http://sysoev.ru>
parents: 276
diff changeset
533
3dbecd747fbb nginx 0.5.12
Igor Sysoev <http://sysoev.ru>
parents: 276
diff changeset
534 flush = 0;
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
535 ll = NULL;
276
c5c2b2883984 nginx 0.5.8
Igor Sysoev <http://sysoev.ru>
parents: 274
diff changeset
536 prev_last_shadow = 1;
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
537
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
538 for ( ;; ) {
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
539 if (p->out) {
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
540 cl = p->out;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
541
28
7ca9bdc82b3f nginx 0.1.14
Igor Sysoev <http://sysoev.ru>
parents: 22
diff changeset
542 if (cl->buf->recycled
7ca9bdc82b3f nginx 0.1.14
Igor Sysoev <http://sysoev.ru>
parents: 22
diff changeset
543 && bsize + cl->buf->last - cl->buf->pos > p->busy_size)
7ca9bdc82b3f nginx 0.1.14
Igor Sysoev <http://sysoev.ru>
parents: 22
diff changeset
544 {
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
545 flush = 1;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
546 break;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
547 }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
548
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
549 p->out = p->out->next;
28
7ca9bdc82b3f nginx 0.1.14
Igor Sysoev <http://sysoev.ru>
parents: 22
diff changeset
550
7ca9bdc82b3f nginx 0.1.14
Igor Sysoev <http://sysoev.ru>
parents: 22
diff changeset
551 ngx_event_pipe_free_shadow_raw_buf(&p->free_raw_bufs, cl->buf);
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
552
340
10cc350ed8a1 nginx 0.6.14
Igor Sysoev <http://sysoev.ru>
parents: 284
diff changeset
553 } else if (!p->cacheable && p->in) {
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
554 cl = p->in;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
555
274
052a7b1d40e5 nginx 0.5.7
Igor Sysoev <http://sysoev.ru>
parents: 258
diff changeset
556 ngx_log_debug3(NGX_LOG_DEBUG_EVENT, p->log, 0,
052a7b1d40e5 nginx 0.5.7
Igor Sysoev <http://sysoev.ru>
parents: 258
diff changeset
557 "pipe write buf ls:%d %p %z",
052a7b1d40e5 nginx 0.5.7
Igor Sysoev <http://sysoev.ru>
parents: 258
diff changeset
558 cl->buf->last_shadow,
052a7b1d40e5 nginx 0.5.7
Igor Sysoev <http://sysoev.ru>
parents: 258
diff changeset
559 cl->buf->pos,
052a7b1d40e5 nginx 0.5.7
Igor Sysoev <http://sysoev.ru>
parents: 258
diff changeset
560 cl->buf->last - cl->buf->pos);
052a7b1d40e5 nginx 0.5.7
Igor Sysoev <http://sysoev.ru>
parents: 258
diff changeset
561
28
7ca9bdc82b3f nginx 0.1.14
Igor Sysoev <http://sysoev.ru>
parents: 22
diff changeset
562 if (cl->buf->recycled
256
2e9c57a5e50a nginx 0.4.13
Igor Sysoev <http://sysoev.ru>
parents: 162
diff changeset
563 && cl->buf->last_shadow
28
7ca9bdc82b3f nginx 0.1.14
Igor Sysoev <http://sysoev.ru>
parents: 22
diff changeset
564 && bsize + cl->buf->last - cl->buf->pos > p->busy_size)
7ca9bdc82b3f nginx 0.1.14
Igor Sysoev <http://sysoev.ru>
parents: 22
diff changeset
565 {
276
c5c2b2883984 nginx 0.5.8
Igor Sysoev <http://sysoev.ru>
parents: 274
diff changeset
566 if (!prev_last_shadow) {
c5c2b2883984 nginx 0.5.8
Igor Sysoev <http://sysoev.ru>
parents: 274
diff changeset
567 p->in = p->in->next;
c5c2b2883984 nginx 0.5.8
Igor Sysoev <http://sysoev.ru>
parents: 274
diff changeset
568
c5c2b2883984 nginx 0.5.8
Igor Sysoev <http://sysoev.ru>
parents: 274
diff changeset
569 cl->next = NULL;
c5c2b2883984 nginx 0.5.8
Igor Sysoev <http://sysoev.ru>
parents: 274
diff changeset
570
c5c2b2883984 nginx 0.5.8
Igor Sysoev <http://sysoev.ru>
parents: 274
diff changeset
571 if (out) {
c5c2b2883984 nginx 0.5.8
Igor Sysoev <http://sysoev.ru>
parents: 274
diff changeset
572 *ll = cl;
c5c2b2883984 nginx 0.5.8
Igor Sysoev <http://sysoev.ru>
parents: 274
diff changeset
573 } else {
c5c2b2883984 nginx 0.5.8
Igor Sysoev <http://sysoev.ru>
parents: 274
diff changeset
574 out = cl;
c5c2b2883984 nginx 0.5.8
Igor Sysoev <http://sysoev.ru>
parents: 274
diff changeset
575 }
c5c2b2883984 nginx 0.5.8
Igor Sysoev <http://sysoev.ru>
parents: 274
diff changeset
576 }
c5c2b2883984 nginx 0.5.8
Igor Sysoev <http://sysoev.ru>
parents: 274
diff changeset
577
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
578 flush = 1;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
579 break;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
580 }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
581
276
c5c2b2883984 nginx 0.5.8
Igor Sysoev <http://sysoev.ru>
parents: 274
diff changeset
582 prev_last_shadow = cl->buf->last_shadow;
c5c2b2883984 nginx 0.5.8
Igor Sysoev <http://sysoev.ru>
parents: 274
diff changeset
583
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
584 p->in = p->in->next;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
585
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
586 } else {
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
587 break;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
588 }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
589
28
7ca9bdc82b3f nginx 0.1.14
Igor Sysoev <http://sysoev.ru>
parents: 22
diff changeset
590 if (cl->buf->recycled) {
7ca9bdc82b3f nginx 0.1.14
Igor Sysoev <http://sysoev.ru>
parents: 22
diff changeset
591 bsize += cl->buf->last - cl->buf->pos;
7ca9bdc82b3f nginx 0.1.14
Igor Sysoev <http://sysoev.ru>
parents: 22
diff changeset
592 }
7ca9bdc82b3f nginx 0.1.14
Igor Sysoev <http://sysoev.ru>
parents: 22
diff changeset
593
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
594 cl->next = NULL;
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents: 32
diff changeset
595
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents: 32
diff changeset
596 if (out) {
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents: 32
diff changeset
597 *ll = cl;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents: 32
diff changeset
598 } else {
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents: 32
diff changeset
599 out = cl;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents: 32
diff changeset
600 }
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents: 32
diff changeset
601 ll = &cl->next;
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
602 }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
603
284
3dbecd747fbb nginx 0.5.12
Igor Sysoev <http://sysoev.ru>
parents: 276
diff changeset
604 flush:
3dbecd747fbb nginx 0.5.12
Igor Sysoev <http://sysoev.ru>
parents: 276
diff changeset
605
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
606 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, p->log, 0,
10
46833bd150cb nginx 0.1.5
Igor Sysoev <http://sysoev.ru>
parents: 6
diff changeset
607 "pipe write: out:%p, f:%d", out, flush);
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
608
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
609 if (out == NULL && !flush) {
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
610 break;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
611 }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
612
346
05693816539c nginx 0.6.17
Igor Sysoev <http://sysoev.ru>
parents: 344
diff changeset
613 rc = p->output_filter(p->output_ctx, out);
05693816539c nginx 0.6.17
Igor Sysoev <http://sysoev.ru>
parents: 344
diff changeset
614
05693816539c nginx 0.6.17
Igor Sysoev <http://sysoev.ru>
parents: 344
diff changeset
615 if (downstream->destroyed) {
05693816539c nginx 0.6.17
Igor Sysoev <http://sysoev.ru>
parents: 344
diff changeset
616 return NGX_ABORT;
05693816539c nginx 0.6.17
Igor Sysoev <http://sysoev.ru>
parents: 344
diff changeset
617 }
05693816539c nginx 0.6.17
Igor Sysoev <http://sysoev.ru>
parents: 344
diff changeset
618
05693816539c nginx 0.6.17
Igor Sysoev <http://sysoev.ru>
parents: 344
diff changeset
619 if (rc == NGX_ERROR) {
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
620 p->downstream_error = 1;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
621 return ngx_event_pipe_drain_chains(p);
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
622 }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
623
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
624 ngx_chain_update_chains(&p->free, &p->busy, &out, p->tag);
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
625
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
626 for (cl = p->free; cl; cl = cl->next) {
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
627
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
628 if (cl->buf->temp_file) {
340
10cc350ed8a1 nginx 0.6.14
Igor Sysoev <http://sysoev.ru>
parents: 284
diff changeset
629 if (p->cacheable || !p->cyclic_temp_file) {
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
630 continue;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
631 }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
632
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
633 /* reset p->temp_offset if all bufs had been sent */
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
634
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
635 if (cl->buf->file_last == p->temp_file->offset) {
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
636 p->temp_file->offset = 0;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
637 }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
638 }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
639
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
640 /* TODO: free buf if p->free_bufs && upstream done */
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
641
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
642 /* add the free shadow raw buf to p->free_raw_bufs */
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
643
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
644 if (cl->buf->last_shadow) {
32
da8c190bdaba nginx 0.1.16
Igor Sysoev <http://sysoev.ru>
parents: 28
diff changeset
645 if (ngx_event_pipe_add_free_buf(p, cl->buf->shadow) != NGX_OK) {
da8c190bdaba nginx 0.1.16
Igor Sysoev <http://sysoev.ru>
parents: 28
diff changeset
646 return NGX_ABORT;
da8c190bdaba nginx 0.1.16
Igor Sysoev <http://sysoev.ru>
parents: 28
diff changeset
647 }
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
648
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
649 cl->buf->last_shadow = 0;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
650 }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
651
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
652 cl->buf->shadow = NULL;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
653 }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
654 }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
655
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
656 return NGX_OK;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
657 }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
658
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
659
126
df17fbafec8f nginx 0.3.10
Igor Sysoev <http://sysoev.ru>
parents: 76
diff changeset
660 static ngx_int_t
df17fbafec8f nginx 0.3.10
Igor Sysoev <http://sysoev.ru>
parents: 76
diff changeset
661 ngx_event_pipe_write_chain_to_temp_file(ngx_event_pipe_t *p)
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
662 {
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
663 ssize_t size, bsize;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
664 ngx_buf_t *b;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
665 ngx_chain_t *cl, *tl, *next, *out, **ll, **last_free, fl;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
666
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
667 if (p->buf_to_file) {
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
668 fl.buf = p->buf_to_file;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
669 fl.next = p->in;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
670 out = &fl;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
671
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
672 } else {
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
673 out = p->in;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
674 }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
675
340
10cc350ed8a1 nginx 0.6.14
Igor Sysoev <http://sysoev.ru>
parents: 284
diff changeset
676 if (!p->cacheable) {
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
677
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
678 size = 0;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
679 cl = out;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
680 ll = NULL;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
681
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
682 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, p->log, 0,
10
46833bd150cb nginx 0.1.5
Igor Sysoev <http://sysoev.ru>
parents: 6
diff changeset
683 "pipe offset: %O", p->temp_file->offset);
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
684
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
685 do {
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
686 bsize = cl->buf->last - cl->buf->pos;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
687
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
688 ngx_log_debug3(NGX_LOG_DEBUG_EVENT, p->log, 0,
10
46833bd150cb nginx 0.1.5
Igor Sysoev <http://sysoev.ru>
parents: 6
diff changeset
689 "pipe buf %p, pos %p, size: %z",
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
690 cl->buf->start, cl->buf->pos, bsize);
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
691
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
692 if ((size + bsize > p->temp_file_write_size)
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
693 || (p->temp_file->offset + size + bsize > p->max_temp_file_size))
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
694 {
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
695 break;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
696 }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
697
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
698 size += bsize;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
699 ll = &cl->next;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
700 cl = cl->next;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
701
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
702 } while (cl);
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
703
10
46833bd150cb nginx 0.1.5
Igor Sysoev <http://sysoev.ru>
parents: 6
diff changeset
704 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, p->log, 0, "size: %z", size);
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
705
70
8ad297c88dcb nginx 0.1.35
Igor Sysoev <http://sysoev.ru>
parents: 58
diff changeset
706 if (ll == NULL) {
8ad297c88dcb nginx 0.1.35
Igor Sysoev <http://sysoev.ru>
parents: 58
diff changeset
707 return NGX_BUSY;
8ad297c88dcb nginx 0.1.35
Igor Sysoev <http://sysoev.ru>
parents: 58
diff changeset
708 }
8ad297c88dcb nginx 0.1.35
Igor Sysoev <http://sysoev.ru>
parents: 58
diff changeset
709
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
710 if (cl) {
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
711 p->in = cl;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
712 *ll = NULL;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
713
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
714 } else {
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
715 p->in = NULL;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
716 p->last_in = &p->in;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
717 }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
718
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
719 } else {
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
720 p->in = NULL;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
721 p->last_in = &p->in;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
722 }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
723
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
724 if (ngx_write_chain_to_temp_file(p->temp_file, out) == NGX_ERROR) {
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
725 return NGX_ABORT;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
726 }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
727
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
728 for (last_free = &p->free_raw_bufs;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
729 *last_free != NULL;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
730 last_free = &(*last_free)->next)
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
731 {
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
732 /* void */
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
733 }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
734
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
735 if (p->buf_to_file) {
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
736 p->temp_file->offset = p->buf_to_file->last - p->buf_to_file->pos;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
737 p->buf_to_file = NULL;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
738 out = out->next;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
739 }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
740
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
741 for (cl = out; cl; cl = next) {
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
742 next = cl->next;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
743 cl->next = NULL;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
744
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
745 b = cl->buf;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
746 b->file = &p->temp_file->file;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
747 b->file_pos = p->temp_file->offset;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
748 p->temp_file->offset += b->last - b->pos;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
749 b->file_last = p->temp_file->offset;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
750
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
751 b->in_file = 1;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
752 b->temp_file = 1;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
753
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents: 32
diff changeset
754 if (p->out) {
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents: 32
diff changeset
755 *p->last_out = cl;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents: 32
diff changeset
756 } else {
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents: 32
diff changeset
757 p->out = cl;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents: 32
diff changeset
758 }
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents: 32
diff changeset
759 p->last_out = &cl->next;
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
760
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
761 if (b->last_shadow) {
32
da8c190bdaba nginx 0.1.16
Igor Sysoev <http://sysoev.ru>
parents: 28
diff changeset
762
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents: 32
diff changeset
763 tl = ngx_alloc_chain_link(p->pool);
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents: 32
diff changeset
764 if (tl == NULL) {
32
da8c190bdaba nginx 0.1.16
Igor Sysoev <http://sysoev.ru>
parents: 28
diff changeset
765 return NGX_ABORT;
da8c190bdaba nginx 0.1.16
Igor Sysoev <http://sysoev.ru>
parents: 28
diff changeset
766 }
da8c190bdaba nginx 0.1.16
Igor Sysoev <http://sysoev.ru>
parents: 28
diff changeset
767
da8c190bdaba nginx 0.1.16
Igor Sysoev <http://sysoev.ru>
parents: 28
diff changeset
768 tl->buf = b->shadow;
da8c190bdaba nginx 0.1.16
Igor Sysoev <http://sysoev.ru>
parents: 28
diff changeset
769 tl->next = NULL;
da8c190bdaba nginx 0.1.16
Igor Sysoev <http://sysoev.ru>
parents: 28
diff changeset
770
da8c190bdaba nginx 0.1.16
Igor Sysoev <http://sysoev.ru>
parents: 28
diff changeset
771 *last_free = tl;
da8c190bdaba nginx 0.1.16
Igor Sysoev <http://sysoev.ru>
parents: 28
diff changeset
772 last_free = &tl->next;
da8c190bdaba nginx 0.1.16
Igor Sysoev <http://sysoev.ru>
parents: 28
diff changeset
773
2
cc9f381affaa nginx 0.1.1
Igor Sysoev <http://sysoev.ru>
parents: 0
diff changeset
774 b->shadow->pos = b->shadow->start;
cc9f381affaa nginx 0.1.1
Igor Sysoev <http://sysoev.ru>
parents: 0
diff changeset
775 b->shadow->last = b->shadow->start;
cc9f381affaa nginx 0.1.1
Igor Sysoev <http://sysoev.ru>
parents: 0
diff changeset
776
32
da8c190bdaba nginx 0.1.16
Igor Sysoev <http://sysoev.ru>
parents: 28
diff changeset
777 ngx_event_pipe_remove_shadow_links(b->shadow);
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
778 }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
779 }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
780
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
781 return NGX_OK;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
782 }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
783
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
784
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
785 /* the copy input filter */
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
786
126
df17fbafec8f nginx 0.3.10
Igor Sysoev <http://sysoev.ru>
parents: 76
diff changeset
787 ngx_int_t
df17fbafec8f nginx 0.3.10
Igor Sysoev <http://sysoev.ru>
parents: 76
diff changeset
788 ngx_event_pipe_copy_input_filter(ngx_event_pipe_t *p, ngx_buf_t *buf)
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
789 {
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
790 ngx_buf_t *b;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
791 ngx_chain_t *cl;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
792
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
793 if (buf->pos == buf->last) {
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
794 return NGX_OK;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
795 }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
796
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
797 if (p->free) {
56
3050baa54a26 nginx 0.1.28
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
798 cl = p->free;
3050baa54a26 nginx 0.1.28
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
799 b = cl->buf;
3050baa54a26 nginx 0.1.28
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
800 p->free = cl->next;
3050baa54a26 nginx 0.1.28
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
801 ngx_free_chain(p->pool, cl);
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
802
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
803 } else {
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents: 32
diff changeset
804 b = ngx_alloc_buf(p->pool);
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents: 32
diff changeset
805 if (b == NULL) {
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
806 return NGX_ERROR;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
807 }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
808 }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
809
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
810 ngx_memcpy(b, buf, sizeof(ngx_buf_t));
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
811 b->shadow = buf;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
812 b->tag = p->tag;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
813 b->last_shadow = 1;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
814 b->recycled = 1;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
815 buf->shadow = b;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
816
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents: 32
diff changeset
817 cl = ngx_alloc_chain_link(p->pool);
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents: 32
diff changeset
818 if (cl == NULL) {
32
da8c190bdaba nginx 0.1.16
Igor Sysoev <http://sysoev.ru>
parents: 28
diff changeset
819 return NGX_ERROR;
da8c190bdaba nginx 0.1.16
Igor Sysoev <http://sysoev.ru>
parents: 28
diff changeset
820 }
da8c190bdaba nginx 0.1.16
Igor Sysoev <http://sysoev.ru>
parents: 28
diff changeset
821
da8c190bdaba nginx 0.1.16
Igor Sysoev <http://sysoev.ru>
parents: 28
diff changeset
822 cl->buf = b;
da8c190bdaba nginx 0.1.16
Igor Sysoev <http://sysoev.ru>
parents: 28
diff changeset
823 cl->next = NULL;
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
824
28
7ca9bdc82b3f nginx 0.1.14
Igor Sysoev <http://sysoev.ru>
parents: 22
diff changeset
825 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, p->log, 0, "input buf #%d", b->num);
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
826
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents: 32
diff changeset
827 if (p->in) {
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents: 32
diff changeset
828 *p->last_in = cl;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents: 32
diff changeset
829 } else {
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents: 32
diff changeset
830 p->in = cl;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents: 32
diff changeset
831 }
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents: 32
diff changeset
832 p->last_in = &cl->next;
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
833
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
834 return NGX_OK;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
835 }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
836
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
837
126
df17fbafec8f nginx 0.3.10
Igor Sysoev <http://sysoev.ru>
parents: 76
diff changeset
838 static ngx_inline void
df17fbafec8f nginx 0.3.10
Igor Sysoev <http://sysoev.ru>
parents: 76
diff changeset
839 ngx_event_pipe_remove_shadow_links(ngx_buf_t *buf)
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
840 {
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
841 ngx_buf_t *b, *next;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
842
2
cc9f381affaa nginx 0.1.1
Igor Sysoev <http://sysoev.ru>
parents: 0
diff changeset
843 b = buf->shadow;
cc9f381affaa nginx 0.1.1
Igor Sysoev <http://sysoev.ru>
parents: 0
diff changeset
844
cc9f381affaa nginx 0.1.1
Igor Sysoev <http://sysoev.ru>
parents: 0
diff changeset
845 if (b == NULL) {
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
846 return;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
847 }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
848
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
849 while (!b->last_shadow) {
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
850 next = b->shadow;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
851
2
cc9f381affaa nginx 0.1.1
Igor Sysoev <http://sysoev.ru>
parents: 0
diff changeset
852 b->temporary = 0;
cc9f381affaa nginx 0.1.1
Igor Sysoev <http://sysoev.ru>
parents: 0
diff changeset
853 b->recycled = 0;
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
854
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
855 b->shadow = NULL;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
856 b = next;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
857 }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
858
2
cc9f381affaa nginx 0.1.1
Igor Sysoev <http://sysoev.ru>
parents: 0
diff changeset
859 b->temporary = 0;
cc9f381affaa nginx 0.1.1
Igor Sysoev <http://sysoev.ru>
parents: 0
diff changeset
860 b->recycled = 0;
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
861 b->last_shadow = 0;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
862
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
863 b->shadow = NULL;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
864
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
865 buf->shadow = NULL;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
866 }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
867
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
868
126
df17fbafec8f nginx 0.3.10
Igor Sysoev <http://sysoev.ru>
parents: 76
diff changeset
869 static ngx_inline void
df17fbafec8f nginx 0.3.10
Igor Sysoev <http://sysoev.ru>
parents: 76
diff changeset
870 ngx_event_pipe_free_shadow_raw_buf(ngx_chain_t **free, ngx_buf_t *buf)
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
871 {
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
872 ngx_buf_t *s;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
873 ngx_chain_t *cl, **ll;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
874
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
875 if (buf->shadow == NULL) {
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
876 return;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
877 }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
878
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
879 for (s = buf->shadow; !s->last_shadow; s = s->shadow) { /* void */ }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
880
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
881 ll = free;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
882
376
d13234035cad nginx 0.6.32
Igor Sysoev <http://sysoev.ru>
parents: 346
diff changeset
883 for (cl = *free; cl; cl = cl->next) {
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
884 if (cl->buf == s) {
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
885 *ll = cl->next;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
886 break;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
887 }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
888
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
889 if (cl->buf->shadow) {
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
890 break;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
891 }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
892
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
893 ll = &cl->next;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
894 }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
895 }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
896
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
897
126
df17fbafec8f nginx 0.3.10
Igor Sysoev <http://sysoev.ru>
parents: 76
diff changeset
898 ngx_int_t
df17fbafec8f nginx 0.3.10
Igor Sysoev <http://sysoev.ru>
parents: 76
diff changeset
899 ngx_event_pipe_add_free_buf(ngx_event_pipe_t *p, ngx_buf_t *b)
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
900 {
32
da8c190bdaba nginx 0.1.16
Igor Sysoev <http://sysoev.ru>
parents: 28
diff changeset
901 ngx_chain_t *cl;
da8c190bdaba nginx 0.1.16
Igor Sysoev <http://sysoev.ru>
parents: 28
diff changeset
902
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents: 32
diff changeset
903 cl = ngx_alloc_chain_link(p->pool);
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents: 32
diff changeset
904 if (cl == NULL) {
32
da8c190bdaba nginx 0.1.16
Igor Sysoev <http://sysoev.ru>
parents: 28
diff changeset
905 return NGX_ERROR;
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
906 }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
907
32
da8c190bdaba nginx 0.1.16
Igor Sysoev <http://sysoev.ru>
parents: 28
diff changeset
908 b->pos = b->start;
da8c190bdaba nginx 0.1.16
Igor Sysoev <http://sysoev.ru>
parents: 28
diff changeset
909 b->last = b->start;
da8c190bdaba nginx 0.1.16
Igor Sysoev <http://sysoev.ru>
parents: 28
diff changeset
910 b->shadow = NULL;
da8c190bdaba nginx 0.1.16
Igor Sysoev <http://sysoev.ru>
parents: 28
diff changeset
911
da8c190bdaba nginx 0.1.16
Igor Sysoev <http://sysoev.ru>
parents: 28
diff changeset
912 cl->buf = b;
da8c190bdaba nginx 0.1.16
Igor Sysoev <http://sysoev.ru>
parents: 28
diff changeset
913
da8c190bdaba nginx 0.1.16
Igor Sysoev <http://sysoev.ru>
parents: 28
diff changeset
914 if (p->free_raw_bufs == NULL) {
da8c190bdaba nginx 0.1.16
Igor Sysoev <http://sysoev.ru>
parents: 28
diff changeset
915 p->free_raw_bufs = cl;
da8c190bdaba nginx 0.1.16
Igor Sysoev <http://sysoev.ru>
parents: 28
diff changeset
916 cl->next = NULL;
da8c190bdaba nginx 0.1.16
Igor Sysoev <http://sysoev.ru>
parents: 28
diff changeset
917
da8c190bdaba nginx 0.1.16
Igor Sysoev <http://sysoev.ru>
parents: 28
diff changeset
918 return NGX_OK;
da8c190bdaba nginx 0.1.16
Igor Sysoev <http://sysoev.ru>
parents: 28
diff changeset
919 }
da8c190bdaba nginx 0.1.16
Igor Sysoev <http://sysoev.ru>
parents: 28
diff changeset
920
da8c190bdaba nginx 0.1.16
Igor Sysoev <http://sysoev.ru>
parents: 28
diff changeset
921 if (p->free_raw_bufs->buf->pos == p->free_raw_bufs->buf->last) {
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
922
32
da8c190bdaba nginx 0.1.16
Igor Sysoev <http://sysoev.ru>
parents: 28
diff changeset
923 /* add the free buf to the list start */
da8c190bdaba nginx 0.1.16
Igor Sysoev <http://sysoev.ru>
parents: 28
diff changeset
924
da8c190bdaba nginx 0.1.16
Igor Sysoev <http://sysoev.ru>
parents: 28
diff changeset
925 cl->next = p->free_raw_bufs;
da8c190bdaba nginx 0.1.16
Igor Sysoev <http://sysoev.ru>
parents: 28
diff changeset
926 p->free_raw_bufs = cl;
da8c190bdaba nginx 0.1.16
Igor Sysoev <http://sysoev.ru>
parents: 28
diff changeset
927
da8c190bdaba nginx 0.1.16
Igor Sysoev <http://sysoev.ru>
parents: 28
diff changeset
928 return NGX_OK;
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
929 }
32
da8c190bdaba nginx 0.1.16
Igor Sysoev <http://sysoev.ru>
parents: 28
diff changeset
930
da8c190bdaba nginx 0.1.16
Igor Sysoev <http://sysoev.ru>
parents: 28
diff changeset
931 /* the first free buf is partialy filled, thus add the free buf after it */
da8c190bdaba nginx 0.1.16
Igor Sysoev <http://sysoev.ru>
parents: 28
diff changeset
932
da8c190bdaba nginx 0.1.16
Igor Sysoev <http://sysoev.ru>
parents: 28
diff changeset
933 cl->next = p->free_raw_bufs->next;
da8c190bdaba nginx 0.1.16
Igor Sysoev <http://sysoev.ru>
parents: 28
diff changeset
934 p->free_raw_bufs->next = cl;
da8c190bdaba nginx 0.1.16
Igor Sysoev <http://sysoev.ru>
parents: 28
diff changeset
935
da8c190bdaba nginx 0.1.16
Igor Sysoev <http://sysoev.ru>
parents: 28
diff changeset
936 return NGX_OK;
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
937 }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
938
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
939
126
df17fbafec8f nginx 0.3.10
Igor Sysoev <http://sysoev.ru>
parents: 76
diff changeset
940 static ngx_int_t
df17fbafec8f nginx 0.3.10
Igor Sysoev <http://sysoev.ru>
parents: 76
diff changeset
941 ngx_event_pipe_drain_chains(ngx_event_pipe_t *p)
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
942 {
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
943 ngx_chain_t *cl, *tl;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
944
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
945 for ( ;; ) {
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
946 if (p->busy) {
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
947 cl = p->busy;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
948 p->busy = NULL;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
949
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
950 } else if (p->out) {
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
951 cl = p->out;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
952 p->out = NULL;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
953
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
954 } else if (p->in) {
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
955 cl = p->in;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
956 p->in = NULL;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
957
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
958 } else {
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
959 return NGX_OK;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
960 }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
961
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
962 while (cl) {
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
963 if (cl->buf->last_shadow) {
32
da8c190bdaba nginx 0.1.16
Igor Sysoev <http://sysoev.ru>
parents: 28
diff changeset
964 if (ngx_event_pipe_add_free_buf(p, cl->buf->shadow) != NGX_OK) {
28
7ca9bdc82b3f nginx 0.1.14
Igor Sysoev <http://sysoev.ru>
parents: 22
diff changeset
965 return NGX_ABORT;
7ca9bdc82b3f nginx 0.1.14
Igor Sysoev <http://sysoev.ru>
parents: 22
diff changeset
966 }
7ca9bdc82b3f nginx 0.1.14
Igor Sysoev <http://sysoev.ru>
parents: 22
diff changeset
967
0
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
968 cl->buf->last_shadow = 0;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
969 }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
970
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
971 cl->buf->shadow = NULL;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
972 tl = cl->next;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
973 cl->next = p->free;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
974 p->free = cl;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
975 cl = tl;
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
976 }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
977 }
f0b350454894 nginx 0.1.0
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
978 }