2003-05-19 12:39:14 -04:00
|
|
|
|
2002-08-06 12:39:45 -04:00
|
|
|
/*
|
2004-09-29 12:00:49 -04:00
|
|
|
* Copyright (C) Igor Sysoev
|
2002-08-06 12:39:45 -04:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include <ngx_config.h>
|
2002-08-29 12:59:54 -04:00
|
|
|
#include <ngx_core.h>
|
2002-08-06 12:39:45 -04:00
|
|
|
#include <ngx_event.h>
|
|
|
|
#include <ngx_kqueue_module.h>
|
|
|
|
|
|
|
|
|
2003-06-06 10:59:20 -04:00
|
|
|
typedef struct {
|
2003-11-21 03:30:49 -03:00
|
|
|
int changes;
|
|
|
|
int events;
|
2003-06-06 10:59:20 -04:00
|
|
|
} ngx_kqueue_conf_t;
|
|
|
|
|
|
|
|
|
2004-06-16 11:32:11 -04:00
|
|
|
static ngx_int_t ngx_kqueue_init(ngx_cycle_t *cycle);
|
2003-07-04 11:10:33 -04:00
|
|
|
static void ngx_kqueue_done(ngx_cycle_t *cycle);
|
2004-06-16 11:32:11 -04:00
|
|
|
static ngx_int_t ngx_kqueue_add_event(ngx_event_t *ev, int event, u_int flags);
|
|
|
|
static ngx_int_t ngx_kqueue_del_event(ngx_event_t *ev, int event, u_int flags);
|
|
|
|
static ngx_int_t ngx_kqueue_set_event(ngx_event_t *ev, int filter, u_int flags);
|
2004-07-07 02:15:04 -04:00
|
|
|
static ngx_int_t ngx_kqueue_process_changes(ngx_cycle_t *cycle, ngx_uint_t try);
|
2004-06-16 11:32:11 -04:00
|
|
|
static ngx_int_t ngx_kqueue_process_events(ngx_cycle_t *cycle);
|
2004-04-08 11:58:25 -04:00
|
|
|
static ngx_inline void ngx_kqueue_dump_event(ngx_log_t *log,
|
2005-03-04 11:06:57 -03:00
|
|
|
struct kevent *kev);
|
2002-12-24 14:30:59 -03:00
|
|
|
|
2003-07-07 02:11:50 -04:00
|
|
|
static void *ngx_kqueue_create_conf(ngx_cycle_t *cycle);
|
|
|
|
static char *ngx_kqueue_init_conf(ngx_cycle_t *cycle, void *conf);
|
2003-05-16 11:27:48 -04:00
|
|
|
|
|
|
|
|
2003-06-15 14:32:13 -04:00
|
|
|
int ngx_kqueue = -1;
|
2002-08-06 12:39:45 -04:00
|
|
|
|
2004-07-07 02:15:04 -04:00
|
|
|
/*
|
|
|
|
* The "change_list" should be declared as ngx_thread_volatile.
|
|
|
|
* However, the use of the change_list is localized in kqueue functions and
|
|
|
|
* is protected by the mutex so even the "icc -ipo" should not build the code
|
|
|
|
* with the race condition. Thus we avoid the declaration to make a more
|
|
|
|
* readable code.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static struct kevent *change_list, *change_list0, *change_list1;
|
|
|
|
static struct kevent *event_list;
|
2003-11-21 03:30:49 -03:00
|
|
|
static int max_changes, nchanges, nevents;
|
2002-12-15 03:25:09 -03:00
|
|
|
|
2004-07-07 02:15:04 -04:00
|
|
|
#if (NGX_THREADS)
|
2004-07-09 11:37:31 -04:00
|
|
|
static ngx_mutex_t *list_mutex;
|
|
|
|
static ngx_mutex_t *kevent_mutex;
|
2004-07-07 02:15:04 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2002-08-06 12:39:45 -04:00
|
|
|
|
2003-05-19 12:39:14 -04:00
|
|
|
static ngx_str_t kqueue_name = ngx_string("kqueue");
|
2003-05-16 11:27:48 -04:00
|
|
|
|
|
|
|
static ngx_command_t ngx_kqueue_commands[] = {
|
|
|
|
|
2005-03-04 11:06:57 -03:00
|
|
|
{ ngx_string("kqueue_changes"),
|
|
|
|
NGX_EVENT_CONF|NGX_CONF_TAKE1,
|
|
|
|
ngx_conf_set_num_slot,
|
|
|
|
0,
|
|
|
|
offsetof(ngx_kqueue_conf_t, changes),
|
|
|
|
NULL },
|
|
|
|
|
|
|
|
{ ngx_string("kqueue_events"),
|
|
|
|
NGX_EVENT_CONF|NGX_CONF_TAKE1,
|
|
|
|
ngx_conf_set_num_slot,
|
|
|
|
0,
|
|
|
|
offsetof(ngx_kqueue_conf_t, events),
|
|
|
|
NULL },
|
|
|
|
|
|
|
|
ngx_null_command
|
2003-05-16 11:27:48 -04:00
|
|
|
};
|
|
|
|
|
2003-05-19 12:39:14 -04:00
|
|
|
|
|
|
|
ngx_event_module_t ngx_kqueue_module_ctx = {
|
|
|
|
&kqueue_name,
|
|
|
|
ngx_kqueue_create_conf, /* create configuration */
|
|
|
|
ngx_kqueue_init_conf, /* init configuration */
|
|
|
|
|
2003-05-23 07:53:01 -04:00
|
|
|
{
|
2003-05-19 12:39:14 -04:00
|
|
|
ngx_kqueue_add_event, /* add an event */
|
|
|
|
ngx_kqueue_del_event, /* delete an event */
|
|
|
|
ngx_kqueue_add_event, /* enable an event */
|
|
|
|
ngx_kqueue_del_event, /* disable an event */
|
|
|
|
NULL, /* add an connection */
|
|
|
|
NULL, /* delete an connection */
|
2004-07-07 02:15:04 -04:00
|
|
|
ngx_kqueue_process_changes, /* process the changes */
|
2003-05-19 12:39:14 -04:00
|
|
|
ngx_kqueue_process_events, /* process the events */
|
|
|
|
ngx_kqueue_init, /* init the events */
|
2003-05-21 09:28:21 -04:00
|
|
|
ngx_kqueue_done /* done the events */
|
2003-05-19 12:39:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2003-05-16 11:27:48 -04:00
|
|
|
ngx_module_t ngx_kqueue_module = {
|
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.
2005-05-12 10:58:06 -04:00
|
|
|
NGX_MODULE_V1,
|
2003-05-19 12:39:14 -04:00
|
|
|
&ngx_kqueue_module_ctx, /* module context */
|
2003-05-16 11:27:48 -04:00
|
|
|
ngx_kqueue_commands, /* module directives */
|
2003-05-27 08:18:54 -04:00
|
|
|
NGX_EVENT_MODULE, /* module type */
|
2005-09-08 10:36:09 -04:00
|
|
|
NULL, /* init master */
|
2003-07-04 02:03:52 -04:00
|
|
|
NULL, /* init module */
|
2005-09-08 10:36:09 -04:00
|
|
|
NULL, /* init process */
|
|
|
|
NULL, /* init thread */
|
|
|
|
NULL, /* exit thread */
|
|
|
|
NULL, /* exit process */
|
|
|
|
NULL, /* exit master */
|
|
|
|
NGX_MODULE_V1_PADDING
|
2003-05-16 11:27:48 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2003-07-03 12:30:22 -04:00
|
|
|
|
2005-03-04 11:06:57 -03:00
|
|
|
static ngx_int_t
|
|
|
|
ngx_kqueue_init(ngx_cycle_t *cycle)
|
2003-07-03 12:30:22 -04:00
|
|
|
{
|
|
|
|
struct timespec ts;
|
|
|
|
ngx_kqueue_conf_t *kcf;
|
|
|
|
|
|
|
|
kcf = ngx_event_get_conf(cycle->conf_ctx, ngx_kqueue_module);
|
|
|
|
|
2003-06-15 14:32:13 -04:00
|
|
|
if (ngx_kqueue == -1) {
|
|
|
|
ngx_kqueue = kqueue();
|
|
|
|
|
|
|
|
if (ngx_kqueue == -1) {
|
2003-07-04 11:10:33 -04:00
|
|
|
ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
|
|
|
|
"kqueue() failed");
|
2003-06-15 14:32:13 -04:00
|
|
|
return NGX_ERROR;
|
|
|
|
}
|
2004-07-07 02:15:04 -04:00
|
|
|
|
|
|
|
#if (NGX_THREADS)
|
2004-07-09 11:37:31 -04:00
|
|
|
|
2005-03-19 08:38:37 -04:00
|
|
|
list_mutex = ngx_mutex_init(cycle->log, 0);
|
|
|
|
if (list_mutex == NULL) {
|
2004-07-09 11:37:31 -04:00
|
|
|
return NGX_ERROR;
|
|
|
|
}
|
|
|
|
|
2005-03-19 08:38:37 -04:00
|
|
|
kevent_mutex = ngx_mutex_init(cycle->log, 0);
|
|
|
|
if (kevent_mutex == NULL) {
|
2004-07-07 02:15:04 -04:00
|
|
|
return NGX_ERROR;
|
|
|
|
}
|
2004-07-09 11:37:31 -04:00
|
|
|
|
2004-07-07 02:15:04 -04:00
|
|
|
#endif
|
2003-06-15 14:32:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (max_changes < kcf->changes) {
|
|
|
|
if (nchanges) {
|
|
|
|
ts.tv_sec = 0;
|
|
|
|
ts.tv_nsec = 0;
|
|
|
|
|
|
|
|
if (kevent(ngx_kqueue, change_list, nchanges, NULL, 0, &ts) == -1) {
|
2003-07-04 11:10:33 -04:00
|
|
|
ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
|
|
|
|
"kevent() failed");
|
2003-06-15 14:32:13 -04:00
|
|
|
return NGX_ERROR;
|
|
|
|
}
|
2003-07-04 11:10:33 -04:00
|
|
|
nchanges = 0;
|
2003-06-15 14:32:13 -04:00
|
|
|
}
|
|
|
|
|
2004-07-07 02:15:04 -04:00
|
|
|
if (change_list0) {
|
|
|
|
ngx_free(change_list0);
|
|
|
|
}
|
|
|
|
|
|
|
|
change_list0 = ngx_alloc(kcf->changes * sizeof(struct kevent),
|
|
|
|
cycle->log);
|
|
|
|
if (change_list0 == NULL) {
|
|
|
|
return NGX_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (change_list1) {
|
|
|
|
ngx_free(change_list1);
|
2003-06-15 14:32:13 -04:00
|
|
|
}
|
|
|
|
|
2004-07-07 02:15:04 -04:00
|
|
|
change_list1 = ngx_alloc(kcf->changes * sizeof(struct kevent),
|
|
|
|
cycle->log);
|
|
|
|
if (change_list1 == NULL) {
|
2003-12-09 12:08:11 -03:00
|
|
|
return NGX_ERROR;
|
|
|
|
}
|
2004-07-07 02:15:04 -04:00
|
|
|
|
|
|
|
change_list = change_list0;
|
2003-06-15 14:32:13 -04:00
|
|
|
}
|
|
|
|
|
2003-05-19 12:39:14 -04:00
|
|
|
max_changes = kcf->changes;
|
2002-08-06 12:39:45 -04:00
|
|
|
|
2003-06-15 14:32:13 -04:00
|
|
|
if (nevents < kcf->events) {
|
|
|
|
if (event_list) {
|
|
|
|
ngx_free(event_list);
|
|
|
|
}
|
2002-09-13 10:47:42 -04:00
|
|
|
|
2004-07-07 02:15:04 -04:00
|
|
|
event_list = ngx_alloc(kcf->events * sizeof(struct kevent), cycle->log);
|
2003-12-09 12:08:11 -03:00
|
|
|
if (event_list == NULL) {
|
|
|
|
return NGX_ERROR;
|
|
|
|
}
|
2002-08-26 11:18:19 -04:00
|
|
|
}
|
2002-08-06 12:39:45 -04:00
|
|
|
|
2003-06-15 14:32:13 -04:00
|
|
|
nevents = kcf->events;
|
2002-08-06 12:39:45 -04:00
|
|
|
|
2003-07-04 11:10:33 -04:00
|
|
|
ngx_io = ngx_os_io;
|
2003-06-15 14:32:13 -04:00
|
|
|
|
2003-05-19 12:39:14 -04:00
|
|
|
ngx_event_actions = ngx_kqueue_module_ctx.actions;
|
2003-02-11 04:14:40 -03:00
|
|
|
|
2003-10-12 13:49:16 -03:00
|
|
|
ngx_event_flags = NGX_USE_ONESHOT_EVENT
|
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.
2005-05-12 10:58:06 -04:00
|
|
|
#if 1
|
2004-11-25 13:17:31 -03:00
|
|
|
#if (NGX_HAVE_CLEAR_EVENT)
|
2003-10-12 13:49:16 -03:00
|
|
|
|NGX_USE_CLEAR_EVENT
|
2003-03-11 16:38:13 -04:00
|
|
|
#else
|
|
|
|
|NGX_USE_LEVEL_EVENT
|
2003-03-04 03:33:48 -03:00
|
|
|
#endif
|
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.
2005-05-12 10:58:06 -04:00
|
|
|
#endif
|
2004-10-21 12:34:38 -03:00
|
|
|
#if (NGX_HAVE_LOWAT_EVENT)
|
|
|
|
|NGX_USE_LOWAT_EVENT
|
2003-02-06 14:21:13 -03:00
|
|
|
#endif
|
2004-10-21 12:34:38 -03:00
|
|
|
|NGX_USE_KQUEUE_EVENT;
|
2003-02-11 04:14:40 -03:00
|
|
|
|
2002-09-27 11:05:29 -04:00
|
|
|
return NGX_OK;
|
2002-08-06 12:39:45 -04:00
|
|
|
}
|
|
|
|
|
2002-12-15 03:25:09 -03:00
|
|
|
|
2005-03-04 11:06:57 -03:00
|
|
|
static void
|
|
|
|
ngx_kqueue_done(ngx_cycle_t *cycle)
|
2003-03-04 03:33:48 -03:00
|
|
|
{
|
2003-05-19 12:39:14 -04:00
|
|
|
if (close(ngx_kqueue) == -1) {
|
2003-07-04 11:10:33 -04:00
|
|
|
ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
|
|
|
|
"kqueue close() failed");
|
2003-03-04 03:33:48 -03:00
|
|
|
}
|
2003-05-19 12:39:14 -04:00
|
|
|
|
2003-06-15 14:32:13 -04:00
|
|
|
ngx_kqueue = -1;
|
|
|
|
|
2004-07-08 11:17:47 -04:00
|
|
|
#if (NGX_THREADS)
|
2004-07-09 11:37:31 -04:00
|
|
|
ngx_mutex_destroy(kevent_mutex);
|
|
|
|
ngx_mutex_destroy(list_mutex);
|
2004-07-08 11:17:47 -04:00
|
|
|
#endif
|
2004-07-07 02:15:04 -04:00
|
|
|
|
|
|
|
ngx_free(change_list1);
|
|
|
|
ngx_free(change_list0);
|
2003-05-19 12:39:14 -04:00
|
|
|
ngx_free(event_list);
|
2003-06-15 14:32:13 -04:00
|
|
|
|
2004-07-07 02:15:04 -04:00
|
|
|
change_list1 = NULL;
|
|
|
|
change_list0 = NULL;
|
2003-06-15 14:32:13 -04:00
|
|
|
change_list = NULL;
|
|
|
|
event_list = NULL;
|
|
|
|
max_changes = 0;
|
|
|
|
nchanges = 0;
|
|
|
|
nevents = 0;
|
2003-03-04 03:33:48 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-03-04 11:06:57 -03:00
|
|
|
static ngx_int_t
|
|
|
|
ngx_kqueue_add_event(ngx_event_t *ev, int event, u_int flags)
|
2002-08-06 12:39:45 -04:00
|
|
|
{
|
2004-07-07 02:15:04 -04:00
|
|
|
ngx_int_t rc;
|
2003-11-25 17:44:56 -03:00
|
|
|
ngx_event_t *e;
|
2003-05-19 12:39:14 -04:00
|
|
|
ngx_connection_t *c;
|
|
|
|
|
2002-12-24 14:30:59 -03:00
|
|
|
ev->active = 1;
|
2004-01-05 17:55:48 -03:00
|
|
|
ev->disabled = 0;
|
2003-05-20 11:37:55 -04:00
|
|
|
ev->oneshot = (flags & NGX_ONESHOT_EVENT) ? 1 : 0;
|
2002-09-12 10:42:29 -04:00
|
|
|
|
2004-07-09 11:37:31 -04:00
|
|
|
if (ngx_mutex_lock(list_mutex) == NGX_ERROR) {
|
2004-07-07 02:15:04 -04:00
|
|
|
return NGX_ERROR;
|
|
|
|
}
|
|
|
|
|
2004-10-21 12:34:38 -03:00
|
|
|
#if 1
|
|
|
|
|
2004-07-07 02:15:04 -04:00
|
|
|
if (nchanges > 0
|
2003-11-21 03:30:49 -03:00
|
|
|
&& ev->index < (u_int) nchanges
|
|
|
|
&& ((uintptr_t) change_list[ev->index].udata & (uintptr_t) ~1)
|
|
|
|
== (uintptr_t) ev)
|
2002-12-23 03:29:22 -03:00
|
|
|
{
|
2003-11-25 17:44:56 -03:00
|
|
|
if (change_list[ev->index].flags == EV_DISABLE) {
|
|
|
|
|
2004-01-05 17:55:48 -03:00
|
|
|
/*
|
|
|
|
* if the EV_DISABLE is still not passed to a kernel
|
|
|
|
* we will not pass it
|
|
|
|
*/
|
2003-11-25 17:44:56 -03:00
|
|
|
|
2004-01-05 17:55:48 -03:00
|
|
|
ngx_log_debug2(NGX_LOG_DEBUG_EVENT, ev->log, 0,
|
|
|
|
"kevent activated: %d: ft:%d",
|
|
|
|
ngx_event_ident(ev->data), event);
|
2003-11-25 17:44:56 -03:00
|
|
|
|
|
|
|
if (ev->index < (u_int) --nchanges) {
|
2004-10-21 12:34:38 -03:00
|
|
|
e = (ngx_event_t *)
|
|
|
|
((uintptr_t) change_list[nchanges].udata & (uintptr_t) ~1);
|
2003-11-25 17:44:56 -03:00
|
|
|
change_list[ev->index] = change_list[nchanges];
|
|
|
|
e->index = ev->index;
|
|
|
|
}
|
|
|
|
|
2004-07-09 11:37:31 -04:00
|
|
|
ngx_mutex_unlock(list_mutex);
|
2004-07-07 02:15:04 -04:00
|
|
|
|
2003-11-25 17:44:56 -03:00
|
|
|
return NGX_OK;
|
|
|
|
}
|
|
|
|
|
2003-05-19 12:39:14 -04:00
|
|
|
c = ev->data;
|
2004-07-07 02:15:04 -04:00
|
|
|
|
2003-05-19 12:39:14 -04:00
|
|
|
ngx_log_error(NGX_LOG_ALERT, ev->log, 0,
|
2003-10-27 13:16:17 -03:00
|
|
|
"previous event on #%d were not passed in kernel", c->fd);
|
2003-03-20 12:09:44 -04:00
|
|
|
|
2004-07-09 11:37:31 -04:00
|
|
|
ngx_mutex_unlock(list_mutex);
|
2004-07-07 02:15:04 -04:00
|
|
|
|
2003-05-19 12:39:14 -04:00
|
|
|
return NGX_ERROR;
|
2002-12-23 03:29:22 -03:00
|
|
|
}
|
|
|
|
|
2004-10-21 12:34:38 -03:00
|
|
|
#endif
|
|
|
|
|
2004-07-07 02:15:04 -04:00
|
|
|
rc = ngx_kqueue_set_event(ev, event, EV_ADD|EV_ENABLE|flags);
|
|
|
|
|
2004-07-09 11:37:31 -04:00
|
|
|
ngx_mutex_unlock(list_mutex);
|
2004-07-07 02:15:04 -04:00
|
|
|
|
|
|
|
return rc;
|
2002-08-06 12:39:45 -04:00
|
|
|
}
|
|
|
|
|
2002-12-15 03:25:09 -03:00
|
|
|
|
2005-03-04 11:06:57 -03:00
|
|
|
static ngx_int_t
|
|
|
|
ngx_kqueue_del_event(ngx_event_t *ev, int event, u_int flags)
|
2002-08-06 12:39:45 -04:00
|
|
|
{
|
2004-07-07 02:15:04 -04:00
|
|
|
ngx_int_t rc;
|
2002-12-24 14:30:59 -03:00
|
|
|
ngx_event_t *e;
|
|
|
|
|
|
|
|
ev->active = 0;
|
2004-01-05 17:55:48 -03:00
|
|
|
ev->disabled = 0;
|
2004-07-02 01:47:00 -04:00
|
|
|
|
2004-07-09 11:37:31 -04:00
|
|
|
if (ngx_mutex_lock(list_mutex) == NGX_ERROR) {
|
2004-07-07 02:15:04 -04:00
|
|
|
return NGX_ERROR;
|
|
|
|
}
|
|
|
|
|
2004-10-21 12:34:38 -03:00
|
|
|
#if 1
|
|
|
|
|
2004-07-07 02:15:04 -04:00
|
|
|
if (nchanges > 0
|
2003-11-21 03:30:49 -03:00
|
|
|
&& ev->index < (u_int) nchanges
|
|
|
|
&& ((uintptr_t) change_list[ev->index].udata & (uintptr_t) ~1)
|
|
|
|
== (uintptr_t) ev)
|
2002-12-19 04:08:55 -03:00
|
|
|
{
|
2004-01-05 17:55:48 -03:00
|
|
|
ngx_log_debug2(NGX_LOG_DEBUG_EVENT, ev->log, 0,
|
|
|
|
"kevent deleted: %d: ft:%d",
|
|
|
|
ngx_event_ident(ev->data), event);
|
2003-03-20 12:09:44 -04:00
|
|
|
|
|
|
|
/* if the event is still not passed to a kernel we will not pass it */
|
|
|
|
|
2003-11-21 03:30:49 -03:00
|
|
|
if (ev->index < (u_int) --nchanges) {
|
2004-10-21 12:34:38 -03:00
|
|
|
e = (ngx_event_t *)
|
|
|
|
((uintptr_t) change_list[nchanges].udata & (uintptr_t) ~1);
|
2002-12-15 03:25:09 -03:00
|
|
|
change_list[ev->index] = change_list[nchanges];
|
|
|
|
e->index = ev->index;
|
|
|
|
}
|
2002-10-04 13:58:04 -04:00
|
|
|
|
2004-07-09 11:37:31 -04:00
|
|
|
ngx_mutex_unlock(list_mutex);
|
2004-07-07 02:15:04 -04:00
|
|
|
|
2002-10-04 13:58:04 -04:00
|
|
|
return NGX_OK;
|
|
|
|
}
|
|
|
|
|
2004-10-21 12:34:38 -03:00
|
|
|
#endif
|
|
|
|
|
2003-10-12 13:49:16 -03:00
|
|
|
/*
|
2004-02-12 17:57:10 -03:00
|
|
|
* when the file descriptor is closed the kqueue automatically deletes
|
2003-10-12 13:49:16 -03:00
|
|
|
* its filters so we do not need to delete explicity the event
|
|
|
|
* before the closing the file descriptor.
|
|
|
|
*/
|
2003-03-20 12:09:44 -04:00
|
|
|
|
2002-12-24 14:30:59 -03:00
|
|
|
if (flags & NGX_CLOSE_EVENT) {
|
2004-07-09 11:37:31 -04:00
|
|
|
ngx_mutex_unlock(list_mutex);
|
2002-12-15 03:25:09 -03:00
|
|
|
return NGX_OK;
|
2002-12-24 14:30:59 -03:00
|
|
|
}
|
2002-12-15 03:25:09 -03:00
|
|
|
|
2004-01-05 17:55:48 -03:00
|
|
|
if (flags & NGX_DISABLE_EVENT) {
|
|
|
|
ev->disabled = 1;
|
|
|
|
}
|
|
|
|
|
2004-07-07 02:15:04 -04:00
|
|
|
rc = ngx_kqueue_set_event(ev, event,
|
2003-11-21 03:30:49 -03:00
|
|
|
flags & NGX_DISABLE_EVENT ? EV_DISABLE : EV_DELETE);
|
2004-07-07 02:15:04 -04:00
|
|
|
|
2004-07-09 11:37:31 -04:00
|
|
|
ngx_mutex_unlock(list_mutex);
|
2004-07-07 02:15:04 -04:00
|
|
|
|
|
|
|
return rc;
|
2002-08-06 12:39:45 -04:00
|
|
|
}
|
|
|
|
|
2002-12-15 03:25:09 -03:00
|
|
|
|
2005-03-04 11:06:57 -03:00
|
|
|
static ngx_int_t
|
|
|
|
ngx_kqueue_set_event(ngx_event_t *ev, int filter, u_int flags)
|
2002-08-06 12:39:45 -04:00
|
|
|
{
|
2004-07-07 02:15:04 -04:00
|
|
|
struct kevent *kev;
|
2003-06-15 14:32:13 -04:00
|
|
|
struct timespec ts;
|
|
|
|
ngx_connection_t *c;
|
2002-12-19 04:08:55 -03:00
|
|
|
|
2003-05-19 12:39:14 -04:00
|
|
|
c = ev->data;
|
2002-08-06 12:39:45 -04:00
|
|
|
|
2003-12-19 09:45:27 -03:00
|
|
|
ngx_log_debug3(NGX_LOG_DEBUG_EVENT, c->log, 0,
|
2004-11-11 11:07:14 -03:00
|
|
|
"kevent set event: %d: ft:%d fl:%04Xd",
|
2003-12-19 09:45:27 -03:00
|
|
|
c->fd, filter, flags);
|
2002-08-06 12:39:45 -04:00
|
|
|
|
2004-07-07 02:15:04 -04:00
|
|
|
if (nchanges >= max_changes) {
|
2002-08-06 12:39:45 -04:00
|
|
|
ngx_log_error(NGX_LOG_WARN, ev->log, 0,
|
2002-09-27 11:05:29 -04:00
|
|
|
"kqueue change list is filled up");
|
2002-08-06 12:39:45 -04:00
|
|
|
|
2002-12-19 04:08:55 -03:00
|
|
|
ts.tv_sec = 0;
|
|
|
|
ts.tv_nsec = 0;
|
|
|
|
|
2003-05-19 12:39:14 -04:00
|
|
|
if (kevent(ngx_kqueue, change_list, nchanges, NULL, 0, &ts) == -1) {
|
2003-06-15 14:32:13 -04:00
|
|
|
ngx_log_error(NGX_LOG_ALERT, ev->log, ngx_errno, "kevent() failed");
|
2002-09-13 10:47:42 -04:00
|
|
|
return NGX_ERROR;
|
2002-08-06 12:39:45 -04:00
|
|
|
}
|
2002-12-24 14:30:59 -03:00
|
|
|
|
2002-08-06 12:39:45 -04:00
|
|
|
nchanges = 0;
|
|
|
|
}
|
|
|
|
|
2004-07-07 02:15:04 -04:00
|
|
|
kev = &change_list[nchanges];
|
2004-06-28 17:03:14 -04:00
|
|
|
|
|
|
|
kev->ident = c->fd;
|
|
|
|
kev->filter = filter;
|
|
|
|
kev->flags = flags;
|
2005-02-16 10:40:36 -03:00
|
|
|
kev->udata = NGX_KQUEUE_UDATA_T ((uintptr_t) ev | ev->instance);
|
2003-03-04 03:33:48 -03:00
|
|
|
|
2003-11-25 17:44:56 -03:00
|
|
|
if (filter == EVFILT_VNODE) {
|
2004-06-28 17:03:14 -04:00
|
|
|
kev->fflags = NOTE_DELETE|NOTE_WRITE|NOTE_EXTEND
|
|
|
|
|NOTE_ATTRIB|NOTE_RENAME
|
2003-11-26 12:42:18 -03:00
|
|
|
#if (__FreeBSD__ == 4 && __FreeBSD_version >= 430000) \
|
|
|
|
|| __FreeBSD_version >= 500018
|
2004-06-28 17:03:14 -04:00
|
|
|
|NOTE_REVOKE
|
2003-11-26 12:42:18 -03:00
|
|
|
#endif
|
|
|
|
;
|
2004-06-28 17:03:14 -04:00
|
|
|
kev->data = 0;
|
2003-03-04 03:33:48 -03:00
|
|
|
|
|
|
|
} else {
|
2004-10-21 12:34:38 -03:00
|
|
|
#if (NGX_HAVE_LOWAT_EVENT)
|
2003-11-25 17:44:56 -03:00
|
|
|
if (flags & NGX_LOWAT_EVENT) {
|
2004-06-28 17:03:14 -04:00
|
|
|
kev->fflags = NOTE_LOWAT;
|
|
|
|
kev->data = ev->available;
|
2003-03-04 03:33:48 -03:00
|
|
|
|
2003-11-25 17:44:56 -03:00
|
|
|
} else {
|
2004-06-28 17:03:14 -04:00
|
|
|
kev->fflags = 0;
|
|
|
|
kev->data = 0;
|
2003-11-25 17:44:56 -03:00
|
|
|
}
|
2003-03-04 03:33:48 -03:00
|
|
|
#else
|
2004-06-28 17:03:14 -04:00
|
|
|
kev->fflags = 0;
|
|
|
|
kev->data = 0;
|
2003-03-04 03:33:48 -03:00
|
|
|
#endif
|
2003-11-25 17:44:56 -03:00
|
|
|
}
|
2002-10-04 13:58:04 -04:00
|
|
|
|
2004-07-07 02:15:04 -04:00
|
|
|
ev->index = nchanges;
|
|
|
|
nchanges++;
|
2002-08-06 12:39:45 -04:00
|
|
|
|
2002-09-13 10:47:42 -04:00
|
|
|
return NGX_OK;
|
2002-08-06 12:39:45 -04:00
|
|
|
}
|
|
|
|
|
2002-12-15 03:25:09 -03:00
|
|
|
|
2005-03-04 11:06:57 -03:00
|
|
|
static ngx_int_t
|
|
|
|
ngx_kqueue_process_events(ngx_cycle_t *cycle)
|
2002-08-06 12:39:45 -04:00
|
|
|
{
|
2004-07-07 02:15:04 -04:00
|
|
|
int events, n;
|
2004-04-04 16:32:09 -04:00
|
|
|
ngx_int_t i, instance;
|
2005-10-07 09:30:52 -04:00
|
|
|
ngx_uint_t lock, accept_lock;
|
2003-11-11 15:13:43 -03:00
|
|
|
ngx_err_t err;
|
2005-10-07 09:30:52 -04:00
|
|
|
ngx_msec_t timer, delta;
|
2003-11-11 15:13:43 -03:00
|
|
|
ngx_event_t *ev;
|
|
|
|
struct timeval tv;
|
|
|
|
struct timespec ts, *tp;
|
2002-12-15 03:25:09 -03:00
|
|
|
|
2005-10-07 09:30:52 -04:00
|
|
|
timer = ngx_event_find_timer();
|
2004-02-25 17:16:15 -03:00
|
|
|
|
2004-07-06 12:12:16 -04:00
|
|
|
#if (NGX_THREADS)
|
2004-07-07 11:01:00 -04:00
|
|
|
|
2005-10-07 09:30:52 -04:00
|
|
|
if (timer == NGX_TIMER_ERROR) {
|
|
|
|
return NGX_ERROR;
|
|
|
|
}
|
2004-02-25 17:16:15 -03:00
|
|
|
|
2005-10-07 09:30:52 -04:00
|
|
|
if (timer == NGX_TIMER_INFINITE || timer > 500) {
|
|
|
|
timer = 500;
|
|
|
|
}
|
2004-02-25 17:16:15 -03:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2004-04-21 14:54:33 -04:00
|
|
|
accept_lock = 0;
|
2003-01-24 03:20:47 -03:00
|
|
|
|
2004-03-31 11:26:46 -04:00
|
|
|
if (ngx_accept_mutex) {
|
2004-04-21 14:54:33 -04:00
|
|
|
if (ngx_accept_disabled > 0) {
|
|
|
|
ngx_accept_disabled--;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
if (ngx_trylock_accept_mutex(cycle) == NGX_ERROR) {
|
|
|
|
return NGX_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ngx_accept_mutex_held) {
|
|
|
|
accept_lock = 1;
|
2004-03-31 11:26:46 -04:00
|
|
|
|
2004-04-21 14:54:33 -04:00
|
|
|
} else if (timer == NGX_TIMER_INFINITE
|
|
|
|
|| timer > ngx_accept_mutex_delay)
|
|
|
|
{
|
|
|
|
timer = ngx_accept_mutex_delay;
|
|
|
|
}
|
2004-03-31 11:26:46 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-07-07 02:15:04 -04:00
|
|
|
if (ngx_threaded) {
|
|
|
|
if (ngx_kqueue_process_changes(cycle, 0) == NGX_ERROR) {
|
|
|
|
ngx_accept_mutex_unlock();
|
|
|
|
return NGX_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
n = 0;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
n = nchanges;
|
|
|
|
nchanges = 0;
|
|
|
|
}
|
|
|
|
|
2004-04-14 16:34:05 -04:00
|
|
|
if (timer == NGX_TIMER_INFINITE) {
|
|
|
|
tp = NULL;
|
2004-04-14 13:44:28 -04:00
|
|
|
|
2004-04-14 16:34:05 -04:00
|
|
|
} else {
|
2003-01-24 03:20:47 -03:00
|
|
|
ts.tv_sec = timer / 1000;
|
|
|
|
ts.tv_nsec = (timer % 1000) * 1000000;
|
|
|
|
tp = &ts;
|
|
|
|
}
|
|
|
|
|
2004-07-07 02:15:04 -04:00
|
|
|
ngx_log_debug2(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
|
2005-10-12 10:50:36 -03:00
|
|
|
"kevent timer: %M, changes: %d", timer, n);
|
2002-08-06 12:39:45 -04:00
|
|
|
|
2004-07-07 02:15:04 -04:00
|
|
|
events = kevent(ngx_kqueue, change_list, n, event_list, nevents, tp);
|
2002-12-19 04:08:55 -03:00
|
|
|
|
2002-09-13 10:47:42 -04:00
|
|
|
if (events == -1) {
|
2003-07-07 02:11:50 -04:00
|
|
|
err = ngx_errno;
|
|
|
|
} else {
|
|
|
|
err = 0;
|
2002-08-06 12:39:45 -04:00
|
|
|
}
|
|
|
|
|
2003-11-11 15:13:43 -03:00
|
|
|
ngx_gettimeofday(&tv);
|
2004-01-29 18:45:01 -03:00
|
|
|
ngx_time_update(tv.tv_sec);
|
2003-11-10 18:09:22 -03:00
|
|
|
|
2004-03-31 11:26:46 -04:00
|
|
|
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
|
|
|
|
"kevent events: %d", events);
|
2004-02-02 18:19:52 -03:00
|
|
|
|
2005-10-07 09:30:52 -04:00
|
|
|
delta = ngx_current_time;
|
|
|
|
ngx_current_time = (ngx_msec_t) tv.tv_sec * 1000 + tv.tv_usec / 1000;
|
2004-07-12 16:43:53 -04:00
|
|
|
|
2004-01-30 14:39:00 -03:00
|
|
|
if (err) {
|
|
|
|
ngx_log_error((err == NGX_EINTR) ? NGX_LOG_INFO : NGX_LOG_ALERT,
|
2004-03-31 11:26:46 -04:00
|
|
|
cycle->log, err, "kevent() failed");
|
2004-04-01 02:21:13 -04:00
|
|
|
ngx_accept_mutex_unlock();
|
2004-01-30 14:39:00 -03:00
|
|
|
return NGX_ERROR;
|
|
|
|
}
|
|
|
|
|
2004-04-14 16:34:05 -04:00
|
|
|
if (timer != NGX_TIMER_INFINITE) {
|
2005-10-07 09:30:52 -04:00
|
|
|
delta = ngx_current_time - delta;
|
2003-07-07 02:11:50 -04:00
|
|
|
|
2004-03-31 11:26:46 -04:00
|
|
|
ngx_log_debug2(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
|
2005-10-07 09:30:52 -04:00
|
|
|
"kevent timer: %M, delta: %M", timer, delta);
|
2004-01-29 18:45:01 -03:00
|
|
|
|
2002-08-06 12:39:45 -04:00
|
|
|
} else {
|
2002-12-24 14:30:59 -03:00
|
|
|
if (events == 0) {
|
2004-03-31 11:26:46 -04:00
|
|
|
ngx_log_error(NGX_LOG_ALERT, cycle->log, 0,
|
2003-06-15 14:32:13 -04:00
|
|
|
"kevent() returned no events without timeout");
|
2004-04-01 02:21:13 -04:00
|
|
|
ngx_accept_mutex_unlock();
|
2002-12-24 14:30:59 -03:00
|
|
|
return NGX_ERROR;
|
|
|
|
}
|
2003-12-04 11:53:00 -03:00
|
|
|
}
|
2002-08-06 12:39:45 -04:00
|
|
|
|
2004-06-28 12:05:02 -04:00
|
|
|
if (events > 0) {
|
|
|
|
if (ngx_mutex_lock(ngx_posted_events_mutex) == NGX_ERROR) {
|
|
|
|
ngx_accept_mutex_unlock();
|
|
|
|
return NGX_ERROR;
|
|
|
|
}
|
2004-02-26 14:10:01 -03:00
|
|
|
|
2004-06-28 12:05:02 -04:00
|
|
|
lock = 1;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
lock =0;
|
|
|
|
}
|
2004-04-04 16:32:09 -04:00
|
|
|
|
2002-08-06 12:39:45 -04:00
|
|
|
for (i = 0; i < events; i++) {
|
|
|
|
|
2004-04-08 11:58:25 -04:00
|
|
|
ngx_kqueue_dump_event(cycle->log, &event_list[i]);
|
2002-08-06 12:39:45 -04:00
|
|
|
|
|
|
|
if (event_list[i].flags & EV_ERROR) {
|
2004-03-31 11:26:46 -04:00
|
|
|
ngx_log_error(NGX_LOG_ALERT, cycle->log, event_list[i].data,
|
2003-06-15 14:32:13 -04:00
|
|
|
"kevent() error on %d", event_list[i].ident);
|
2002-08-06 12:39:45 -04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
ev = (ngx_event_t *) event_list[i].udata;
|
2002-12-24 14:30:59 -03:00
|
|
|
|
2002-08-06 12:39:45 -04:00
|
|
|
switch (event_list[i].filter) {
|
|
|
|
|
|
|
|
case EVFILT_READ:
|
|
|
|
case EVFILT_WRITE:
|
2003-03-20 12:09:44 -04:00
|
|
|
|
2003-05-21 09:28:21 -04:00
|
|
|
instance = (uintptr_t) ev & 1;
|
2003-11-21 03:30:49 -03:00
|
|
|
ev = (ngx_event_t *) ((uintptr_t) ev & (uintptr_t) ~1);
|
2003-05-21 09:28:21 -04:00
|
|
|
|
2004-07-02 11:54:34 -04:00
|
|
|
if (ev->closed || ev->instance != instance) {
|
2003-12-14 17:10:27 -03:00
|
|
|
|
|
|
|
/*
|
2004-02-01 05:10:52 -03:00
|
|
|
* the stale event from a file descriptor
|
2003-12-14 17:10:27 -03:00
|
|
|
* that was just closed in this iteration
|
|
|
|
*/
|
|
|
|
|
2004-03-31 11:26:46 -04:00
|
|
|
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
|
2004-11-11 11:07:14 -03:00
|
|
|
"kevent: stale event %p", ev);
|
2003-05-21 09:28:21 -04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2004-04-12 12:38:09 -04:00
|
|
|
if (ev->log && (ev->log->log_level & NGX_LOG_DEBUG_CONNECTION)) {
|
|
|
|
ngx_kqueue_dump_event(ev->log, &event_list[i]);
|
|
|
|
}
|
|
|
|
|
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.
2005-05-12 10:58:06 -04:00
|
|
|
if (ev->oneshot) {
|
|
|
|
ev->active = 0;
|
|
|
|
}
|
|
|
|
|
2004-07-02 11:54:34 -04:00
|
|
|
#if (NGX_THREADS)
|
|
|
|
|
|
|
|
if (ngx_threaded && !ev->accept) {
|
2004-07-02 01:47:00 -04:00
|
|
|
ev->posted_ready = 1;
|
2004-07-05 11:08:23 -04:00
|
|
|
ev->posted_available = event_list[i].data;
|
2004-07-02 01:47:00 -04:00
|
|
|
|
|
|
|
if (event_list[i].flags & EV_EOF) {
|
|
|
|
ev->posted_eof = 1;
|
|
|
|
ev->posted_errno = event_list[i].fflags;
|
|
|
|
}
|
|
|
|
|
|
|
|
ngx_post_event(ev);
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2004-07-02 11:54:34 -04:00
|
|
|
#endif
|
|
|
|
|
2002-08-06 12:39:45 -04:00
|
|
|
ev->available = event_list[i].data;
|
|
|
|
|
|
|
|
if (event_list[i].flags & EV_EOF) {
|
2004-07-02 11:54:34 -04:00
|
|
|
ev->pending_eof = 1;
|
2003-10-28 12:45:41 -03:00
|
|
|
ev->kq_errno = event_list[i].fflags;
|
2002-08-06 12:39:45 -04:00
|
|
|
}
|
|
|
|
|
2003-10-12 13:49:16 -03:00
|
|
|
ev->ready = 1;
|
|
|
|
|
|
|
|
break;
|
2003-02-06 14:21:13 -03:00
|
|
|
|
2003-11-25 17:44:56 -03:00
|
|
|
case EVFILT_VNODE:
|
|
|
|
ev->kq_vnode = 1;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
2003-02-06 14:21:13 -03:00
|
|
|
case EVFILT_AIO:
|
2003-10-30 05:51:06 -03:00
|
|
|
ev->complete = 1;
|
|
|
|
ev->ready = 1;
|
2003-02-06 14:21:13 -03:00
|
|
|
|
2002-08-06 12:39:45 -04:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2004-03-31 11:26:46 -04:00
|
|
|
ngx_log_error(NGX_LOG_ALERT, cycle->log, 0,
|
2003-11-25 17:44:56 -03:00
|
|
|
"unexpected kevent() filter %d",
|
|
|
|
event_list[i].filter);
|
2004-02-26 14:10:01 -03:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2004-04-04 16:32:09 -04:00
|
|
|
if (!ngx_threaded && !ngx_accept_mutex_held) {
|
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.
2005-05-12 10:58:06 -04:00
|
|
|
ev->handler(ev);
|
2004-02-26 14:10:01 -03:00
|
|
|
continue;
|
2002-12-24 14:30:59 -03:00
|
|
|
}
|
2004-02-26 14:10:01 -03:00
|
|
|
|
2004-04-04 16:32:09 -04:00
|
|
|
if (!ev->accept) {
|
|
|
|
ngx_post_event(ev);
|
|
|
|
continue;
|
2004-02-29 18:03:02 -03:00
|
|
|
}
|
|
|
|
|
2004-04-21 14:54:33 -04:00
|
|
|
if (ngx_accept_disabled > 0) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2004-04-04 16:32:09 -04:00
|
|
|
ngx_mutex_unlock(ngx_posted_events_mutex);
|
2004-02-26 14:10:01 -03:00
|
|
|
|
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.
2005-05-12 10:58:06 -04:00
|
|
|
ev->handler(ev);
|
2004-03-31 11:26:46 -04:00
|
|
|
|
2004-04-21 14:54:33 -04:00
|
|
|
if (ngx_accept_disabled > 0) {
|
|
|
|
ngx_accept_mutex_unlock();
|
|
|
|
accept_lock = 0;
|
|
|
|
}
|
|
|
|
|
2004-04-04 16:32:09 -04:00
|
|
|
if (i + 1 == events) {
|
|
|
|
lock = 0;
|
|
|
|
break;
|
2004-03-31 11:26:46 -04:00
|
|
|
}
|
|
|
|
|
2004-04-04 16:32:09 -04:00
|
|
|
if (ngx_mutex_lock(ngx_posted_events_mutex) == NGX_ERROR) {
|
2004-04-21 14:54:33 -04:00
|
|
|
if (accept_lock) {
|
|
|
|
ngx_accept_mutex_unlock();
|
|
|
|
}
|
2004-04-04 16:32:09 -04:00
|
|
|
return NGX_ERROR;
|
2004-03-31 11:26:46 -04:00
|
|
|
}
|
2004-02-26 14:10:01 -03:00
|
|
|
}
|
|
|
|
|
2004-04-21 14:54:33 -04:00
|
|
|
if (accept_lock) {
|
|
|
|
ngx_accept_mutex_unlock();
|
|
|
|
}
|
|
|
|
|
2004-04-04 16:32:09 -04:00
|
|
|
if (lock) {
|
|
|
|
ngx_mutex_unlock(ngx_posted_events_mutex);
|
|
|
|
}
|
2003-05-19 12:39:14 -04:00
|
|
|
|
2005-10-07 09:30:52 -04:00
|
|
|
ngx_event_expire_timers();
|
2004-02-26 14:10:01 -03:00
|
|
|
|
2004-06-27 14:01:57 -04:00
|
|
|
if (ngx_posted_events) {
|
|
|
|
if (ngx_threaded) {
|
2004-07-05 02:55:54 -04:00
|
|
|
ngx_wakeup_worker_thread(cycle);
|
2004-06-27 14:01:57 -04:00
|
|
|
|
|
|
|
} else {
|
|
|
|
ngx_event_process_posted(cycle);
|
|
|
|
}
|
2004-03-31 11:26:46 -04:00
|
|
|
}
|
|
|
|
|
2004-04-04 16:32:09 -04:00
|
|
|
return NGX_OK;
|
2004-02-26 14:10:01 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-03-04 11:06:57 -03:00
|
|
|
static ngx_int_t
|
|
|
|
ngx_kqueue_process_changes(ngx_cycle_t *cycle, ngx_uint_t try)
|
2004-07-07 02:15:04 -04:00
|
|
|
{
|
2004-09-14 11:55:24 -04:00
|
|
|
int n;
|
|
|
|
ngx_int_t rc;
|
|
|
|
ngx_err_t err;
|
|
|
|
struct timespec ts;
|
|
|
|
struct kevent *changes;
|
2004-07-07 02:15:04 -04:00
|
|
|
|
2004-07-09 11:37:31 -04:00
|
|
|
if (ngx_mutex_lock(kevent_mutex) == NGX_ERROR) {
|
|
|
|
return NGX_ERROR;
|
|
|
|
}
|
2004-07-07 02:15:04 -04:00
|
|
|
|
2004-07-09 11:37:31 -04:00
|
|
|
if (ngx_mutex_lock(list_mutex) == NGX_ERROR) {
|
|
|
|
ngx_mutex_unlock(kevent_mutex);
|
|
|
|
return NGX_ERROR;
|
2004-07-07 02:15:04 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (nchanges == 0) {
|
2004-07-09 11:37:31 -04:00
|
|
|
ngx_mutex_unlock(list_mutex);
|
|
|
|
ngx_mutex_unlock(kevent_mutex);
|
2004-07-07 02:15:04 -04:00
|
|
|
return NGX_OK;
|
|
|
|
}
|
|
|
|
|
2004-07-09 11:37:31 -04:00
|
|
|
changes = change_list;
|
2004-07-07 02:15:04 -04:00
|
|
|
if (change_list == change_list0) {
|
|
|
|
change_list = change_list1;
|
|
|
|
} else {
|
|
|
|
change_list = change_list0;
|
|
|
|
}
|
|
|
|
|
|
|
|
n = nchanges;
|
|
|
|
nchanges = 0;
|
|
|
|
|
2004-07-09 11:37:31 -04:00
|
|
|
ngx_mutex_unlock(list_mutex);
|
|
|
|
|
2004-07-07 02:15:04 -04:00
|
|
|
ts.tv_sec = 0;
|
|
|
|
ts.tv_nsec = 0;
|
|
|
|
|
|
|
|
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
|
|
|
|
"kevent changes: %d", n);
|
|
|
|
|
|
|
|
if (kevent(ngx_kqueue, changes, n, NULL, 0, &ts) == -1) {
|
|
|
|
err = ngx_errno;
|
|
|
|
ngx_log_error((err == NGX_EINTR) ? NGX_LOG_INFO : NGX_LOG_ALERT,
|
|
|
|
cycle->log, err, "kevent() failed");
|
|
|
|
rc = NGX_ERROR;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
rc = NGX_OK;
|
|
|
|
}
|
|
|
|
|
2004-07-09 11:37:31 -04:00
|
|
|
ngx_mutex_unlock(kevent_mutex);
|
2004-07-07 02:15:04 -04:00
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-03-04 11:06:57 -03:00
|
|
|
static ngx_inline void
|
|
|
|
ngx_kqueue_dump_event(ngx_log_t *log, struct kevent *kev)
|
2004-04-08 11:58:25 -04:00
|
|
|
{
|
|
|
|
ngx_log_debug6(NGX_LOG_DEBUG_EVENT, log, 0,
|
|
|
|
(kev->ident > 0x8000000 && kev->ident != (unsigned) -1) ?
|
2004-11-11 11:07:14 -03:00
|
|
|
"kevent: %p: ft:%d fl:%04Xd ff:%08Xd d:%d ud:%p":
|
|
|
|
"kevent: %d: ft:%d fl:%04Xd ff:%08Xd d:%d ud:%p",
|
2004-04-08 11:58:25 -04:00
|
|
|
kev->ident, kev->filter,
|
|
|
|
kev->flags, kev->fflags,
|
|
|
|
kev->data, kev->udata);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-03-04 11:06:57 -03:00
|
|
|
static void *
|
|
|
|
ngx_kqueue_create_conf(ngx_cycle_t *cycle)
|
2003-05-19 12:39:14 -04:00
|
|
|
{
|
|
|
|
ngx_kqueue_conf_t *kcf;
|
|
|
|
|
2005-03-19 08:38:37 -04:00
|
|
|
kcf = ngx_palloc(cycle->pool, sizeof(ngx_kqueue_conf_t));
|
|
|
|
if (kcf == NULL) {
|
|
|
|
return NGX_CONF_ERROR;
|
|
|
|
}
|
2003-05-19 12:39:14 -04:00
|
|
|
|
|
|
|
kcf->changes = NGX_CONF_UNSET;
|
|
|
|
kcf->events = NGX_CONF_UNSET;
|
|
|
|
|
|
|
|
return kcf;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-03-04 11:06:57 -03:00
|
|
|
static char *
|
|
|
|
ngx_kqueue_init_conf(ngx_cycle_t *cycle, void *conf)
|
2003-05-19 12:39:14 -04:00
|
|
|
{
|
|
|
|
ngx_kqueue_conf_t *kcf = conf;
|
|
|
|
|
2003-11-21 03:30:49 -03:00
|
|
|
ngx_conf_init_value(kcf->changes, 512);
|
|
|
|
ngx_conf_init_value(kcf->events, 512);
|
2003-05-19 12:39:14 -04:00
|
|
|
|
|
|
|
return NGX_CONF_OK;
|
|
|
|
}
|