# HG changeset patch # User Igor Sysoev # Date 1071821711 0 # Node ID 679f60139863b27e8d5764e8878d80cc634c7477 # Parent fd9fecc4193f83eaa3ba828e80265d2bd3168570 nginx-0.0.1-2003-12-19-11:15:11 import diff --git a/auto/lib/conf b/auto/lib/conf --- a/auto/lib/conf +++ b/auto/lib/conf @@ -2,12 +2,15 @@ if [ $PCRE != NO ]; then CORE_INCS="$CORE_INCS -I $PCRE" + CORE_DEPS="$CORE_DEPS $REGEX_DEPS" + CORE_SRCS="$CORE_SRCS $REGEX_SRCS" if [ "$PLATFORM" = "win32" ]; then - CFLAGS="$CFLAGS -D PCRE_STATIC" + CFLAGS="$CFLAGS -D PCRE_STATIC -D HAVE_PCRE=1" CORE_LIBS="$CORE_LIBS pcre.lib" CORE_LINK="$CORE_LINK -libpath:$PCRE" else + CFLAGS="$CFLAGS -D HAVE_PCRE=1" CORE_DEPS="$CORE_DEPS $PCRE/.libs/libpcre.a" CORE_LIBS="$CORE_LIBS -L $PCRE/.libs -lpcre" fi diff --git a/auto/sources b/auto/sources --- a/auto/sources +++ b/auto/sources @@ -5,6 +5,7 @@ CORE_INCS="-I src/core" CORE_DEPS="src/core/nginx.h \ src/core/ngx_config.h \ + src/core/ngx_atomic.h \ src/core/ngx_log.h \ src/core/ngx_alloc.h \ src/core/ngx_array.h \ @@ -15,7 +16,6 @@ CORE_DEPS="src/core/nginx.h \ src/core/ngx_inet.h \ src/core/ngx_file.h \ src/core/ngx_crc.h \ - src/core/ngx_regex.h \ src/core/ngx_rbtree.h \ src/core/ngx_times.h \ src/core/ngx_connection.h \ @@ -32,13 +32,16 @@ CORE_SRCS="src/core/nginx.c \ src/core/ngx_parse.c \ src/core/ngx_inet.c \ src/core/ngx_file.c \ - src/core/ngx_regex.c \ src/core/ngx_rbtree.c \ src/core/ngx_times.c \ src/core/ngx_conf_file.c \ src/core/ngx_garbage_collector.c" +REGEX_DEPS="src/core/ngx_regex.h" +REGEX_SRCS="src/core/ngx_regex.c" + + EVENT_MODULES="ngx_events_module ngx_event_core_module" EVENT_INCS="-I src/event -I src/event/modules" diff --git a/auto/summary b/auto/summary --- a/auto/summary +++ b/auto/summary @@ -2,6 +2,12 @@ echo echo "Configuration summary" +case $PCRE in + YES) echo " + using system PCRE library" ;; + NO) echo " + PCRE library is not found" ;; + *) echo " + using PCRE library: $PCRE" ;; +esac + case $MD5 in YES) echo " + using system md5 library" ;; NO) echo " + md5 library is not found" ;; diff --git a/auto/unix b/auto/unix --- a/auto/unix +++ b/auto/unix @@ -83,6 +83,12 @@ n = pwrite(1, buf, 1, 0)" . auto/func +ngx_func="strsignal()" +ngx_func_inc="#include " +ngx_func_test="char *s = strsignal(1)" +. auto/func + + ngx_func="strerror_r()" ngx_func_inc="#include " ngx_func_test="char buf[20]; strerror_r(1, buf, 20)" diff --git a/src/core/nginx.c b/src/core/nginx.c --- a/src/core/nginx.c +++ b/src/core/nginx.c @@ -72,7 +72,7 @@ int main(int argc, char *const *argv) int i; ngx_fd_t fd; ngx_log_t *log; - ngx_cycle_t *cycle; + ngx_cycle_t *cycle, init_cycle; ngx_open_file_t *file; #if !(WIN32) size_t len; @@ -88,10 +88,19 @@ int main(int argc, char *const *argv) /* TODO */ ngx_max_sockets = -1; ngx_time_init(); +#if (HAVE_PCRE) ngx_regex_init(); +#endif log = ngx_log_init_errlog(); + + /* init_cycle->log is required for signal handlers */ + + ngx_memzero(&init_cycle, sizeof(ngx_cycle_t)); + init_cycle.log = log; + ngx_cycle = &init_cycle; + if (ngx_os_init(log) == NGX_ERROR) { return 1; } @@ -207,7 +216,7 @@ int main(int argc, char *const *argv) } if (rotate) { - ngx_log_error(NGX_LOG_INFO, cycle->log, 0, "rotating logs"); + ngx_log_error(NGX_LOG_INFO, cycle->log, 0, "reopen logs"); file = cycle->open_files.elts; for (i = 0; i < cycle->open_files.nelts; i++) { diff --git a/src/core/ngx_atomic.h b/src/core/ngx_atomic.h new file mode 100644 --- /dev/null +++ b/src/core/ngx_atomic.h @@ -0,0 +1,13 @@ +#ifndef _NGX_ATOMIC_H_INCLUDED_ +#define _NGX_ATOMIC_H_INCLUDED_ + + +#include +#include + + +#define ngx_atomic_inc(x) x++; +#define ngx_atomic_dec(x) x--; + + +#endif /* _NGX_ATOMIC_H_INCLUDED_ */ diff --git a/src/core/ngx_core.h b/src/core/ngx_core.h --- a/src/core/ngx_core.h +++ b/src/core/ngx_core.h @@ -15,6 +15,7 @@ typedef struct ngx_event_s ngx_eve typedef struct ngx_connection_s ngx_connection_t; +#include #include #include #include @@ -30,7 +31,9 @@ typedef struct ngx_connection_s ngx_con #include #include #include +#if (HAVE_PCRE) #include +#endif #include #include #include diff --git a/src/core/ngx_rbtree.c b/src/core/ngx_rbtree.c --- a/src/core/ngx_rbtree.c +++ b/src/core/ngx_rbtree.c @@ -31,7 +31,7 @@ void ngx_rbtree_insert(ngx_rbtree_t **ro /* a binary tree insert */ if (*root == sentinel) { - node->parent = sentinel; + node->parent = NULL; node->left = sentinel; node->right = sentinel; ngx_rbt_black(node); @@ -71,7 +71,7 @@ void ngx_rbtree_insert(ngx_rbtree_t **ro ngx_rbt_red(node); - while (node->parent && ngx_rbt_is_red(node->parent)) { + while (node != *root && ngx_rbt_is_red(node->parent)) { if (node->parent == node->parent->parent->left) { temp = node->parent->parent->right; @@ -123,61 +123,90 @@ void ngx_rbtree_insert(ngx_rbtree_t **ro void ngx_rbtree_delete(ngx_rbtree_t **root, ngx_rbtree_t *sentinel, ngx_rbtree_t *node) { + ngx_int_t red; ngx_rbtree_t *subst, *temp, *w; /* a binary tree delete */ - if (node->left == sentinel || node->right == sentinel) { + if (node->left == sentinel) { + temp = node->right; + subst = node; + + } else if (node->right == sentinel) { + temp = node->left; subst = node; } else { - - /* find a node successor */ - - if (node->right == sentinel) { - temp = node; - subst = node->parent; + subst = ngx_rbtree_min(node->right, sentinel); - while (subst != sentinel && temp == subst->right) { - temp = subst; - subst = subst->parent; - } - + if (subst->left != sentinel) { + temp = subst->left; } else { - subst = ngx_rbtree_min(node->right, sentinel); + temp = subst->right; } } - if (subst->left != sentinel) { - temp = subst->left; - } else { - temp = subst->right; + if (subst == *root) { + /* it's the last node */ + *root = sentinel; + return; } - temp->parent = subst->parent; + red = ngx_rbt_is_red(subst); - if (subst->parent == sentinel) { - *root = temp; - - } else if (subst == subst->parent->left) { + if (subst == subst->parent->left) { subst->parent->left = temp; } else { subst->parent->right = temp; } - if (subst != node) { - node->key = subst->key; - node->color = subst->color; + if (subst == node) { + + temp->parent = subst->parent; + + } else { + + if (subst->parent == node) { + temp->parent = subst; + + } else { + temp->parent = subst->parent; + } + + subst->left = node->left; + subst->right = node->right; + subst->parent = node->parent; + ngx_rbt_copy_color(subst, node); + + if (node == *root) { + *root = subst; + + } else { + if (node == node->parent->left) { + node->parent->left = subst; + } else { + node->parent->right = subst; + } + } + + if (subst->left != sentinel) { + subst->left->parent = subst; + } + + if (subst->right != sentinel) { + subst->right->parent = subst; + } } - if (ngx_rbt_is_red(subst)) { + if (red) { return; } /* a delete fixup */ - while (temp->parent != sentinel && ngx_rbt_is_black(temp)) { + while (temp != *root && ngx_rbt_is_black(temp)) { + if (temp == temp->parent->left) { w = temp->parent->right; @@ -257,7 +286,7 @@ ngx_inline void ngx_rbtree_left_rotate(n temp->parent = node->parent; - if (node->parent == sentinel) { + if (node == *root) { *root = temp; } else if (node == node->parent->left) { @@ -287,7 +316,7 @@ ngx_inline void ngx_rbtree_right_rotate( temp->parent = node->parent; - if (node->parent == sentinel) { + if (node == *root) { *root = temp; } else if (node == node->parent->right) { diff --git a/src/event/ngx_event_accept.c b/src/event/ngx_event_accept.c --- a/src/event/ngx_event_accept.c +++ b/src/event/ngx_event_accept.c @@ -207,6 +207,7 @@ void ngx_event_accept(ngx_event_t *ev) * - atomic increment (x86: lock xadd) * or protection by critical section or mutex */ + c->number = ngx_connection_counter++; ngx_log_debug(ev->log, "accept: %d, %d" _ s _ c->number); diff --git a/src/event/ngx_event_timer.c b/src/event/ngx_event_timer.c --- a/src/event/ngx_event_timer.c +++ b/src/event/ngx_event_timer.c @@ -22,8 +22,11 @@ int ngx_event_timer_init(ngx_cycle_t *cy ngx_event_timer_rbtree = &ngx_event_timer_sentinel; ngx_event_timer_sentinel.left = &ngx_event_timer_sentinel; + +#if 0 ngx_event_timer_sentinel.right = &ngx_event_timer_sentinel; ngx_event_timer_sentinel.parent = &ngx_event_timer_sentinel; +#endif return NGX_OK; } diff --git a/src/http/ngx_http.c b/src/http/ngx_http.c --- a/src/http/ngx_http.c +++ b/src/http/ngx_http.c @@ -8,7 +8,16 @@ static char *ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); -int ngx_http_max_module; +int ngx_http_max_module; + +ngx_uint_t ngx_http_reading_state; +ngx_uint_t ngx_http_processing_state; +ngx_uint_t ngx_http_writing_state; +ngx_uint_t ngx_http_lingering_close_state; +ngx_uint_t ngx_http_keepalive_state; + +ngx_uint_t ngx_http_total_requests; +uint64_t ngx_http_total_sent; int (*ngx_http_top_header_filter) (ngx_http_request_t *r); diff --git a/src/http/ngx_http.h b/src/http/ngx_http.h --- a/src/http/ngx_http.h +++ b/src/http/ngx_http.h @@ -87,7 +87,17 @@ int ngx_http_discard_body(ngx_http_reque extern ngx_module_t ngx_http_module; -extern int ngx_max_module; +extern int ngx_max_module; + +extern ngx_uint_t ngx_http_reading_state; +extern ngx_uint_t ngx_http_processing_state; +extern ngx_uint_t ngx_http_writing_state; +extern ngx_uint_t ngx_http_lingering_close_state; +extern ngx_uint_t ngx_http_keepalive_state; + +extern ngx_uint_t ngx_http_total_requests; +extern uint64_t ngx_http_total_sent; + /* STUB */ diff --git a/src/http/ngx_http_request.c b/src/http/ngx_http_request.c --- a/src/http/ngx_http_request.c +++ b/src/http/ngx_http_request.c @@ -107,6 +107,8 @@ void ngx_http_init_connection(ngx_connec return; } #endif + + ngx_atomic_inc(ngx_http_reading_state); } @@ -127,6 +129,7 @@ static void ngx_http_init_request(ngx_ev if (rev->timedout) { ngx_log_error(NGX_LOG_INFO, c->log, NGX_ETIMEDOUT, "client timed out"); + ngx_atomic_dec(ngx_http_reading_state); ngx_http_close_connection(c); return; } @@ -1264,7 +1267,7 @@ static void ngx_http_set_lingering_close rev = c->read; rev->event_handler = ngx_http_lingering_close_handler; - r->lingering_time = ngx_time() + clcf->lingering_time / 1000; + r->lingering_time = ngx_cached_time + clcf->lingering_time / 1000; ngx_add_timer(rev, clcf->lingering_timeout); if (ngx_handle_level_read_event(rev) == NGX_ERROR) { @@ -1326,7 +1329,7 @@ static void ngx_http_lingering_close_han return; } - timer = r->lingering_time - ngx_time(); + timer = r->lingering_time - ngx_cached_time; if (timer <= 0) { ngx_http_close_request(r, 0); ngx_http_close_connection(c); diff --git a/src/os/unix/ngx_posix_init.c b/src/os/unix/ngx_posix_init.c --- a/src/os/unix/ngx_posix_init.c +++ b/src/os/unix/ngx_posix_init.c @@ -91,7 +91,6 @@ int ngx_posix_init(ngx_log_t *log) void ngx_signal_handler(int signo) { - char *name; ngx_signal_t *sig; for (sig = signals; sig->signo != 0; sig++) { @@ -100,11 +99,18 @@ void ngx_signal_handler(int signo) } } - /* STUB */ - name = strsignal(signo); +#if (HAVE_STRSIGNAL) + ngx_log_error(NGX_LOG_INFO, ngx_cycle->log, 0, "signal #%d (%s: %s) received, %s", - signo, sig->signame, name, sig->action); + signo, sig->signame, strsignal(signo), sig->action); +#else + + ngx_log_error(NGX_LOG_INFO, ngx_cycle->log, 0, + "signal #%d (%s) received, %s", + signo, sig->signame, sig->action); + +#endif switch (signo) {