diff options
author | Igor Sysoev <igor@sysoev.ru> | 2004-04-09 20:03:04 +0400 |
---|---|---|
committer | Igor Sysoev <igor@sysoev.ru> | 2004-04-09 20:03:04 +0400 |
commit | 407b0deeaf8455b220f0fdc5754d599dd3830a46 (patch) | |
tree | dfcbd24e036064ead477df71c4a3ee77562178d5 | |
parent | 3d3d2e4700e2de6d6864c2164dccff6e78c51b3d (diff) |
nginx-0.0.3-2004-04-09-20:03:04 import
-rw-r--r-- | auto/lib/pcre/conf | 5 | ||||
-rw-r--r-- | src/core/nginx.c | 1 | ||||
-rw-r--r-- | src/core/nginx.h | 4 | ||||
-rw-r--r-- | src/core/ngx_config.h | 1 | ||||
-rw-r--r-- | src/event/modules/ngx_epoll_module.c | 18 | ||||
-rw-r--r-- | src/event/ngx_event.c | 28 | ||||
-rw-r--r-- | src/event/ngx_event.h | 1 | ||||
-rw-r--r-- | src/event/ngx_event_accept.c | 2 | ||||
-rw-r--r-- | src/event/ngx_event_connect.c | 2 | ||||
-rw-r--r-- | src/os/unix/ngx_process_cycle.c | 53 |
10 files changed, 93 insertions, 22 deletions
diff --git a/auto/lib/pcre/conf b/auto/lib/pcre/conf index a907e8b50..a2ab1c6b5 100644 --- a/auto/lib/pcre/conf +++ b/auto/lib/pcre/conf @@ -44,8 +44,8 @@ else ngx_lib_inc="#include <pcre.h>" ngx_lib="PCRE library" - ngx_lib_test="pcre *re; pcre_compile(re, 0, NULL, 0, NULL)" - ngx_libs=-lpcre + ngx_lib_test="pcre *re; re = pcre_compile(NULL, 0, NULL, 0, NULL)" + ngx_libs="-lpcre" . auto/lib/test @@ -61,6 +61,7 @@ else ngx_lib="PCRE library in /usr/local/" ngx_lib_cflags="-I /usr/local/include" + ngx_libs="-L /usr/local/lib -lpcre" . auto/lib/test fi diff --git a/src/core/nginx.c b/src/core/nginx.c index 9c35e089e..3e3a07271 100644 --- a/src/core/nginx.c +++ b/src/core/nginx.c @@ -65,7 +65,6 @@ ngx_module_t ngx_core_module = { ngx_int_t ngx_max_module; -ngx_atomic_t ngx_connection_counter; ngx_int_t ngx_process; ngx_pid_t ngx_pid; diff --git a/src/core/nginx.h b/src/core/nginx.h index 224605a32..61a6f50e0 100644 --- a/src/core/nginx.h +++ b/src/core/nginx.h @@ -12,9 +12,5 @@ extern ngx_module_t ngx_core_module; -extern ngx_atomic_t ngx_connection_counter; - -extern ngx_int_t ngx_process; - #endif /* _NGINX_H_INCLUDED_ */ diff --git a/src/core/ngx_config.h b/src/core/ngx_config.h index eb3cacbe8..4e3e77bdd 100644 --- a/src/core/ngx_config.h +++ b/src/core/ngx_config.h @@ -83,6 +83,7 @@ typedef int ngx_flag_t; /* TODO: auto */ #define NGX_INT32_LEN sizeof("-2147483648") - 1 +#define NGX_INT64_LEN sizeof("-9223372036854775808") - 1 #define NGX_TIME_T_LEN sizeof("-2147483648") - 1 #define NGX_OFF_T_LEN sizeof("-9223372036854775808") - 1 diff --git a/src/event/modules/ngx_epoll_module.c b/src/event/modules/ngx_epoll_module.c index fb41fd417..1d387799a 100644 --- a/src/event/modules/ngx_epoll_module.c +++ b/src/event/modules/ngx_epoll_module.c @@ -341,11 +341,12 @@ static int ngx_epoll_del_connection(ngx_connection_t *c) int ngx_epoll_process_events(ngx_cycle_t *cycle) { int events; + size_t n; ngx_int_t instance, i; ngx_uint_t lock, expire; - size_t n; - ngx_msec_t timer; ngx_err_t err; + ngx_log_t *log; + ngx_msec_t timer; struct timeval tv; ngx_connection_t *c; ngx_epoch_msec_t delta; @@ -416,6 +417,7 @@ int ngx_epoll_process_events(ngx_cycle_t *cycle) } lock = 1; + log = cycle->log; for (i = 0; i < events; i++) { c = event_list[i].data.ptr; @@ -431,7 +433,11 @@ int ngx_epoll_process_events(ngx_cycle_t *cycle) c->write->returned_instance = instance; } - ngx_log_debug3(NGX_LOG_DEBUG_EVENT, cycle->log, 0, +#if (NGX_DEBUG) + log = c->log ? c->log : cycle->log; +#endif + + ngx_log_debug3(NGX_LOG_DEBUG_EVENT, log, 0, "epoll: fd:%d ev:%04X d:" PTR_FMT, c->fd, event_list[i].events, event_list[i].data); @@ -442,19 +448,19 @@ int ngx_epoll_process_events(ngx_cycle_t *cycle) * that was just closed in this iteration */ - ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0, + ngx_log_debug1(NGX_LOG_DEBUG_EVENT, log, 0, "epoll: stale event " PTR_FMT, c); continue; } if (event_list[i].events & (EPOLLERR|EPOLLHUP)) { - ngx_log_debug2(NGX_LOG_DEBUG_EVENT, cycle->log, 0, + ngx_log_debug2(NGX_LOG_DEBUG_EVENT, log, 0, "epoll_wait() error on fd:%d ev:%04X", c->fd, event_list[i].events); } if (event_list[i].events & ~(EPOLLIN|EPOLLOUT|EPOLLERR|EPOLLHUP)) { - ngx_log_error(NGX_LOG_ALERT, cycle->log, 0, + ngx_log_error(NGX_LOG_ALERT, log, 0, "strange epoll_wait() events fd:%d ev:%04X", c->fd, event_list[i].events); } diff --git a/src/event/ngx_event.c b/src/event/ngx_event.c index c5ea45d2c..70a533f3b 100644 --- a/src/event/ngx_event.c +++ b/src/event/ngx_event.c @@ -48,6 +48,10 @@ ngx_uint_t ngx_event_flags; ngx_event_actions_t ngx_event_actions; +ngx_atomic_t connection_counter; +ngx_atomic_t *ngx_connection_counter = &connection_counter; + + ngx_atomic_t *ngx_accept_mutex_ptr; ngx_atomic_t *ngx_accept_mutex; ngx_uint_t ngx_accept_mutex_held; @@ -152,6 +156,9 @@ ngx_module_t ngx_event_core_module = { static ngx_int_t ngx_event_module_init(ngx_cycle_t *cycle) { #if !(WIN32) + + size_t size; + char *shared; ngx_core_conf_t *ccf; ngx_event_conf_t *ecf; @@ -163,19 +170,26 @@ static ngx_int_t ngx_event_module_init(ngx_cycle_t *cycle) ecf = ngx_event_get_conf(cycle->conf_ctx, ngx_event_core_module); - if (ecf->accept_mutex == 0) { - return NGX_OK; - } - ngx_accept_mutex_ptr = (ngx_atomic_t *) mmap(NULL, sizeof(ngx_atomic_t), - PROT_READ|PROT_WRITE, - MAP_ANON|MAP_SHARED, -1, 0); + /* TODO: 128 is cache line size */ + + size = 128 /* ngx_accept_mutex */ + + 128; /* ngx_connection_counter */ - if (ngx_accept_mutex_ptr == NULL) { + shared = mmap(NULL, size, PROT_READ|PROT_WRITE, MAP_ANON|MAP_SHARED, -1, 0); + + if (shared == NULL) { ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, "mmap(MAP_ANON|MAP_SHARED) failed"); return NGX_ERROR; } + + if (ecf->accept_mutex) { + ngx_accept_mutex_ptr = (ngx_atomic_t *) shared; + } + + ngx_connection_counter = (ngx_atomic_t *) (shared + 128); + #endif return NGX_OK; diff --git a/src/event/ngx_event.h b/src/event/ngx_event.h index 433d6cffc..4c1403fa3 100644 --- a/src/event/ngx_event.h +++ b/src/event/ngx_event.h @@ -407,6 +407,7 @@ typedef struct { } ngx_event_module_t; +extern ngx_atomic_t *ngx_connection_counter; extern ngx_atomic_t *ngx_accept_mutex_ptr; extern ngx_atomic_t *ngx_accept_mutex; diff --git a/src/event/ngx_event_accept.c b/src/event/ngx_event_accept.c index 70db78d71..235ff7fc7 100644 --- a/src/event/ngx_event_accept.c +++ b/src/event/ngx_event_accept.c @@ -270,7 +270,7 @@ void ngx_event_accept(ngx_event_t *ev) * or protection by critical section or light mutex */ - c->number = ngx_atomic_inc(&ngx_connection_counter); + c->number = ngx_atomic_inc(ngx_connection_counter); ngx_log_debug2(NGX_LOG_DEBUG_EVENT, ev->log, 0, "accept: fd:%d c:%d", s, c->number); diff --git a/src/event/ngx_event_connect.c b/src/event/ngx_event_connect.c index 24fa834ec..857b3f695 100644 --- a/src/event/ngx_event_connect.c +++ b/src/event/ngx_event_connect.c @@ -202,7 +202,7 @@ int ngx_event_connect_peer(ngx_peer_connection_t *pc) * or protection by critical section or mutex */ - c->number = ngx_atomic_inc(&ngx_connection_counter); + c->number = ngx_atomic_inc(ngx_connection_counter); if (ngx_add_conn) { if (ngx_add_conn(c) == NGX_ERROR) { diff --git a/src/os/unix/ngx_process_cycle.c b/src/os/unix/ngx_process_cycle.c index 2410671f1..2797670df 100644 --- a/src/os/unix/ngx_process_cycle.c +++ b/src/os/unix/ngx_process_cycle.c @@ -3,6 +3,8 @@ #include <ngx_core.h> #include <ngx_event.h> +#include <nginx.h> + static void ngx_master_exit(ngx_cycle_t *cycle, ngx_master_ctx_t *ctx); static void ngx_worker_process_cycle(ngx_cycle_t *cycle, void *data); @@ -531,3 +533,54 @@ int ngx_worker_thread_cycle(void *data) } #endif + + +static ngx_int_t ngx_create_pid_file(ngx_cycle_t *cycle, ngx_master_ctx_t *ctx) +{ + size_t len; + u_char pid[NGX_INT64_LEN + 1]; + ngx_core_conf_t *ccf; + + ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module); + + if (ccf->pid.len == 0) { + ccf->pid.len = sizeof(NGINX_PID) - 1; + ccf->pid.data = NGINX_PID; + ccf->newpid.len = sizeof(NGINX_NEW_PID) - 1; + ccf->newpid.data = NGINX_NEW_PID; + + } else { + ccf->newpid.len = ccf->pid.len + sizeof(NGINX_NEW_PID_EXT); + if (!(ccf->newpid.data = ngx_alloc(ccf->newpid.len, cycle->log))) { + return NGX_ERROR; + } + + ngx_memcpy(ngx_cpymem(ccf->newpid.data, ccf->pid.data, ccf->pid.len), + NGINX_NEW_PID_EXT, sizeof(NGINX_NEW_PID_EXT)); + } + + len = ngx_snprintf((char *) pid, /* STUB */ 10, PID_T_FMT, ngx_getpid()); + ngx_memzero(&ctx->pid, sizeof(ngx_file_t)); + ctx->pid.name = ngx_inherited ? ccf->newpid : ccf->pid; + ctx->name = ccf->pid.data; + + ctx->pid.fd = ngx_open_file(ctx->pid.name.data, NGX_FILE_RDWR, + NGX_FILE_CREATE_OR_OPEN); + + if (ctx->pid.fd == NGX_INVALID_FILE) { + ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, + ngx_open_file_n " \"%s\" failed", ctx->pid.name.data); + return NGX_ERROR; + } + + if (ngx_write_file(&ctx->pid, pid, len, 0) == NGX_ERROR) { + return NGX_ERROR; + } + + if (ngx_close_file(ctx->pid.fd) == NGX_FILE_ERROR) { + ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, + ngx_close_file_n " \"%s\" failed", ctx->pid.name.data); + } + + return NGX_OK; +} |