Mercurial > hg > nginx
comparison src/stream/ngx_stream_core_module.c @ 6693:3908156a51fa
Stream: phases.
author | Roman Arutyunyan <arut@nginx.com> |
---|---|
date | Thu, 15 Sep 2016 14:55:54 +0300 |
parents | 4a16fceea03b |
children | ea9dfe2f62e7 |
comparison
equal
deleted
inserted
replaced
6692:56fc55e32f23 | 6693:3908156a51fa |
---|---|
121 NULL, /* exit master */ | 121 NULL, /* exit master */ |
122 NGX_MODULE_V1_PADDING | 122 NGX_MODULE_V1_PADDING |
123 }; | 123 }; |
124 | 124 |
125 | 125 |
126 void | |
127 ngx_stream_core_run_phases(ngx_stream_session_t *s) | |
128 { | |
129 ngx_int_t rc; | |
130 ngx_stream_phase_handler_t *ph; | |
131 ngx_stream_core_main_conf_t *cmcf; | |
132 | |
133 cmcf = ngx_stream_get_module_main_conf(s, ngx_stream_core_module); | |
134 | |
135 ph = cmcf->phase_engine.handlers; | |
136 | |
137 while (ph[s->phase_handler].checker) { | |
138 | |
139 rc = ph[s->phase_handler].checker(s, &ph[s->phase_handler]); | |
140 | |
141 if (rc == NGX_OK) { | |
142 return; | |
143 } | |
144 } | |
145 } | |
146 | |
147 | |
148 ngx_int_t | |
149 ngx_stream_core_generic_phase(ngx_stream_session_t *s, | |
150 ngx_stream_phase_handler_t *ph) | |
151 { | |
152 ngx_int_t rc; | |
153 | |
154 /* | |
155 * generic phase checker, | |
156 * used by all phases, except for content | |
157 */ | |
158 | |
159 ngx_log_debug1(NGX_LOG_DEBUG_STREAM, s->connection->log, 0, | |
160 "generic phase: %ui", s->phase_handler); | |
161 | |
162 rc = ph->handler(s); | |
163 | |
164 if (rc == NGX_OK) { | |
165 s->phase_handler = ph->next; | |
166 return NGX_AGAIN; | |
167 } | |
168 | |
169 if (rc == NGX_DECLINED) { | |
170 s->phase_handler++; | |
171 return NGX_AGAIN; | |
172 } | |
173 | |
174 if (rc == NGX_AGAIN || rc == NGX_DONE) { | |
175 return NGX_OK; | |
176 } | |
177 | |
178 if (rc == NGX_ERROR) { | |
179 rc = NGX_STREAM_INTERNAL_SERVER_ERROR; | |
180 } | |
181 | |
182 ngx_stream_finalize_session(s, rc); | |
183 | |
184 return NGX_OK; | |
185 } | |
186 | |
187 | |
188 ngx_int_t | |
189 ngx_stream_core_content_phase(ngx_stream_session_t *s, | |
190 ngx_stream_phase_handler_t *ph) | |
191 { | |
192 int tcp_nodelay; | |
193 ngx_connection_t *c; | |
194 ngx_stream_core_srv_conf_t *cscf; | |
195 | |
196 c = s->connection; | |
197 | |
198 c->log->action = NULL; | |
199 | |
200 cscf = ngx_stream_get_module_srv_conf(s, ngx_stream_core_module); | |
201 | |
202 if (c->type == SOCK_STREAM | |
203 && cscf->tcp_nodelay | |
204 && c->tcp_nodelay == NGX_TCP_NODELAY_UNSET) | |
205 { | |
206 ngx_log_debug0(NGX_LOG_DEBUG_STREAM, c->log, 0, "tcp_nodelay"); | |
207 | |
208 tcp_nodelay = 1; | |
209 | |
210 if (setsockopt(c->fd, IPPROTO_TCP, TCP_NODELAY, | |
211 (const void *) &tcp_nodelay, sizeof(int)) == -1) | |
212 { | |
213 ngx_connection_error(c, ngx_socket_errno, | |
214 "setsockopt(TCP_NODELAY) failed"); | |
215 ngx_stream_finalize_session(s, NGX_STREAM_INTERNAL_SERVER_ERROR); | |
216 return NGX_OK; | |
217 } | |
218 | |
219 c->tcp_nodelay = NGX_TCP_NODELAY_SET; | |
220 } | |
221 | |
222 cscf->handler(s); | |
223 | |
224 return NGX_OK; | |
225 } | |
226 | |
227 | |
126 static ngx_int_t | 228 static ngx_int_t |
127 ngx_stream_core_preconfiguration(ngx_conf_t *cf) | 229 ngx_stream_core_preconfiguration(ngx_conf_t *cf) |
128 { | 230 { |
129 return ngx_stream_variables_add_core_vars(cf); | 231 return ngx_stream_variables_add_core_vars(cf); |
130 } | 232 } |