comparison src/event/ngx_event.c @ 58:b55cbf18157e NGINX_0_1_29

nginx 0.1.29 *) Feature: the ngx_http_ssi_module supports "include virtual" command. *) Feature: the ngx_http_ssi_module supports the condition command like 'if expr="$NAME"' and "else" and "endif" commands. Only one nested level is supported. *) Feature: the ngx_http_ssi_module supports the DATE_LOCAL and DATE_GMT variables and "config timefmt" command. *) Feature: the "ssi_ignore_recycled_buffers" directive. *) Bugfix: the "echo" command did not show the default value for the empty QUERY_STRING variable. *) Change: the ngx_http_proxy_module was rewritten. *) Feature: the "proxy_redirect", "proxy_pass_request_headers", "proxy_pass_request_body", and "proxy_method" directives. *) Feature: the "proxy_set_header" directive. The "proxy_x_var" was canceled and must be replaced with the proxy_set_header directive. *) Change: the "proxy_preserve_host" is canceled and must be replaced with the "proxy_set_header Host $host" and the "proxy_redirect off" directives, the "proxy_set_header Host $host:$proxy_port" directive and the appropriate proxy_redirect directives. *) Change: the "proxy_set_x_real_ip" is canceled and must be replaced with the "proxy_set_header X-Real-IP $remote_addr" directive. *) Change: the "proxy_add_x_forwarded_for" is canceled and must be replaced with the "proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for" directive. *) Change: the "proxy_set_x_url" is canceled and must be replaced with the "proxy_set_header X-URL http://$host:$server_port$request_uri" directive. *) Feature: the "fastcgi_param" directive. *) Change: the "fastcgi_root", "fastcgi_set_var" and "fastcgi_params" directive are canceled and must be replaced with the fastcgi_param directives. *) Feature: the "index" directive can use the variables. *) Feature: the "index" directive can be used at http and server levels. *) Change: the last index only in the "index" directive can be absolute. *) Feature: the "rewrite" directive can use the variables. *) Feature: the "internal" directive. *) Feature: the CONTENT_LENGTH, CONTENT_TYPE, REMOTE_PORT, SERVER_ADDR, SERVER_PORT, SERVER_PROTOCOL, DOCUMENT_ROOT, SERVER_NAME, REQUEST_METHOD, REQUEST_URI, and REMOTE_USER variables. *) Change: nginx now passes the invalid lines in a client request headers or a backend response header. *) Bugfix: if the backend did not transfer response for a long time and the "send_timeout" was less than "proxy_read_timeout", then nginx returned the 408 response. *) Bugfix: the segmentation fault was occurred if the backend sent an invalid line in response header; bug appeared in 0.1.26. *) Bugfix: the segmentation fault may occurred in FastCGI fault tolerance configuration. *) Bugfix: the "expires" directive did not remove the previous "Expires" and "Cache-Control" headers. *) Bugfix: nginx did not take into account trailing dot in "Host" header line. *) Bugfix: the ngx_http_auth_module did not work under Linux. *) Bugfix: the rewrite directive worked incorrectly, if the arguments were in a request. *) Bugfix: nginx could not be built on MacOS X.
author Igor Sysoev <http://sysoev.ru>
date Thu, 12 May 2005 00:00:00 +0400
parents 0d75d65c642f
children 71c46860eb55
comparison
equal deleted inserted replaced
57:5df375c55338 58:b55cbf18157e
22 static ngx_int_t ngx_event_module_init(ngx_cycle_t *cycle); 22 static ngx_int_t ngx_event_module_init(ngx_cycle_t *cycle);
23 static ngx_int_t ngx_event_process_init(ngx_cycle_t *cycle); 23 static ngx_int_t ngx_event_process_init(ngx_cycle_t *cycle);
24 static char *ngx_events_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); 24 static char *ngx_events_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
25 25
26 static char *ngx_event_connections(ngx_conf_t *cf, ngx_command_t *cmd, 26 static char *ngx_event_connections(ngx_conf_t *cf, ngx_command_t *cmd,
27 void *conf); 27 void *conf);
28 static char *ngx_event_use(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); 28 static char *ngx_event_use(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
29 static char *ngx_event_debug_connection(ngx_conf_t *cf, ngx_command_t *cmd, 29 static char *ngx_event_debug_connection(ngx_conf_t *cf, ngx_command_t *cmd,
30 void *conf); 30 void *conf);
31 31
32 static void *ngx_event_create_conf(ngx_cycle_t *cycle); 32 static void *ngx_event_create_conf(ngx_cycle_t *cycle);
33 static char *ngx_event_init_conf(ngx_cycle_t *cycle, void *conf); 33 static char *ngx_event_init_conf(ngx_cycle_t *cycle, void *conf);
34 static char *ngx_accept_mutex_check(ngx_conf_t *cf, void *post, void *data); 34 static char *ngx_accept_mutex_check(ngx_conf_t *cf, void *post, void *data);
35 35
89 NULL 89 NULL
90 }; 90 };
91 91
92 92
93 ngx_module_t ngx_events_module = { 93 ngx_module_t ngx_events_module = {
94 NGX_MODULE, 94 NGX_MODULE_V1,
95 &ngx_events_module_ctx, /* module context */ 95 &ngx_events_module_ctx, /* module context */
96 ngx_events_commands, /* module directives */ 96 ngx_events_commands, /* module directives */
97 NGX_CORE_MODULE, /* module type */ 97 NGX_CORE_MODULE, /* module type */
98 NULL, /* init module */ 98 NULL, /* init module */
99 NULL /* init process */ 99 NULL /* init process */
161 { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL } 161 { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }
162 }; 162 };
163 163
164 164
165 ngx_module_t ngx_event_core_module = { 165 ngx_module_t ngx_event_core_module = {
166 NGX_MODULE, 166 NGX_MODULE_V1,
167 &ngx_event_core_module_ctx, /* module context */ 167 &ngx_event_core_module_ctx, /* module context */
168 ngx_event_core_commands, /* module directives */ 168 ngx_event_core_commands, /* module directives */
169 NGX_EVENT_MODULE, /* module type */ 169 NGX_EVENT_MODULE, /* module type */
170 ngx_event_module_init, /* init module */ 170 ngx_event_module_init, /* init module */
171 ngx_event_process_init /* init process */ 171 ngx_event_process_init /* init process */
172 }; 172 };
173 173
174 174
175 static ngx_int_t ngx_event_module_init(ngx_cycle_t *cycle) 175 ngx_int_t
176 ngx_handle_read_event(ngx_event_t *rev, u_int flags)
177 {
178 if (ngx_event_flags & NGX_USE_CLEAR_EVENT) {
179
180 /* kqueue, epoll */
181
182 if (!rev->active && !rev->ready) {
183 if (ngx_add_event(rev, NGX_READ_EVENT, NGX_CLEAR_EVENT)
184 == NGX_ERROR)
185 {
186 return NGX_ERROR;
187 }
188 }
189
190 return NGX_OK;
191
192 } else if (ngx_event_flags & NGX_USE_LEVEL_EVENT) {
193
194 /* select, poll, /dev/poll */
195
196 if (!rev->active && !rev->ready) {
197 if (ngx_add_event(rev, NGX_READ_EVENT, NGX_LEVEL_EVENT)
198 == NGX_ERROR)
199 {
200 return NGX_ERROR;
201 }
202
203 return NGX_OK;
204 }
205
206 if (rev->active && (rev->ready || (flags & NGX_CLOSE_EVENT))) {
207 if (ngx_del_event(rev, NGX_READ_EVENT, NGX_LEVEL_EVENT | flags)
208 == NGX_ERROR)
209 {
210 return NGX_ERROR;
211 }
212
213 return NGX_OK;
214 }
215
216 } else if (ngx_event_flags & NGX_USE_ONESHOT_EVENT) {
217
218 /* event ports */
219
220 if (!rev->active) {
221 if (ngx_add_event(rev, NGX_READ_EVENT, NGX_ONESHOT_EVENT)
222 == NGX_ERROR)
223 {
224 return NGX_ERROR;
225 }
226 }
227
228 return NGX_OK;
229 }
230
231 /* aio, iocp, rtsig */
232
233 return NGX_OK;
234 }
235
236
237 ngx_int_t
238 ngx_handle_write_event(ngx_event_t *wev, size_t lowat)
239 {
240 ngx_connection_t *c;
241
242 if (lowat) {
243 c = (ngx_connection_t *) wev->data;
244
245 if (ngx_send_lowat(c, lowat) == NGX_ERROR) {
246 return NGX_ERROR;
247 }
248 }
249
250 if (ngx_event_flags & NGX_USE_CLEAR_EVENT) {
251
252 /* kqueue, epoll */
253
254 if (!wev->active && !wev->ready) {
255 if (ngx_add_event(wev, NGX_WRITE_EVENT,
256 NGX_CLEAR_EVENT | (lowat ? NGX_LOWAT_EVENT : 0))
257 == NGX_ERROR)
258 {
259 return NGX_ERROR;
260 }
261 }
262
263 return NGX_OK;
264
265 } else if (ngx_event_flags & NGX_USE_LEVEL_EVENT) {
266
267 /* select, poll, /dev/poll */
268
269 if (!wev->active && !wev->ready) {
270 if (ngx_add_event(wev, NGX_WRITE_EVENT, NGX_LEVEL_EVENT)
271 == NGX_ERROR)
272 {
273 return NGX_ERROR;
274 }
275
276 return NGX_OK;
277 }
278
279 if (wev->active && wev->ready) {
280 if (ngx_del_event(wev, NGX_WRITE_EVENT, NGX_LEVEL_EVENT)
281 == NGX_ERROR)
282 {
283 return NGX_ERROR;
284 }
285
286 return NGX_OK;
287 }
288
289 } else if (ngx_event_flags & NGX_USE_ONESHOT_EVENT) {
290
291 /* event ports */
292
293 if (!wev->active) {
294 if (ngx_add_event(wev, NGX_WRITE_EVENT, NGX_ONESHOT_EVENT)
295 == NGX_ERROR)
296 {
297 return NGX_ERROR;
298 }
299 }
300
301 return NGX_OK;
302 }
303
304 /* aio, iocp, rtsig */
305
306 return NGX_OK;
307 }
308
309
310 static ngx_int_t
311 ngx_event_module_init(ngx_cycle_t *cycle)
176 { 312 {
177 #if !(NGX_WIN32) 313 #if !(NGX_WIN32)
178 314
179 size_t size; 315 size_t size;
180 void ***cf; 316 void ***cf;
246 382
247 return NGX_OK; 383 return NGX_OK;
248 } 384 }
249 385
250 386
251 static ngx_int_t ngx_event_process_init(ngx_cycle_t *cycle) 387 static ngx_int_t
388 ngx_event_process_init(ngx_cycle_t *cycle)
252 { 389 {
253 ngx_uint_t m, i; 390 ngx_uint_t m, i;
254 ngx_socket_t fd; 391 ngx_socket_t fd;
255 ngx_event_t *rev, *wev; 392 ngx_event_t *rev, *wev;
256 ngx_listening_t *s; 393 ngx_listening_t *s;
415 } 552 }
416 553
417 #if (NGX_WIN32) 554 #if (NGX_WIN32)
418 555
419 if (ngx_event_flags & NGX_USE_IOCP_EVENT) { 556 if (ngx_event_flags & NGX_USE_IOCP_EVENT) {
420 rev->event_handler = ngx_event_acceptex; 557 rev->handler = ngx_event_acceptex;
421 558
422 if (ngx_add_event(rev, 0, NGX_IOCP_ACCEPT) == NGX_ERROR) { 559 if (ngx_add_event(rev, 0, NGX_IOCP_ACCEPT) == NGX_ERROR) {
423 return NGX_ERROR; 560 return NGX_ERROR;
424 } 561 }
425 562
429 { 566 {
430 return NGX_ERROR; 567 return NGX_ERROR;
431 } 568 }
432 569
433 } else { 570 } else {
434 rev->event_handler = ngx_event_accept; 571 rev->handler = ngx_event_accept;
435 572
436 if (ngx_add_event(rev, NGX_READ_EVENT, 0) == NGX_ERROR) { 573 if (ngx_add_event(rev, NGX_READ_EVENT, 0) == NGX_ERROR) {
437 return NGX_ERROR; 574 return NGX_ERROR;
438 } 575 }
439 } 576 }
440 577
441 #else 578 #else
442 579
443 rev->event_handler = ngx_event_accept; 580 rev->handler = ngx_event_accept;
444 581
445 if (ngx_accept_mutex) { 582 if (ngx_accept_mutex) {
446 continue; 583 continue;
447 } 584 }
448 585
462 599
463 return NGX_OK; 600 return NGX_OK;
464 } 601 }
465 602
466 603
467 ngx_int_t ngx_send_lowat(ngx_connection_t *c, size_t lowat) 604 ngx_int_t
605 ngx_send_lowat(ngx_connection_t *c, size_t lowat)
468 { 606 {
469 int sndlowat; 607 int sndlowat;
470 608
471 #if (NGX_HAVE_LOWAT_EVENT) 609 #if (NGX_HAVE_LOWAT_EVENT)
472 610
495 633
496 return NGX_OK; 634 return NGX_OK;
497 } 635 }
498 636
499 637
500 static char *ngx_events_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) 638 static char *
639 ngx_events_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
501 { 640 {
502 char *rv; 641 char *rv;
503 void ***ctx; 642 void ***ctx;
504 ngx_uint_t i; 643 ngx_uint_t i;
505 ngx_conf_t pcf; 644 ngx_conf_t pcf;
572 711
573 return NGX_CONF_OK; 712 return NGX_CONF_OK;
574 } 713 }
575 714
576 715
577 static char *ngx_event_connections(ngx_conf_t *cf, ngx_command_t *cmd, 716 static char *
578 void *conf) 717 ngx_event_connections(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
579 { 718 {
580 ngx_event_conf_t *ecf = conf; 719 ngx_event_conf_t *ecf = conf;
581 720
582 ngx_str_t *value; 721 ngx_str_t *value;
583 722
598 737
599 return NGX_CONF_OK; 738 return NGX_CONF_OK;
600 } 739 }
601 740
602 741
603 static char *ngx_event_use(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) 742 static char *
743 ngx_event_use(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
604 { 744 {
605 ngx_event_conf_t *ecf = conf; 745 ngx_event_conf_t *ecf = conf;
606 746
607 ngx_int_t m; 747 ngx_int_t m;
608 ngx_str_t *value; 748 ngx_str_t *value;
660 800
661 return NGX_CONF_ERROR; 801 return NGX_CONF_ERROR;
662 } 802 }
663 803
664 804
665 static char *ngx_event_debug_connection(ngx_conf_t *cf, ngx_command_t *cmd, 805 static char *
666 void *conf) 806 ngx_event_debug_connection(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
667 { 807 {
668 #if (NGX_DEBUG) 808 #if (NGX_DEBUG)
669 ngx_event_conf_t *ecf = conf; 809 ngx_event_conf_t *ecf = conf;
670 810
671 in_addr_t *addr; 811 in_addr_t *addr;
707 847
708 return NGX_OK; 848 return NGX_OK;
709 } 849 }
710 850
711 851
712 static void *ngx_event_create_conf(ngx_cycle_t *cycle) 852 static void *
853 ngx_event_create_conf(ngx_cycle_t *cycle)
713 { 854 {
714 ngx_event_conf_t *ecf; 855 ngx_event_conf_t *ecf;
715 856
716 ecf = ngx_palloc(cycle->pool, sizeof(ngx_event_conf_t)); 857 ecf = ngx_palloc(cycle->pool, sizeof(ngx_event_conf_t));
717 if (ecf == NULL) { 858 if (ecf == NULL) {
737 878
738 return ecf; 879 return ecf;
739 } 880 }
740 881
741 882
742 static char *ngx_event_init_conf(ngx_cycle_t *cycle, void *conf) 883 static char *
884 ngx_event_init_conf(ngx_cycle_t *cycle, void *conf)
743 { 885 {
744 ngx_event_conf_t *ecf = conf; 886 ngx_event_conf_t *ecf = conf;
745 887
746 #if (NGX_HAVE_EPOLL) && !(NGX_TEST_BUILD_EPOLL) 888 #if (NGX_HAVE_EPOLL) && !(NGX_TEST_BUILD_EPOLL)
747 int fd; 889 int fd;
872 1014
873 return NGX_CONF_ERROR; 1015 return NGX_CONF_ERROR;
874 } 1016 }
875 1017
876 1018
877 static char *ngx_accept_mutex_check(ngx_conf_t *cf, void *post, void *data) 1019 static char *
1020 ngx_accept_mutex_check(ngx_conf_t *cf, void *post, void *data)
878 { 1021 {
879 #if !(NGX_HAVE_ATOMIC_OPS) 1022 #if !(NGX_HAVE_ATOMIC_OPS)
880 1023
881 ngx_flag_t *fp = data; 1024 ngx_flag_t *fp = data;
882 1025