Mercurial > hg > nginx
changeset 309:2e899477243a
nginx-0.0.3-2004-04-09-20:03:04 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Fri, 09 Apr 2004 16:03:04 +0000 |
parents | 7a0dbd779c6d |
children | a9a9af2c7370 |
files | auto/lib/pcre/conf src/core/nginx.c src/core/nginx.h src/core/ngx_config.h src/event/modules/ngx_epoll_module.c src/event/ngx_event.c src/event/ngx_event.h src/event/ngx_event_accept.c src/event/ngx_event_connect.c src/os/unix/ngx_process_cycle.c |
diffstat | 10 files changed, 93 insertions(+), 22 deletions(-) [+] |
line wrap: on
line diff
--- a/auto/lib/pcre/conf Fri Apr 09 05:45:41 2004 +0000 +++ b/auto/lib/pcre/conf Fri Apr 09 16:03:04 2004 +0000 @@ -44,8 +44,8 @@ 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 @@ 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
--- a/src/core/nginx.c Fri Apr 09 05:45:41 2004 +0000 +++ b/src/core/nginx.c Fri Apr 09 16:03:04 2004 +0000 @@ -65,7 +65,6 @@ ngx_int_t ngx_max_module; -ngx_atomic_t ngx_connection_counter; ngx_int_t ngx_process; ngx_pid_t ngx_pid;
--- a/src/core/nginx.h Fri Apr 09 05:45:41 2004 +0000 +++ b/src/core/nginx.h Fri Apr 09 16:03:04 2004 +0000 @@ -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_ */
--- a/src/core/ngx_config.h Fri Apr 09 05:45:41 2004 +0000 +++ b/src/core/ngx_config.h Fri Apr 09 16:03:04 2004 +0000 @@ -83,6 +83,7 @@ /* 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
--- a/src/event/modules/ngx_epoll_module.c Fri Apr 09 05:45:41 2004 +0000 +++ b/src/event/modules/ngx_epoll_module.c Fri Apr 09 16:03:04 2004 +0000 @@ -341,11 +341,12 @@ 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_err_t err; + ngx_log_t *log; ngx_msec_t timer; - ngx_err_t err; struct timeval tv; ngx_connection_t *c; ngx_epoch_msec_t delta; @@ -416,6 +417,7 @@ } lock = 1; + log = cycle->log; for (i = 0; i < events; i++) { c = event_list[i].data.ptr; @@ -431,7 +433,11 @@ 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 @@ * 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); }
--- a/src/event/ngx_event.c Fri Apr 09 05:45:41 2004 +0000 +++ b/src/event/ngx_event.c Fri Apr 09 16:03:04 2004 +0000 @@ -48,6 +48,10 @@ 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 @@ 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 @@ ecf = ngx_event_get_conf(cycle->conf_ctx, ngx_event_core_module); - if (ecf->accept_mutex == 0) { - return NGX_OK; - } + + /* TODO: 128 is cache line size */ - ngx_accept_mutex_ptr = (ngx_atomic_t *) mmap(NULL, sizeof(ngx_atomic_t), - PROT_READ|PROT_WRITE, - MAP_ANON|MAP_SHARED, -1, 0); + 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;
--- a/src/event/ngx_event.h Fri Apr 09 05:45:41 2004 +0000 +++ b/src/event/ngx_event.h Fri Apr 09 16:03:04 2004 +0000 @@ -407,6 +407,7 @@ } 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;
--- a/src/event/ngx_event_accept.c Fri Apr 09 05:45:41 2004 +0000 +++ b/src/event/ngx_event_accept.c Fri Apr 09 16:03:04 2004 +0000 @@ -270,7 +270,7 @@ * 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);
--- a/src/event/ngx_event_connect.c Fri Apr 09 05:45:41 2004 +0000 +++ b/src/event/ngx_event_connect.c Fri Apr 09 16:03:04 2004 +0000 @@ -202,7 +202,7 @@ * 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) {
--- a/src/os/unix/ngx_process_cycle.c Fri Apr 09 05:45:41 2004 +0000 +++ b/src/os/unix/ngx_process_cycle.c Fri Apr 09 16:03:04 2004 +0000 @@ -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 @@ } #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; +}