From 899b44eab259f32af5c6e3da342f430c654528ce Mon Sep 17 00:00:00 2001 From: Igor Sysoev Date: Thu, 12 May 2005 14:58:06 +0000 Subject: nginx-0.1.29-RELEASE import *) 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; the bug had 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. --- src/event/modules/ngx_aio_module.c | 2 +- src/event/modules/ngx_devpoll_module.c | 8 +- src/event/modules/ngx_epoll_module.c | 8 +- src/event/modules/ngx_iocp_module.c | 6 +- src/event/modules/ngx_kqueue_module.c | 12 ++- src/event/modules/ngx_poll_module.c | 6 +- src/event/modules/ngx_rtsig_module.c | 20 ++-- src/event/modules/ngx_select_module.c | 6 +- src/event/ngx_event.c | 181 +++++++++++++++++++++++++++++---- src/event/ngx_event.h | 161 +---------------------------- src/event/ngx_event_accept.c | 4 +- src/event/ngx_event_acceptex.c | 2 +- src/event/ngx_event_busy_lock.c | 6 +- src/event/ngx_event_connect.c | 3 + src/event/ngx_event_openssl.c | 25 +++-- src/event/ngx_event_openssl.h | 1 + src/event/ngx_event_pipe.c | 26 ++++- src/event/ngx_event_posted.c | 4 +- src/event/ngx_event_timer.c | 2 +- 19 files changed, 256 insertions(+), 227 deletions(-) (limited to 'src/event') diff --git a/src/event/modules/ngx_aio_module.c b/src/event/modules/ngx_aio_module.c index 37a3a4499..37d520a96 100644 --- a/src/event/modules/ngx_aio_module.c +++ b/src/event/modules/ngx_aio_module.c @@ -54,7 +54,7 @@ ngx_event_module_t ngx_aio_module_ctx = { }; ngx_module_t ngx_aio_module = { - NGX_MODULE, + NGX_MODULE_V1, &ngx_aio_module_ctx, /* module context */ NULL, /* module directives */ NGX_EVENT_MODULE, /* module type */ diff --git a/src/event/modules/ngx_devpoll_module.c b/src/event/modules/ngx_devpoll_module.c index 57b6b1239..cab5af074 100644 --- a/src/event/modules/ngx_devpoll_module.c +++ b/src/event/modules/ngx_devpoll_module.c @@ -91,7 +91,7 @@ ngx_event_module_t ngx_devpoll_module_ctx = { }; ngx_module_t ngx_devpoll_module = { - NGX_MODULE, + NGX_MODULE_V1, &ngx_devpoll_module_ctx, /* module context */ ngx_devpoll_commands, /* module directives */ NGX_EVENT_MODULE, /* module type */ @@ -511,7 +511,7 @@ ngx_devpoll_process_events(ngx_cycle_t *cycle) wev->ready = 1; if (!ngx_threaded && !ngx_accept_mutex_held) { - wev->event_handler(wev); + wev->handler(wev); } else { ngx_post_event(wev); @@ -530,7 +530,7 @@ ngx_devpoll_process_events(ngx_cycle_t *cycle) rev->ready = 1; if (!ngx_threaded && !ngx_accept_mutex_held) { - rev->event_handler(rev); + rev->handler(rev); } else if (!rev->accept) { ngx_post_event(rev); @@ -538,7 +538,7 @@ ngx_devpoll_process_events(ngx_cycle_t *cycle) } else if (ngx_accept_disabled <= 0) { ngx_mutex_unlock(ngx_posted_events_mutex); - c->read->event_handler(rev); + c->read->handler(rev); if (ngx_accept_disabled > 0) { ngx_accept_mutex_unlock(); diff --git a/src/event/modules/ngx_epoll_module.c b/src/event/modules/ngx_epoll_module.c index 14b77508c..9847e0fe4 100644 --- a/src/event/modules/ngx_epoll_module.c +++ b/src/event/modules/ngx_epoll_module.c @@ -121,7 +121,7 @@ ngx_event_module_t ngx_epoll_module_ctx = { }; ngx_module_t ngx_epoll_module = { - NGX_MODULE, + NGX_MODULE_V1, &ngx_epoll_module_ctx, /* module context */ ngx_epoll_commands, /* module directives */ NGX_EVENT_MODULE, /* module type */ @@ -573,7 +573,7 @@ ngx_epoll_process_events(ngx_cycle_t *cycle) wev->ready = 1; if (!ngx_accept_mutex_held) { - wev->event_handler(wev); + wev->handler(wev); } else { ngx_post_event(wev); @@ -600,7 +600,7 @@ ngx_epoll_process_events(ngx_cycle_t *cycle) rev->ready = 1; if (!ngx_threaded && !ngx_accept_mutex_held) { - rev->event_handler(rev); + rev->handler(rev); } else if (!rev->accept) { ngx_post_event(rev); @@ -609,7 +609,7 @@ ngx_epoll_process_events(ngx_cycle_t *cycle) ngx_mutex_unlock(ngx_posted_events_mutex); - rev->event_handler(rev); + rev->handler(rev); if (ngx_accept_disabled > 0) { ngx_accept_mutex_unlock(); diff --git a/src/event/modules/ngx_iocp_module.c b/src/event/modules/ngx_iocp_module.c index 0a04a209a..1bb677c63 100644 --- a/src/event/modules/ngx_iocp_module.c +++ b/src/event/modules/ngx_iocp_module.c @@ -69,7 +69,7 @@ ngx_event_module_t ngx_iocp_module_ctx = { }; ngx_module_t ngx_iocp_module = { - NGX_MODULE, + NGX_MODULE_V1, &ngx_iocp_module_ctx, /* module context */ ngx_iocp_commands, /* module directives */ NGX_EVENT_MODULE, /* module type */ @@ -294,9 +294,9 @@ ngx_int_t ngx_iocp_process_events(ngx_cycle_t *cycle) ev->available = bytes; ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0, - "iocp event handler: %p", ev->event_handler); + "iocp event handler: %p", ev->handler); - ev->event_handler(ev); + ev->handler(ev); if (timer != INFINITE && delta) { ngx_event_expire_timers((ngx_msec_t) delta); diff --git a/src/event/modules/ngx_kqueue_module.c b/src/event/modules/ngx_kqueue_module.c index 14bbfaf27..713ea1a07 100644 --- a/src/event/modules/ngx_kqueue_module.c +++ b/src/event/modules/ngx_kqueue_module.c @@ -94,7 +94,7 @@ ngx_event_module_t ngx_kqueue_module_ctx = { }; ngx_module_t ngx_kqueue_module = { - NGX_MODULE, + NGX_MODULE_V1, &ngx_kqueue_module_ctx, /* module context */ ngx_kqueue_commands, /* module directives */ NGX_EVENT_MODULE, /* module type */ @@ -192,11 +192,13 @@ ngx_kqueue_init(ngx_cycle_t *cycle) ngx_event_actions = ngx_kqueue_module_ctx.actions; ngx_event_flags = NGX_USE_ONESHOT_EVENT +#if 1 #if (NGX_HAVE_CLEAR_EVENT) |NGX_USE_CLEAR_EVENT #else |NGX_USE_LEVEL_EVENT #endif +#endif #if (NGX_HAVE_LOWAT_EVENT) |NGX_USE_LOWAT_EVENT #endif @@ -615,6 +617,10 @@ ngx_kqueue_process_events(ngx_cycle_t *cycle) ngx_kqueue_dump_event(ev->log, &event_list[i]); } + if (ev->oneshot) { + ev->active = 0; + } + #if (NGX_THREADS) if (ngx_threaded && !ev->accept) { @@ -663,7 +669,7 @@ ngx_kqueue_process_events(ngx_cycle_t *cycle) } if (!ngx_threaded && !ngx_accept_mutex_held) { - ev->event_handler(ev); + ev->handler(ev); continue; } @@ -678,7 +684,7 @@ ngx_kqueue_process_events(ngx_cycle_t *cycle) ngx_mutex_unlock(ngx_posted_events_mutex); - ev->event_handler(ev); + ev->handler(ev); if (ngx_accept_disabled > 0) { ngx_accept_mutex_unlock(); diff --git a/src/event/modules/ngx_poll_module.c b/src/event/modules/ngx_poll_module.c index c25a5611c..97ac7ccc4 100644 --- a/src/event/modules/ngx_poll_module.c +++ b/src/event/modules/ngx_poll_module.c @@ -50,7 +50,7 @@ ngx_event_module_t ngx_poll_module_ctx = { }; ngx_module_t ngx_poll_module = { - NGX_MODULE, + NGX_MODULE_V1, &ngx_poll_module_ctx, /* module context */ NULL, /* module directives */ NGX_EVENT_MODULE, /* module type */ @@ -536,7 +536,7 @@ ngx_poll_process_events(ngx_cycle_t *cycle) } } - ev->event_handler(ev); + ev->handler(ev); } #endif @@ -553,7 +553,7 @@ ngx_poll_process_events(ngx_cycle_t *cycle) ngx_mutex_unlock(ngx_posted_events_mutex); - ev->event_handler(ev); + ev->handler(ev); if (ngx_accept_disabled > 0) { lock = 0; diff --git a/src/event/modules/ngx_rtsig_module.c b/src/event/modules/ngx_rtsig_module.c index 6c94977db..122b0918d 100644 --- a/src/event/modules/ngx_rtsig_module.c +++ b/src/event/modules/ngx_rtsig_module.c @@ -118,7 +118,7 @@ ngx_event_module_t ngx_rtsig_module_ctx = { }; ngx_module_t ngx_rtsig_module = { - NGX_MODULE, + NGX_MODULE_V1, &ngx_rtsig_module_ctx, /* module context */ ngx_rtsig_commands, /* module directives */ NGX_EVENT_MODULE, /* module type */ @@ -461,11 +461,11 @@ ngx_rtsig_process_events(ngx_cycle_t *cycle) rev->ready = 1; if (!ngx_threaded && !ngx_accept_mutex_held) { - rev->event_handler(rev); + rev->handler(rev); } else if (rev->accept) { if (ngx_accept_disabled <= 0) { - rev->event_handler(rev); + rev->handler(rev); } } else { @@ -495,7 +495,7 @@ ngx_rtsig_process_events(ngx_cycle_t *cycle) wev->ready = 1; if (!ngx_threaded && !ngx_accept_mutex_held) { - wev->event_handler(wev); + wev->handler(wev); } else { ngx_post_event(wev); @@ -598,11 +598,11 @@ ngx_rtsig_process_overflow(ngx_cycle_t *cycle) events = 0; - if (c->read->active && c->read->event_handler) { + if (c->read->active && c->read->handler) { events |= POLLIN; } - if (c->write->active && c->write->event_handler) { + if (c->write->active && c->write->handler) { events |= POLLOUT; } @@ -652,7 +652,7 @@ ngx_rtsig_process_overflow(ngx_cycle_t *cycle) if (rev->active && !rev->closed - && rev->event_handler + && rev->handler && (overflow_list[i].revents & (POLLIN|POLLERR|POLLHUP|POLLNVAL))) { @@ -664,7 +664,7 @@ ngx_rtsig_process_overflow(ngx_cycle_t *cycle) } else { rev->ready = 1; - rev->event_handler(rev); + rev->handler(rev); } } @@ -672,7 +672,7 @@ ngx_rtsig_process_overflow(ngx_cycle_t *cycle) if (wev->active && !wev->closed - && wev->event_handler + && wev->handler && (overflow_list[i].revents & (POLLOUT|POLLERR|POLLHUP|POLLNVAL))) { @@ -684,7 +684,7 @@ ngx_rtsig_process_overflow(ngx_cycle_t *cycle) } else { wev->ready = 1; - wev->event_handler(wev); + wev->handler(wev); } } } diff --git a/src/event/modules/ngx_select_module.c b/src/event/modules/ngx_select_module.c index 6edc2840a..4cf88400c 100644 --- a/src/event/modules/ngx_select_module.c +++ b/src/event/modules/ngx_select_module.c @@ -63,7 +63,7 @@ ngx_event_module_t ngx_select_module_ctx = { }; ngx_module_t ngx_select_module = { - NGX_MODULE, + NGX_MODULE_V1, &ngx_select_module_ctx, /* module context */ NULL, /* module directives */ NGX_EVENT_MODULE, /* module type */ @@ -540,7 +540,7 @@ ngx_select_process_events(ngx_cycle_t *cycle) } } - ev->event_handler(ev); + ev->handler(ev); } #endif @@ -557,7 +557,7 @@ ngx_select_process_events(ngx_cycle_t *cycle) ngx_mutex_unlock(ngx_posted_events_mutex); - ev->event_handler(ev); + ev->handler(ev); if (ngx_accept_disabled > 0) { lock = 0; diff --git a/src/event/ngx_event.c b/src/event/ngx_event.c index 0d10c4b56..274be6c52 100644 --- a/src/event/ngx_event.c +++ b/src/event/ngx_event.c @@ -24,10 +24,10 @@ static ngx_int_t ngx_event_process_init(ngx_cycle_t *cycle); static char *ngx_events_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); static char *ngx_event_connections(ngx_conf_t *cf, ngx_command_t *cmd, - void *conf); + void *conf); static char *ngx_event_use(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); static char *ngx_event_debug_connection(ngx_conf_t *cf, ngx_command_t *cmd, - void *conf); + void *conf); static void *ngx_event_create_conf(ngx_cycle_t *cycle); static char *ngx_event_init_conf(ngx_cycle_t *cycle, void *conf); @@ -91,7 +91,7 @@ static ngx_core_module_t ngx_events_module_ctx = { ngx_module_t ngx_events_module = { - NGX_MODULE, + NGX_MODULE_V1, &ngx_events_module_ctx, /* module context */ ngx_events_commands, /* module directives */ NGX_CORE_MODULE, /* module type */ @@ -163,7 +163,7 @@ ngx_event_module_t ngx_event_core_module_ctx = { ngx_module_t ngx_event_core_module = { - NGX_MODULE, + NGX_MODULE_V1, &ngx_event_core_module_ctx, /* module context */ ngx_event_core_commands, /* module directives */ NGX_EVENT_MODULE, /* module type */ @@ -172,7 +172,143 @@ ngx_module_t ngx_event_core_module = { }; -static ngx_int_t ngx_event_module_init(ngx_cycle_t *cycle) +ngx_int_t +ngx_handle_read_event(ngx_event_t *rev, u_int flags) +{ + if (ngx_event_flags & NGX_USE_CLEAR_EVENT) { + + /* kqueue, epoll */ + + if (!rev->active && !rev->ready) { + if (ngx_add_event(rev, NGX_READ_EVENT, NGX_CLEAR_EVENT) + == NGX_ERROR) + { + return NGX_ERROR; + } + } + + return NGX_OK; + + } else if (ngx_event_flags & NGX_USE_LEVEL_EVENT) { + + /* select, poll, /dev/poll */ + + if (!rev->active && !rev->ready) { + if (ngx_add_event(rev, NGX_READ_EVENT, NGX_LEVEL_EVENT) + == NGX_ERROR) + { + return NGX_ERROR; + } + + return NGX_OK; + } + + if (rev->active && (rev->ready || (flags & NGX_CLOSE_EVENT))) { + if (ngx_del_event(rev, NGX_READ_EVENT, NGX_LEVEL_EVENT | flags) + == NGX_ERROR) + { + return NGX_ERROR; + } + + return NGX_OK; + } + + } else if (ngx_event_flags & NGX_USE_ONESHOT_EVENT) { + + /* event ports */ + + if (!rev->active) { + if (ngx_add_event(rev, NGX_READ_EVENT, NGX_ONESHOT_EVENT) + == NGX_ERROR) + { + return NGX_ERROR; + } + } + + return NGX_OK; + } + + /* aio, iocp, rtsig */ + + return NGX_OK; +} + + +ngx_int_t +ngx_handle_write_event(ngx_event_t *wev, size_t lowat) +{ + ngx_connection_t *c; + + if (lowat) { + c = (ngx_connection_t *) wev->data; + + if (ngx_send_lowat(c, lowat) == NGX_ERROR) { + return NGX_ERROR; + } + } + + if (ngx_event_flags & NGX_USE_CLEAR_EVENT) { + + /* kqueue, epoll */ + + if (!wev->active && !wev->ready) { + if (ngx_add_event(wev, NGX_WRITE_EVENT, + NGX_CLEAR_EVENT | (lowat ? NGX_LOWAT_EVENT : 0)) + == NGX_ERROR) + { + return NGX_ERROR; + } + } + + return NGX_OK; + + } else if (ngx_event_flags & NGX_USE_LEVEL_EVENT) { + + /* select, poll, /dev/poll */ + + if (!wev->active && !wev->ready) { + if (ngx_add_event(wev, NGX_WRITE_EVENT, NGX_LEVEL_EVENT) + == NGX_ERROR) + { + return NGX_ERROR; + } + + return NGX_OK; + } + + if (wev->active && wev->ready) { + if (ngx_del_event(wev, NGX_WRITE_EVENT, NGX_LEVEL_EVENT) + == NGX_ERROR) + { + return NGX_ERROR; + } + + return NGX_OK; + } + + } else if (ngx_event_flags & NGX_USE_ONESHOT_EVENT) { + + /* event ports */ + + if (!wev->active) { + if (ngx_add_event(wev, NGX_WRITE_EVENT, NGX_ONESHOT_EVENT) + == NGX_ERROR) + { + return NGX_ERROR; + } + } + + return NGX_OK; + } + + /* aio, iocp, rtsig */ + + return NGX_OK; +} + + +static ngx_int_t +ngx_event_module_init(ngx_cycle_t *cycle) { #if !(NGX_WIN32) @@ -248,7 +384,8 @@ static ngx_int_t ngx_event_module_init(ngx_cycle_t *cycle) } -static ngx_int_t ngx_event_process_init(ngx_cycle_t *cycle) +static ngx_int_t +ngx_event_process_init(ngx_cycle_t *cycle) { ngx_uint_t m, i; ngx_socket_t fd; @@ -417,7 +554,7 @@ static ngx_int_t ngx_event_process_init(ngx_cycle_t *cycle) #if (NGX_WIN32) if (ngx_event_flags & NGX_USE_IOCP_EVENT) { - rev->event_handler = ngx_event_acceptex; + rev->handler = ngx_event_acceptex; if (ngx_add_event(rev, 0, NGX_IOCP_ACCEPT) == NGX_ERROR) { return NGX_ERROR; @@ -431,7 +568,7 @@ static ngx_int_t ngx_event_process_init(ngx_cycle_t *cycle) } } else { - rev->event_handler = ngx_event_accept; + rev->handler = ngx_event_accept; if (ngx_add_event(rev, NGX_READ_EVENT, 0) == NGX_ERROR) { return NGX_ERROR; @@ -440,7 +577,7 @@ static ngx_int_t ngx_event_process_init(ngx_cycle_t *cycle) #else - rev->event_handler = ngx_event_accept; + rev->handler = ngx_event_accept; if (ngx_accept_mutex) { continue; @@ -464,7 +601,8 @@ static ngx_int_t ngx_event_process_init(ngx_cycle_t *cycle) } -ngx_int_t ngx_send_lowat(ngx_connection_t *c, size_t lowat) +ngx_int_t +ngx_send_lowat(ngx_connection_t *c, size_t lowat) { int sndlowat; @@ -497,7 +635,8 @@ ngx_int_t ngx_send_lowat(ngx_connection_t *c, size_t lowat) } -static char *ngx_events_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) +static char * +ngx_events_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) { char *rv; void ***ctx; @@ -574,8 +713,8 @@ static char *ngx_events_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) } -static char *ngx_event_connections(ngx_conf_t *cf, ngx_command_t *cmd, - void *conf) +static char * +ngx_event_connections(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) { ngx_event_conf_t *ecf = conf; @@ -600,7 +739,8 @@ static char *ngx_event_connections(ngx_conf_t *cf, ngx_command_t *cmd, } -static char *ngx_event_use(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) +static char * +ngx_event_use(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) { ngx_event_conf_t *ecf = conf; @@ -662,8 +802,8 @@ static char *ngx_event_use(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) } -static char *ngx_event_debug_connection(ngx_conf_t *cf, ngx_command_t *cmd, - void *conf) +static char * +ngx_event_debug_connection(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) { #if (NGX_DEBUG) ngx_event_conf_t *ecf = conf; @@ -709,7 +849,8 @@ static char *ngx_event_debug_connection(ngx_conf_t *cf, ngx_command_t *cmd, } -static void *ngx_event_create_conf(ngx_cycle_t *cycle) +static void * +ngx_event_create_conf(ngx_cycle_t *cycle) { ngx_event_conf_t *ecf; @@ -739,7 +880,8 @@ static void *ngx_event_create_conf(ngx_cycle_t *cycle) } -static char *ngx_event_init_conf(ngx_cycle_t *cycle, void *conf) +static char * +ngx_event_init_conf(ngx_cycle_t *cycle, void *conf) { ngx_event_conf_t *ecf = conf; @@ -874,7 +1016,8 @@ static char *ngx_event_init_conf(ngx_cycle_t *cycle, void *conf) } -static char *ngx_accept_mutex_check(ngx_conf_t *cf, void *post, void *data) +static char * +ngx_accept_mutex_check(ngx_conf_t *cf, void *post, void *data) { #if !(NGX_HAVE_ATOMIC_OPS) diff --git a/src/event/ngx_event.h b/src/event/ngx_event.h index 6dfd70986..3e93bf778 100644 --- a/src/event/ngx_event.h +++ b/src/event/ngx_event.h @@ -113,8 +113,7 @@ struct ngx_event_s { unsigned available:1; #endif - /* TODO rename to handler */ - ngx_event_handler_pt event_handler; + ngx_event_handler_pt handler; #if (NGX_HAVE_AIO) @@ -474,6 +473,10 @@ ngx_int_t ngx_disable_accept_events(ngx_cycle_t *cycle); ngx_int_t ngx_enable_accept_events(ngx_cycle_t *cycle); +ngx_int_t ngx_handle_read_event(ngx_event_t *rev, u_int flags); +ngx_int_t ngx_handle_write_event(ngx_event_t *wev, size_t lowat); + + #if (NGX_WIN32) void ngx_event_acceptex(ngx_event_t *ev); int ngx_event_post_acceptex(ngx_listening_t *ls, int n); @@ -496,158 +499,4 @@ ngx_int_t ngx_send_lowat(ngx_connection_t *c, size_t lowat); #endif - -static ngx_inline ngx_int_t ngx_handle_read_event(ngx_event_t *rev, u_int flags) -{ - if (ngx_event_flags & NGX_USE_CLEAR_EVENT) { - - /* kqueue, epoll */ - - if (!rev->active && !rev->ready) { - if (ngx_add_event(rev, NGX_READ_EVENT, NGX_CLEAR_EVENT) - == NGX_ERROR) { - return NGX_ERROR; - } - } - - return NGX_OK; - - } else if (ngx_event_flags & NGX_USE_LEVEL_EVENT) { - - /* select, poll, /dev/poll */ - - if (!rev->active && !rev->ready) { - if (ngx_add_event(rev, NGX_READ_EVENT, NGX_LEVEL_EVENT) - == NGX_ERROR) - { - return NGX_ERROR; - } - - return NGX_OK; - } - - if (rev->active && (rev->ready || (flags & NGX_CLOSE_EVENT))) { - if (ngx_del_event(rev, NGX_READ_EVENT, flags) == NGX_ERROR) { - return NGX_ERROR; - } - - return NGX_OK; - } - } - - /* aio, iocp, rtsig */ - - return NGX_OK; -} - - -static ngx_inline ngx_int_t ngx_handle_level_read_event(ngx_event_t *rev) -{ - if (ngx_event_flags & NGX_USE_LEVEL_EVENT) { - if (!rev->active && !rev->ready) { - if (ngx_add_event(rev, NGX_READ_EVENT, NGX_LEVEL_EVENT) - == NGX_ERROR) - { - return NGX_ERROR; - } - - return NGX_OK; - } - - if (rev->active && rev->ready) { - if (ngx_del_event(rev, NGX_READ_EVENT, 0) == NGX_ERROR) { - return NGX_ERROR; - } - - return NGX_OK; - } - } - - return NGX_OK; -} - - -static ngx_inline ngx_int_t ngx_handle_write_event(ngx_event_t *wev, - size_t lowat) -{ - ngx_connection_t *c; - - if (lowat) { - c = (ngx_connection_t *) wev->data; - - if (ngx_send_lowat(c, lowat) == NGX_ERROR) { - return NGX_ERROR; - } - } - - if (ngx_event_flags & NGX_USE_CLEAR_EVENT) { - - /* kqueue, epoll */ - - if (!wev->active && !wev->ready) { - if (ngx_add_event(wev, NGX_WRITE_EVENT, - NGX_CLEAR_EVENT | (lowat ? NGX_LOWAT_EVENT : 0)) - == NGX_ERROR) - { - return NGX_ERROR; - } - } - - return NGX_OK; - - } else if (ngx_event_flags & NGX_USE_LEVEL_EVENT) { - - /* select, poll, /dev/poll */ - - if (!wev->active && !wev->ready) { - if (ngx_add_event(wev, NGX_WRITE_EVENT, NGX_LEVEL_EVENT) - == NGX_ERROR) - { - return NGX_ERROR; - } - - return NGX_OK; - } - - if (wev->active && wev->ready) { - if (ngx_del_event(wev, NGX_WRITE_EVENT, 0) == NGX_ERROR) { - return NGX_ERROR; - } - - return NGX_OK; - } - } - - /* aio, iocp, rtsig */ - - return NGX_OK; -} - - -static ngx_inline ngx_int_t ngx_handle_level_write_event(ngx_event_t *wev) -{ - if (ngx_event_flags & NGX_USE_LEVEL_EVENT) { - if (!wev->active && !wev->ready) { - if (ngx_add_event(wev, NGX_WRITE_EVENT, NGX_LEVEL_EVENT) - == NGX_ERROR) - { - return NGX_ERROR; - } - - return NGX_OK; - } - - if (wev->active && wev->ready) { - if (ngx_del_event(wev, NGX_WRITE_EVENT, 0) == NGX_ERROR) { - return NGX_ERROR; - } - - return NGX_OK; - } - } - - return NGX_OK; -} - - #endif /* _NGX_EVENT_H_INCLUDED_ */ diff --git a/src/event/ngx_event_accept.c b/src/event/ngx_event_accept.c index 9441c82a6..e31253367 100644 --- a/src/event/ngx_event_accept.c +++ b/src/event/ngx_event_accept.c @@ -106,7 +106,9 @@ ngx_event_accept(ngx_event_t *ev) return; } - ngx_log_error(NGX_LOG_ALERT, ev->log, err, + ngx_log_error((err == NGX_ECONNABORTED) ? NGX_LOG_CRIT: + NGX_LOG_ALERT, + ev->log, err, "accept() on %V failed", &ls->listening->addr_text); if (err == NGX_ECONNABORTED) { diff --git a/src/event/ngx_event_acceptex.c b/src/event/ngx_event_acceptex.c index b02dfd0d5..50cd21df3 100644 --- a/src/event/ngx_event_acceptex.c +++ b/src/event/ngx_event_acceptex.c @@ -132,7 +132,7 @@ int ngx_event_post_acceptex(ngx_listening_t *ls, int n) rev->ovlp.event = rev; wev->ovlp.event = wev; - rev->event_handler = ngx_event_acceptex; + rev->handler = ngx_event_acceptex; rev->data = c; wev->data = c; diff --git a/src/event/ngx_event_busy_lock.c b/src/event/ngx_event_busy_lock.c index 56a8d921c..4d499a3ae 100644 --- a/src/event/ngx_event_busy_lock.c +++ b/src/event/ngx_event_busy_lock.c @@ -43,7 +43,7 @@ ngx_int_t ngx_event_busy_lock(ngx_event_busy_lock_t *bl, } else if (ctx->timer && bl->waiting < bl->max_waiting) { bl->waiting++; ngx_add_timer(ctx->event, ctx->timer); - ctx->event->event_handler = ngx_event_busy_lock_handler; + ctx->event->handler = ngx_event_busy_lock_handler; if (bl->events) { bl->last->next = ctx; @@ -92,7 +92,7 @@ ngx_int_t ngx_event_busy_lock_cachable(ngx_event_busy_lock_t *bl, if (ctx->timer && bl->waiting < bl->max_waiting) { bl->waiting++; ngx_add_timer(ctx->event, ctx->timer); - ctx->event->event_handler = ngx_event_busy_lock_handler; + ctx->event->handler = ngx_event_busy_lock_handler; if (bl->events == NULL) { bl->events = ctx; @@ -296,7 +296,7 @@ static void ngx_event_busy_lock_handler(ngx_event_t *ev) ngx_mutex_unlock(ngx_posted_events_mutex); - ev->event_handler = ngx_event_busy_lock_posted_handler; + ev->handler = ngx_event_busy_lock_posted_handler; } diff --git a/src/event/ngx_event_connect.c b/src/event/ngx_event_connect.c index 81798d315..2f559a34d 100644 --- a/src/event/ngx_event_connect.c +++ b/src/event/ngx_event_connect.c @@ -114,6 +114,9 @@ ngx_event_connect_peer(ngx_peer_connection_t *pc) s = ngx_socket(peer->sockaddr->sa_family, SOCK_STREAM, 0); + ngx_log_debug1(NGX_LOG_DEBUG_EVENT, pc->log, 0, + "socket %d", s); + if (s == -1) { ngx_log_error(NGX_LOG_ALERT, pc->log, ngx_socket_errno, ngx_socket_n " failed"); diff --git a/src/event/ngx_event_openssl.c b/src/event/ngx_event_openssl.c index d213eb158..afdf4631c 100644 --- a/src/event/ngx_event_openssl.c +++ b/src/event/ngx_event_openssl.c @@ -170,7 +170,7 @@ ngx_ssl_handle_recv(ngx_connection_t *c, int n) if (c->ssl->saved_write_handler) { - c->write->event_handler = c->ssl->saved_write_handler; + c->write->handler = c->ssl->saved_write_handler; c->ssl->saved_write_handler = NULL; c->write->ready = 1; @@ -223,8 +223,8 @@ ngx_ssl_handle_recv(ngx_connection_t *c, int n) */ if (c->ssl->saved_write_handler == NULL) { - c->ssl->saved_write_handler = c->write->event_handler; - c->write->event_handler = ngx_ssl_write_handler; + c->ssl->saved_write_handler = c->write->handler; + c->write->handler = ngx_ssl_write_handler; } return NGX_AGAIN; @@ -253,7 +253,7 @@ ngx_ssl_write_handler(ngx_event_t *wev) ngx_connection_t *c; c = wev->data; - c->read->event_handler(c->read); + c->read->handler(c->read); } @@ -405,7 +405,7 @@ ngx_ssl_write(ngx_connection_t *c, u_char *data, size_t size) if (n > 0) { if (c->ssl->saved_read_handler) { - c->read->event_handler = c->ssl->saved_read_handler; + c->read->handler = c->ssl->saved_read_handler; c->ssl->saved_read_handler = NULL; c->read->ready = 1; @@ -460,8 +460,8 @@ ngx_ssl_write(ngx_connection_t *c, u_char *data, size_t size) */ if (c->ssl->saved_read_handler == NULL) { - c->ssl->saved_read_handler = c->read->event_handler; - c->read->event_handler = ngx_ssl_read_handler; + c->ssl->saved_read_handler = c->read->handler; + c->read->handler = ngx_ssl_read_handler; } return NGX_AGAIN; @@ -482,7 +482,7 @@ ngx_ssl_read_handler(ngx_event_t *rev) ngx_connection_t *c; c = rev->data; - c->write->event_handler(c->write); + c->write->handler(c->write); } @@ -592,3 +592,12 @@ ngx_ssl_error(ngx_uint_t level, ngx_log_t *log, ngx_err_t err, char *fmt, ...) ngx_log_error(level, log, err, "%s)", errstr); } + + +void +ngx_ssl_cleanup_ctx(void *data) +{ + SSL_CTX *ctx = data; + + SSL_CTX_free(ctx); +} diff --git a/src/event/ngx_event_openssl.h b/src/event/ngx_event_openssl.h index afebde694..8797fcd0f 100644 --- a/src/event/ngx_event_openssl.h +++ b/src/event/ngx_event_openssl.h @@ -54,6 +54,7 @@ ngx_chain_t *ngx_ssl_send_chain(ngx_connection_t *c, ngx_chain_t *in, ngx_int_t ngx_ssl_shutdown(ngx_connection_t *c); void ngx_ssl_error(ngx_uint_t level, ngx_log_t *log, ngx_err_t err, char *fmt, ...); +void ngx_ssl_cleanup_ctx(void *data); #endif /* _NGX_EVENT_OPENSSL_H_INCLUDED_ */ diff --git a/src/event/ngx_event_pipe.c b/src/event/ngx_event_pipe.c index 5f9d7c090..5d26405e2 100644 --- a/src/event/ngx_event_pipe.c +++ b/src/event/ngx_event_pipe.c @@ -64,13 +64,13 @@ ngx_int_t ngx_event_pipe(ngx_event_pipe_t *p, int do_write) } } - if (p->downstream->fd != -1) { + if (p->downstream->fd != -1 && p->downstream->data == p->output_ctx) { wev = p->downstream->write; if (ngx_handle_write_event(wev, p->send_lowat) == NGX_ERROR) { return NGX_ABORT; } - if (wev->active) { + if (wev->active && !wev->ready && !wev->delayed) { ngx_add_timer(wev, p->send_timeout); } } @@ -180,8 +180,10 @@ static ngx_int_t ngx_event_pipe_read_upstream(ngx_event_pipe_t *p) chain->buf = b; chain->next = NULL; - } else if (!p->cachable && p->downstream->write->ready) { - + } else if (!p->cachable + && p->downstream->data == p->output_ctx + && p->downstream->write->ready) + { /* * if the bufs are not needed to be saved in a cache and * a downstream is ready then write the bufs to a downstream @@ -409,10 +411,18 @@ static ngx_int_t ngx_event_pipe_write_to_downstream(ngx_event_pipe_t *p) /* pass the p->out and p->in chains to the output filter */ + for (cl = p->busy; cl; cl = cl->next) { + cl->buf->recycled = 0; + } + if (p->out) { ngx_log_debug0(NGX_LOG_DEBUG_EVENT, p->log, 0, "pipe write downstream flush out"); + for (cl = p->out; cl; cl = cl->next) { + cl->buf->recycled = 0; + } + if (p->output_filter(p->output_ctx, p->out) == NGX_ERROR) { p->downstream_error = 1; return ngx_event_pipe_drain_chains(p); @@ -425,6 +435,10 @@ static ngx_int_t ngx_event_pipe_write_to_downstream(ngx_event_pipe_t *p) ngx_log_debug0(NGX_LOG_DEBUG_EVENT, p->log, 0, "pipe write downstream flush in"); + for (cl = p->in; cl; cl = cl->next) { + cl->buf->recycled = 0; + } + if (p->output_filter(p->output_ctx, p->in) == NGX_ERROR) { p->downstream_error = 1; return ngx_event_pipe_drain_chains(p); @@ -442,7 +456,9 @@ static ngx_int_t ngx_event_pipe_write_to_downstream(ngx_event_pipe_t *p) break; } - if (!p->downstream->write->ready) { + if (p->downstream->data != p->output_ctx + || !p->downstream->write->ready) + { break; } diff --git a/src/event/ngx_event_posted.c b/src/event/ngx_event_posted.c index 8050c326f..181ab4cb4 100644 --- a/src/event/ngx_event_posted.c +++ b/src/event/ngx_event_posted.c @@ -33,7 +33,7 @@ void ngx_event_process_posted(ngx_cycle_t *cycle) ngx_delete_posted_event(ev); - ev->event_handler(ev); + ev->handler(ev); } } @@ -137,7 +137,7 @@ ngx_int_t ngx_event_thread_process_posted(ngx_cycle_t *cycle) ngx_mutex_unlock(ngx_posted_events_mutex); - ev->event_handler(ev); + ev->handler(ev); if (ngx_mutex_lock(ngx_posted_events_mutex) == NGX_ERROR) { return NGX_ERROR; diff --git a/src/event/ngx_event_timer.c b/src/event/ngx_event_timer.c index 7655c4fd8..fdec446c4 100644 --- a/src/event/ngx_event_timer.c +++ b/src/event/ngx_event_timer.c @@ -156,7 +156,7 @@ ngx_event_expire_timers(ngx_msec_t timer) ev->timedout = 1; - ev->event_handler(ev); + ev->handler(ev); continue; } -- cgit v1.2.3