nginx-0.0.3-2004-04-09-20:03:04 import
This commit is contained in:
parent
041b93cab3
commit
d63559b107
10 changed files with 93 additions and 22 deletions
|
@ -44,8 +44,8 @@ else
|
||||||
|
|
||||||
ngx_lib_inc="#include <pcre.h>"
|
ngx_lib_inc="#include <pcre.h>"
|
||||||
ngx_lib="PCRE library"
|
ngx_lib="PCRE library"
|
||||||
ngx_lib_test="pcre *re; pcre_compile(re, 0, NULL, 0, NULL)"
|
ngx_lib_test="pcre *re; re = pcre_compile(NULL, 0, NULL, 0, NULL)"
|
||||||
ngx_libs=-lpcre
|
ngx_libs="-lpcre"
|
||||||
. auto/lib/test
|
. auto/lib/test
|
||||||
|
|
||||||
|
|
||||||
|
@ -61,6 +61,7 @@ else
|
||||||
|
|
||||||
ngx_lib="PCRE library in /usr/local/"
|
ngx_lib="PCRE library in /usr/local/"
|
||||||
ngx_lib_cflags="-I /usr/local/include"
|
ngx_lib_cflags="-I /usr/local/include"
|
||||||
|
ngx_libs="-L /usr/local/lib -lpcre"
|
||||||
. auto/lib/test
|
. auto/lib/test
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
|
@ -65,7 +65,6 @@ ngx_module_t ngx_core_module = {
|
||||||
|
|
||||||
|
|
||||||
ngx_int_t ngx_max_module;
|
ngx_int_t ngx_max_module;
|
||||||
ngx_atomic_t ngx_connection_counter;
|
|
||||||
|
|
||||||
ngx_int_t ngx_process;
|
ngx_int_t ngx_process;
|
||||||
ngx_pid_t ngx_pid;
|
ngx_pid_t ngx_pid;
|
||||||
|
|
|
@ -12,9 +12,5 @@
|
||||||
|
|
||||||
extern ngx_module_t ngx_core_module;
|
extern ngx_module_t ngx_core_module;
|
||||||
|
|
||||||
extern ngx_atomic_t ngx_connection_counter;
|
|
||||||
|
|
||||||
extern ngx_int_t ngx_process;
|
|
||||||
|
|
||||||
|
|
||||||
#endif /* _NGINX_H_INCLUDED_ */
|
#endif /* _NGINX_H_INCLUDED_ */
|
||||||
|
|
|
@ -83,6 +83,7 @@ typedef int ngx_flag_t;
|
||||||
|
|
||||||
/* TODO: auto */
|
/* TODO: auto */
|
||||||
#define NGX_INT32_LEN sizeof("-2147483648") - 1
|
#define NGX_INT32_LEN sizeof("-2147483648") - 1
|
||||||
|
#define NGX_INT64_LEN sizeof("-9223372036854775808") - 1
|
||||||
#define NGX_TIME_T_LEN sizeof("-2147483648") - 1
|
#define NGX_TIME_T_LEN sizeof("-2147483648") - 1
|
||||||
#define NGX_OFF_T_LEN sizeof("-9223372036854775808") - 1
|
#define NGX_OFF_T_LEN sizeof("-9223372036854775808") - 1
|
||||||
|
|
||||||
|
|
|
@ -341,11 +341,12 @@ static int ngx_epoll_del_connection(ngx_connection_t *c)
|
||||||
int ngx_epoll_process_events(ngx_cycle_t *cycle)
|
int ngx_epoll_process_events(ngx_cycle_t *cycle)
|
||||||
{
|
{
|
||||||
int events;
|
int events;
|
||||||
|
size_t n;
|
||||||
ngx_int_t instance, i;
|
ngx_int_t instance, i;
|
||||||
ngx_uint_t lock, expire;
|
ngx_uint_t lock, expire;
|
||||||
size_t n;
|
|
||||||
ngx_msec_t timer;
|
|
||||||
ngx_err_t err;
|
ngx_err_t err;
|
||||||
|
ngx_log_t *log;
|
||||||
|
ngx_msec_t timer;
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
ngx_connection_t *c;
|
ngx_connection_t *c;
|
||||||
ngx_epoch_msec_t delta;
|
ngx_epoch_msec_t delta;
|
||||||
|
@ -416,6 +417,7 @@ int ngx_epoll_process_events(ngx_cycle_t *cycle)
|
||||||
}
|
}
|
||||||
|
|
||||||
lock = 1;
|
lock = 1;
|
||||||
|
log = cycle->log;
|
||||||
|
|
||||||
for (i = 0; i < events; i++) {
|
for (i = 0; i < events; i++) {
|
||||||
c = event_list[i].data.ptr;
|
c = event_list[i].data.ptr;
|
||||||
|
@ -431,7 +433,11 @@ int ngx_epoll_process_events(ngx_cycle_t *cycle)
|
||||||
c->write->returned_instance = instance;
|
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,
|
"epoll: fd:%d ev:%04X d:" PTR_FMT,
|
||||||
c->fd, event_list[i].events, event_list[i].data);
|
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
|
* 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);
|
"epoll: stale event " PTR_FMT, c);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event_list[i].events & (EPOLLERR|EPOLLHUP)) {
|
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",
|
"epoll_wait() error on fd:%d ev:%04X",
|
||||||
c->fd, event_list[i].events);
|
c->fd, event_list[i].events);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event_list[i].events & ~(EPOLLIN|EPOLLOUT|EPOLLERR|EPOLLHUP)) {
|
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",
|
"strange epoll_wait() events fd:%d ev:%04X",
|
||||||
c->fd, event_list[i].events);
|
c->fd, event_list[i].events);
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,6 +48,10 @@ ngx_uint_t ngx_event_flags;
|
||||||
ngx_event_actions_t ngx_event_actions;
|
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_ptr;
|
||||||
ngx_atomic_t *ngx_accept_mutex;
|
ngx_atomic_t *ngx_accept_mutex;
|
||||||
ngx_uint_t ngx_accept_mutex_held;
|
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)
|
static ngx_int_t ngx_event_module_init(ngx_cycle_t *cycle)
|
||||||
{
|
{
|
||||||
#if !(WIN32)
|
#if !(WIN32)
|
||||||
|
|
||||||
|
size_t size;
|
||||||
|
char *shared;
|
||||||
ngx_core_conf_t *ccf;
|
ngx_core_conf_t *ccf;
|
||||||
ngx_event_conf_t *ecf;
|
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);
|
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),
|
/* TODO: 128 is cache line size */
|
||||||
PROT_READ|PROT_WRITE,
|
|
||||||
MAP_ANON|MAP_SHARED, -1, 0);
|
|
||||||
|
|
||||||
if (ngx_accept_mutex_ptr == NULL) {
|
size = 128 /* ngx_accept_mutex */
|
||||||
|
+ 128; /* ngx_connection_counter */
|
||||||
|
|
||||||
|
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,
|
ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
|
||||||
"mmap(MAP_ANON|MAP_SHARED) failed");
|
"mmap(MAP_ANON|MAP_SHARED) failed");
|
||||||
return NGX_ERROR;
|
return NGX_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ecf->accept_mutex) {
|
||||||
|
ngx_accept_mutex_ptr = (ngx_atomic_t *) shared;
|
||||||
|
}
|
||||||
|
|
||||||
|
ngx_connection_counter = (ngx_atomic_t *) (shared + 128);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return NGX_OK;
|
return NGX_OK;
|
||||||
|
|
|
@ -407,6 +407,7 @@ typedef struct {
|
||||||
} ngx_event_module_t;
|
} 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_ptr;
|
||||||
extern ngx_atomic_t *ngx_accept_mutex;
|
extern ngx_atomic_t *ngx_accept_mutex;
|
||||||
|
|
|
@ -270,7 +270,7 @@ void ngx_event_accept(ngx_event_t *ev)
|
||||||
* or protection by critical section or light mutex
|
* 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,
|
ngx_log_debug2(NGX_LOG_DEBUG_EVENT, ev->log, 0,
|
||||||
"accept: fd:%d c:%d", s, c->number);
|
"accept: fd:%d c:%d", s, c->number);
|
||||||
|
|
|
@ -202,7 +202,7 @@ int ngx_event_connect_peer(ngx_peer_connection_t *pc)
|
||||||
* or protection by critical section or mutex
|
* 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) {
|
||||||
if (ngx_add_conn(c) == NGX_ERROR) {
|
if (ngx_add_conn(c) == NGX_ERROR) {
|
||||||
|
|
|
@ -3,6 +3,8 @@
|
||||||
#include <ngx_core.h>
|
#include <ngx_core.h>
|
||||||
#include <ngx_event.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_master_exit(ngx_cycle_t *cycle, ngx_master_ctx_t *ctx);
|
||||||
static void ngx_worker_process_cycle(ngx_cycle_t *cycle, void *data);
|
static void ngx_worker_process_cycle(ngx_cycle_t *cycle, void *data);
|
||||||
|
@ -531,3 +533,54 @@ int ngx_worker_thread_cycle(void *data)
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#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;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue