comparison src/http/ngx_http_request.c @ 116:e38f51cd0905 NGINX_0_3_5

nginx 0.3.5 *) Bugfix: the segmentation fault may occurred if the IMAP/POP3 login was changed by authorization server; bug appeared in 0.2.2. *) Bugfix: the accept mutex did not work and all connections were handled by one process; bug appeared in 0.3.3. *) Bugfix: the timeout did not work if the "rtsig" method and the "timer_resolution" directive were used.
author Igor Sysoev <http://sysoev.ru>
date Fri, 21 Oct 2005 00:00:00 +0400
parents 408f195b3482
children 644a7935144b
comparison
equal deleted inserted replaced
115:45a230988aa5 116:e38f51cd0905
157 rev = c->read; 157 rev = c->read;
158 rev->handler = ngx_http_init_request; 158 rev->handler = ngx_http_init_request;
159 159
160 /* STUB: epoll edge */ c->write->handler = ngx_http_empty_handler; 160 /* STUB: epoll edge */ c->write->handler = ngx_http_empty_handler;
161 161
162 if (rev->ready) {
163 /* the deferred accept(), rtsig, aio, iocp */
164
165 if (ngx_accept_mutex) {
166
167 ngx_post_event(rev, &ngx_posted_events);
168
169 #if (NGX_STAT_STUB)
170 ngx_atomic_fetch_add(ngx_stat_reading, 1);
171 #endif
172 return;
173 }
174
175 #if (NGX_STAT_STUB)
176 ngx_atomic_fetch_add(ngx_stat_reading, 1);
177 #endif
178
179 ngx_http_init_request(rev);
180 return;
181 }
182
183 ngx_add_timer(rev, c->listening->post_accept_timeout);
184
185 if (ngx_handle_read_event(rev, 0) == NGX_ERROR) {
186 ngx_http_close_connection(c);
187 return;
188 }
189
190 #if (NGX_STAT_STUB) 162 #if (NGX_STAT_STUB)
191 ngx_atomic_fetch_add(ngx_stat_reading, 1); 163 ngx_atomic_fetch_add(ngx_stat_reading, 1);
192 #endif 164 #endif
193 165
166 if (rev->ready) {
167 /* the deferred accept(), rtsig, aio, iocp */
168
169 if (ngx_accept_mutex) {
170 ngx_post_event(rev, &ngx_posted_events);
171 return;
172 }
173
174 ngx_http_init_request(rev);
175 return;
176 }
177
178 ngx_add_timer(rev, c->listening->post_accept_timeout);
179
180 if (ngx_handle_read_event(rev, 0) == NGX_ERROR) {
181 #if (NGX_STAT_STUB)
182 ngx_atomic_fetch_add(ngx_stat_reading, -1);
183 #endif
184 ngx_http_close_connection(c);
185 return;
186 }
194 } 187 }
195 188
196 189
197 static 190 static
198 void ngx_http_init_request(ngx_event_t *rev) 191 void ngx_http_init_request(ngx_event_t *rev)
211 ngx_http_core_loc_conf_t *clcf; 204 ngx_http_core_loc_conf_t *clcf;
212 #if (NGX_HTTP_SSL) 205 #if (NGX_HTTP_SSL)
213 ngx_http_ssl_srv_conf_t *sscf; 206 ngx_http_ssl_srv_conf_t *sscf;
214 #endif 207 #endif
215 208
209 #if (NGX_STAT_STUB)
210 ngx_atomic_fetch_add(ngx_stat_reading, -1);
211 #endif
212
216 c = rev->data; 213 c = rev->data;
217 214
218 if (rev->timedout) { 215 if (rev->timedout) {
219 ngx_log_error(NGX_LOG_INFO, c->log, NGX_ETIMEDOUT, "client timed out"); 216 ngx_log_error(NGX_LOG_INFO, c->log, NGX_ETIMEDOUT, "client timed out");
220 217
221 #if (NGX_STAT_STUB)
222 ngx_atomic_fetch_add(ngx_stat_reading, -1);
223 #endif
224
225 ngx_http_close_connection(c); 218 ngx_http_close_connection(c);
226 return; 219 return;
227 } 220 }
228 221
229 hc = c->data; 222 hc = c->data;
230 223
231 if (hc) { 224 if (hc == NULL) {
232
233 #if (NGX_STAT_STUB)
234 ngx_atomic_fetch_add(ngx_stat_reading, 1);
235 #endif
236
237 } else {
238 hc = ngx_pcalloc(c->pool, sizeof(ngx_http_connection_t)); 225 hc = ngx_pcalloc(c->pool, sizeof(ngx_http_connection_t));
239 if (hc == NULL) { 226 if (hc == NULL) {
240
241 #if (NGX_STAT_STUB)
242 ngx_atomic_fetch_add(ngx_stat_reading, -1);
243 #endif
244
245 ngx_http_close_connection(c); 227 ngx_http_close_connection(c);
246 return; 228 return;
247 } 229 }
248 } 230 }
249 231
259 } 241 }
260 242
261 } else { 243 } else {
262 r = ngx_pcalloc(c->pool, sizeof(ngx_http_request_t)); 244 r = ngx_pcalloc(c->pool, sizeof(ngx_http_request_t));
263 if (r == NULL) { 245 if (r == NULL) {
264
265 #if (NGX_STAT_STUB)
266 ngx_atomic_fetch_add(ngx_stat_reading, -1);
267 #endif
268
269 ngx_http_close_connection(c); 246 ngx_http_close_connection(c);
270 return; 247 return;
271 } 248 }
272 249
273 hc->request = r; 250 hc->request = r;
274 } 251 }
275
276 #if (NGX_STAT_STUB)
277 ngx_atomic_fetch_add(ngx_stat_reading, -1);
278 #endif
279 252
280 c->data = r; 253 c->data = r;
281 r->http_connection = hc; 254 r->http_connection = hc;
282 255
283 c->sent = 0; 256 c->sent = 0;
1650 if (wev->timedout) { 1623 if (wev->timedout) {
1651 if (!wev->delayed) { 1624 if (!wev->delayed) {
1652 ngx_log_error(NGX_LOG_INFO, c->log, NGX_ETIMEDOUT, 1625 ngx_log_error(NGX_LOG_INFO, c->log, NGX_ETIMEDOUT,
1653 "client timed out"); 1626 "client timed out");
1654 c->timedout = 1; 1627 c->timedout = 1;
1655 ngx_http_close_request(r, NGX_HTTP_REQUEST_TIME_OUT); 1628
1629 #if 0
1630 ngx_http_close_request(r->main, NGX_HTTP_REQUEST_TIME_OUT);
1656 ngx_http_close_connection(c); 1631 ngx_http_close_connection(c);
1632 #endif
1633
1634 c->closed = 1;
1635 ngx_http_finalize_request(r, 0);
1636
1657 return; 1637 return;
1658 } 1638 }
1659 1639
1660 wev->timedout = 0; 1640 wev->timedout = 0;
1661 wev->delayed = 0; 1641 wev->delayed = 0;
1663 if (!wev->ready) { 1643 if (!wev->ready) {
1664 clcf = ngx_http_get_module_loc_conf(r->main, ngx_http_core_module); 1644 clcf = ngx_http_get_module_loc_conf(r->main, ngx_http_core_module);
1665 ngx_add_timer(wev, clcf->send_timeout); 1645 ngx_add_timer(wev, clcf->send_timeout);
1666 1646
1667 if (ngx_handle_write_event(wev, clcf->send_lowat) == NGX_ERROR) { 1647 if (ngx_handle_write_event(wev, clcf->send_lowat) == NGX_ERROR) {
1668 ngx_http_close_request(r, 0); 1648 ngx_http_close_request(r->main, 0);
1669 ngx_http_close_connection(r->connection); 1649 ngx_http_close_connection(r->connection);
1670 } 1650 }
1671 1651
1672 return; 1652 return;
1673 } 1653 }
1678 "http writer delayed"); 1658 "http writer delayed");
1679 1659
1680 clcf = ngx_http_get_module_loc_conf(r->main, ngx_http_core_module); 1660 clcf = ngx_http_get_module_loc_conf(r->main, ngx_http_core_module);
1681 1661
1682 if (ngx_handle_write_event(wev, clcf->send_lowat) == NGX_ERROR) { 1662 if (ngx_handle_write_event(wev, clcf->send_lowat) == NGX_ERROR) {
1683 ngx_http_close_request(r, 0); 1663 ngx_http_close_request(r->main, 0);
1684 ngx_http_close_connection(r->connection); 1664 ngx_http_close_connection(r->connection);
1685 } 1665 }
1686 1666
1687 return; 1667 return;
1688 } 1668 }
1709 if (!wev->ready && !wev->delayed) { 1689 if (!wev->ready && !wev->delayed) {
1710 ngx_add_timer(wev, clcf->send_timeout); 1690 ngx_add_timer(wev, clcf->send_timeout);
1711 } 1691 }
1712 1692
1713 if (ngx_handle_write_event(wev, clcf->send_lowat) == NGX_ERROR) { 1693 if (ngx_handle_write_event(wev, clcf->send_lowat) == NGX_ERROR) {
1714 ngx_http_close_request(r, 0); 1694 ngx_http_close_request(r->main, 0);
1715 ngx_http_close_connection(r->connection); 1695 ngx_http_close_connection(r->connection);
1716 } 1696 }
1717 1697
1718 return; 1698 return;
1719 } 1699 }
1986 1966
1987 if (b->pos < b->last) { 1967 if (b->pos < b->last) {
1988 1968
1989 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "pipelined request"); 1969 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "pipelined request");
1990 1970
1971 #if (NGX_STAT_STUB)
1972 ngx_atomic_fetch_add(ngx_stat_reading, 1);
1973 #endif
1974
1991 hc->pipeline = 1; 1975 hc->pipeline = 1;
1992 c->log->action = "reading client pipelined request line"; 1976 c->log->action = "reading client pipelined request line";
1977
1993 ngx_http_init_request(rev); 1978 ngx_http_init_request(rev);
1994 return; 1979 return;
1995 } 1980 }
1996 1981
1997 hc->pipeline = 0; 1982 hc->pipeline = 0;
2204 return; 2189 return;
2205 } 2190 }
2206 2191
2207 b->last += n; 2192 b->last += n;
2208 2193
2194 #if (NGX_STAT_STUB)
2195 ngx_atomic_fetch_add(ngx_stat_reading, 1);
2196 #endif
2197
2209 c->log->handler = ngx_http_log_error; 2198 c->log->handler = ngx_http_log_error;
2210 c->log->action = "reading client request line"; 2199 c->log->action = "reading client request line";
2211 2200
2212 ngx_http_init_request(rev); 2201 ngx_http_init_request(rev);
2213 } 2202 }
2386 ngx_log_error(NGX_LOG_ALERT, log, 0, "http request already closed"); 2375 ngx_log_error(NGX_LOG_ALERT, log, 0, "http request already closed");
2387 return; 2376 return;
2388 } 2377 }
2389 2378
2390 #if (NGX_STAT_STUB) 2379 #if (NGX_STAT_STUB)
2380
2391 if (r->stat_reading) { 2381 if (r->stat_reading) {
2392 ngx_atomic_fetch_add(ngx_stat_reading, -1); 2382 ngx_atomic_fetch_add(ngx_stat_reading, -1);
2393 } 2383 }
2394 2384
2395 if (r->stat_writing) { 2385 if (r->stat_writing) {
2396 ngx_atomic_fetch_add(ngx_stat_writing, -1); 2386 ngx_atomic_fetch_add(ngx_stat_writing, -1);
2397 } 2387 }
2388
2398 #endif 2389 #endif
2399 2390
2400 if (error && r->headers_out.status == 0) { 2391 if (error && r->headers_out.status == 0) {
2401 r->headers_out.status = error; 2392 r->headers_out.status = error;
2402 } 2393 }