Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nginx/nginx.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIgor Sysoev <igor@sysoev.ru>2003-12-19 11:15:11 +0300
committerIgor Sysoev <igor@sysoev.ru>2003-12-19 11:15:11 +0300
commite89c4581f4706187052671a8a40dda4fe3e3c391 (patch)
tree3644c7b95ae7ed7b62d830c62e452b632ac9e89b
parente3466a4058ec3a6c7915f5239fac9f6bfbb6a29d (diff)
nginx-0.0.1-2003-12-19-11:15:11 import
-rw-r--r--auto/lib/conf5
-rw-r--r--auto/sources7
-rw-r--r--auto/summary6
-rwxr-xr-xauto/unix6
-rw-r--r--src/core/nginx.c13
-rw-r--r--src/core/ngx_atomic.h13
-rw-r--r--src/core/ngx_core.h3
-rw-r--r--src/core/ngx_rbtree.c91
-rw-r--r--src/event/ngx_event_accept.c1
-rw-r--r--src/event/ngx_event_timer.c3
-rw-r--r--src/http/ngx_http.c11
-rw-r--r--src/http/ngx_http.h12
-rw-r--r--src/http/ngx_http_request.c7
-rw-r--r--src/os/unix/ngx_posix_init.c14
14 files changed, 148 insertions, 44 deletions
diff --git a/auto/lib/conf b/auto/lib/conf
index b5271a225..0739a72d4 100644
--- 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
index 1e8790fd9..b2eec4426 100644
--- 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
index 19afd04b1..28fe5f5d5 100644
--- 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
index 09115f59d..4fd44f46a 100755
--- 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 <string.h>"
+ngx_func_test="char *s = strsignal(1)"
+. auto/func
+
+
ngx_func="strerror_r()"
ngx_func_inc="#include <string.h>"
ngx_func_test="char buf[20]; strerror_r(1, buf, 20)"
diff --git a/src/core/nginx.c b/src/core/nginx.c
index 36a8b4bd8..7deb24fd3 100644
--- 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
index 000000000..b24a997c4
--- /dev/null
+++ b/src/core/ngx_atomic.h
@@ -0,0 +1,13 @@
+#ifndef _NGX_ATOMIC_H_INCLUDED_
+#define _NGX_ATOMIC_H_INCLUDED_
+
+
+#include <ngx_config.h>
+#include <ngx_core.h>
+
+
+#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
index b2c3d554d..75658bacb 100644
--- a/src/core/ngx_core.h
+++ b/src/core/ngx_core.h
@@ -15,6 +15,7 @@ typedef struct ngx_event_s ngx_event_t;
typedef struct ngx_connection_s ngx_connection_t;
+#include <ngx_atomic.h>
#include <ngx_time.h>
#include <ngx_socket.h>
#include <ngx_errno.h>
@@ -30,7 +31,9 @@ typedef struct ngx_connection_s ngx_connection_t;
#include <ngx_file.h>
#include <ngx_files.h>
#include <ngx_crc.h>
+#if (HAVE_PCRE)
#include <ngx_regex.h>
+#endif
#include <ngx_rbtree.h>
#include <ngx_times.h>
#include <ngx_inet.h>
diff --git a/src/core/ngx_rbtree.c b/src/core/ngx_rbtree.c
index 3e6025f12..dc605510e 100644
--- a/src/core/ngx_rbtree.c
+++ b/src/core/ngx_rbtree.c
@@ -31,7 +31,7 @@ void ngx_rbtree_insert(ngx_rbtree_t **root, ngx_rbtree_t *sentinel,
/* 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 **root, ngx_rbtree_t *sentinel,
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 **root, ngx_rbtree_t *sentinel,
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 {
-
- /* find a node successor */
-
- if (node->right == sentinel) {
- temp = node;
- subst = node->parent;
+ } else if (node->right == sentinel) {
+ temp = node->left;
+ subst = node;
- while (subst != sentinel && temp == subst->right) {
- temp = subst;
- subst = subst->parent;
- }
+ } else {
+ subst = ngx_rbtree_min(node->right, sentinel);
+ 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(ngx_rbtree_t **root,
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(ngx_rbtree_t **root,
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
index 9a08e00f5..a5a130fde 100644
--- 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
index 4ed9498b3..416cb13f0 100644
--- 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 *cycle)
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
index 91fa2310b..592e1b6ca 100644
--- 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
index 58d918b36..954f695b2 100644
--- a/src/http/ngx_http.h
+++ b/src/http/ngx_http.h
@@ -87,7 +87,17 @@ int ngx_http_discard_body(ngx_http_request_t *r);
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
index 66bf9be47..c484d277b 100644
--- a/src/http/ngx_http_request.c
+++ b/src/http/ngx_http_request.c
@@ -107,6 +107,8 @@ void ngx_http_init_connection(ngx_connection_t *c)
return;
}
#endif
+
+ ngx_atomic_inc(ngx_http_reading_state);
}
@@ -127,6 +129,7 @@ static void ngx_http_init_request(ngx_event_t *rev)
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(ngx_http_request_t *r)
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_handler(ngx_event_t *rev)
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
index 9ebc3d17c..5ae5c7346 100644
--- 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) {