nginx-0.0.1-2003-12-19-11:15:11 import

This commit is contained in:
Igor Sysoev 2003-12-19 08:15:11 +00:00
parent e3466a4058
commit e89c4581f4
14 changed files with 148 additions and 44 deletions

View File

@ -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

View File

@ -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"

View File

@ -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" ;;

View File

@ -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)"

View File

@ -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++) {

13
src/core/ngx_atomic.h Normal file
View File

@ -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_ */

View File

@ -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>

View File

@ -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 if (node->right == sentinel) {
temp = node->left;
subst = node;
} else {
subst = ngx_rbtree_min(node->right, sentinel);
/* find a node successor */
if (node->right == sentinel) {
temp = node;
subst = node->parent;
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(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) {

View File

@ -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);

View File

@ -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;
}

View File

@ -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);

View File

@ -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 */

View File

@ -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);

View File

@ -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) {