From faca119aa5b2375d247c4948ba6791e7d8d2b8bc Mon Sep 17 00:00:00 2001 From: Igor Sysoev Date: Fri, 5 Dec 2003 07:11:46 +0000 Subject: [PATCH] nginx-0.0.1-2003-12-05-10:11:46 import --- auto/cc | 9 ++- auto/os/conf | 3 + src/core/ngx_rbtree.c | 11 ++- src/core/ngx_rbtree.h | 2 +- src/event/ngx_event.h | 120 +++++++++++++++++--------------- src/event/ngx_event_accept.c | 3 - src/event/ngx_event_timer.c | 9 +-- src/event/ngx_event_timer.h | 12 ++-- src/http/ngx_http_core_module.c | 6 ++ 9 files changed, 99 insertions(+), 76 deletions(-) diff --git a/auto/cc b/auto/cc index 1aadae34f..082b13f75 100644 --- a/auto/cc +++ b/auto/cc @@ -95,8 +95,13 @@ case $CC in # link flags CORE_LINK="$CORE_LINK -link" - CORE_LINK="$CORE_LINK -nodefaultlib:msvcrt" - CORE_LINK="$CORE_LINK -nodefaultlib:libcpmt" + + # msvcrt.dll + CORE_LINK="$CORE_LINK -nodefaultlib:libcmt" + + # static libc + #CORE_LINK="$CORE_LINK -nodefaultlib:msvcrt" + CORE_LINK="$CORE_LINK -verbose:lib" # debug diff --git a/auto/os/conf b/auto/os/conf index d0eb7876d..f0d25b647 100644 --- a/auto/os/conf +++ b/auto/os/conf @@ -35,6 +35,9 @@ case $PLATFORM in CFLAGS="$CFLAGS -D HAVE_AIO=1 -D HAVE_IOCP=1" CORE_LIBS="$CORE_LIBS ws2_32.lib" + + # msvcrt.dll + CORE_LIBS="$CORE_LIBS msvcrt.lib" ;; esac diff --git a/src/core/ngx_rbtree.c b/src/core/ngx_rbtree.c index 2bc4650f0..ea78e2254 100644 --- a/src/core/ngx_rbtree.c +++ b/src/core/ngx_rbtree.c @@ -8,12 +8,11 @@ * to Algorithms" by Cormen, Leiserson and Rivest. */ -#define ngx_rbt_red(node) ((uintptr_t) (node)->data |= 1) -#define ngx_rbt_black(node) ((uintptr_t) (node)->data &= ~1) -#define ngx_rbt_is_red(node) ((uintptr_t) (node)->data & 1) +#define ngx_rbt_red(node) ((node)->color = 1) +#define ngx_rbt_black(node) ((node)->color = 0) +#define ngx_rbt_is_red(node) ((node)->color) #define ngx_rbt_is_black(node) (!ngx_rbt_is_red(node)) -#define ngx_rbt_copy_color(n1, n2) \ - ((uintptr_t) (n1)->data |= (uintptr_t) (n2)->data & 1) +#define ngx_rbt_copy_color(n1, n2) (n1->color = n2->color) ngx_inline void ngx_rbtree_left_rotate(ngx_rbtree_t **root, ngx_rbtree_t *node); @@ -166,7 +165,7 @@ void ngx_rbtree_delete(ngx_rbtree_t **root, ngx_rbtree_t *node) if (subst != node) { node->key = subst->key; - node->data = subst->data; + node->color = subst->color; } if (ngx_rbt_is_red(subst)) { diff --git a/src/core/ngx_rbtree.h b/src/core/ngx_rbtree.h index de6fef904..af0f2ec37 100644 --- a/src/core/ngx_rbtree.h +++ b/src/core/ngx_rbtree.h @@ -13,7 +13,7 @@ struct ngx_rbtree_s { ngx_rbtree_t *left; ngx_rbtree_t *right; ngx_rbtree_t *parent; - void *data; + char color; }; extern ngx_rbtree_t sentinel; diff --git a/src/event/ngx_event.h b/src/event/ngx_event.h index 1454cdb7c..71b280799 100644 --- a/src/event/ngx_event.h +++ b/src/event/ngx_event.h @@ -31,8 +31,6 @@ struct ngx_event_s { ngx_event_t *prev; ngx_event_t *next; - ngx_rbtree_t rbtree; - #if 0 ngx_event_t *timer_prev; ngx_event_t *timer_next; @@ -42,6 +40,69 @@ struct ngx_event_s { ngx_log_t *log; + /* + * ngx_rbtree_t rbtree; + */ + + ngx_int_t rbtree_key; + void *rbtree_left; + void *rbtree_right; + void *rbtree_parent; + char rbtree_color; + + unsigned char oneshot:1; + + unsigned char write:1; + + /* used to detect the stale events in kqueue, rt signals and epoll */ + unsigned char instance:1; + + /* + * the event was passed or would be passed to a kernel; + * in aio mode - operation was posted. + */ + unsigned char active:1; + + /* the ready event; in aio mode 0 means that no operation can be posted */ + unsigned char ready:1; + + /* aio operation is complete */ + unsigned char complete:1; + + unsigned char eof:1; + unsigned char error:1; + + unsigned short timedout:1; + unsigned short timer_set:1; + + unsigned short delayed:1; + + unsigned short read_discarded:1; + + unsigned short ignore_econnreset:1; + unsigned short unexpected_eof:1; + + unsigned short deferred_accept:1; + + /* TODO: aio_eof and kq_eof can be the single pending_eof */ + /* the pending eof in aio chain operation */ + unsigned short aio_eof:1; + + /* the pending eof reported by kqueue */ + unsigned short kq_eof:1; + +#if (WIN32) + /* setsockopt(SO_UPDATE_ACCEPT_CONTEXT) was succesfull */ + unsigned short accept_context_updated:1; +#endif + +#if (HAVE_KQUEUE) + unsigned short kq_vnode:1; + + /* the pending errno reported by kqueue */ + int kq_errno; +#endif + /* * kqueue only: * accept: number of sockets that wait to be accepted @@ -57,60 +118,7 @@ struct ngx_event_s { #if (HAVE_KQUEUE) int available; #else - unsigned available:1; -#endif - - unsigned oneshot:1; - - unsigned write:1; - - /* used to detect the stale events in kqueue, rt signals and epoll */ - unsigned instance:1; - - /* - * the event was passed or would be passed to a kernel; - * in aio mode - operation was posted. - */ - unsigned active:1; - - /* the ready event; in aio mode 0 means that no operation can be posted */ - unsigned ready:1; - - /* aio operation is complete */ - unsigned complete:1; - - unsigned eof:1; - unsigned error:1; - - unsigned timedout:1; - unsigned timer_set:1; - - unsigned delayed:1; - - unsigned read_discarded:1; - - unsigned ignore_econnreset:1; - unsigned unexpected_eof:1; - - unsigned deferred_accept:1; - - /* TODO: aio_eof and kq_eof can be the single pending_eof */ - /* the pending eof in aio chain operation */ - unsigned aio_eof:1; - - /* the pending eof reported by kqueue */ - unsigned kq_eof:1; - -#if (WIN32) - /* setsockopt(SO_UPDATE_ACCEPT_CONTEXT) was succesfull */ - unsigned accept_context_updated:1; -#endif - -#if (HAVE_KQUEUE) - unsigned kq_vnode:1; - - /* the pending errno reported by kqueue */ - int kq_errno; + unsigned short available:1; #endif diff --git a/src/event/ngx_event_accept.c b/src/event/ngx_event_accept.c index bba5aa55f..ea63724e9 100644 --- a/src/event/ngx_event_accept.c +++ b/src/event/ngx_event_accept.c @@ -175,9 +175,6 @@ void ngx_event_accept(ngx_event_t *ev) rev->index = NGX_INVALID_INDEX; wev->index = NGX_INVALID_INDEX; - rev->rbtree.data = rev; - wev->rbtree.data = wev; - rev->data = c; wev->data = c; diff --git a/src/event/ngx_event_timer.c b/src/event/ngx_event_timer.c index 296c748ee..db97d01fc 100644 --- a/src/event/ngx_event_timer.c +++ b/src/event/ngx_event_timer.c @@ -23,7 +23,7 @@ void ngx_event_timer_done(ngx_cycle_t *cycle) } -int ngx_event_find_timer(void) +ngx_msec_t ngx_event_find_timer(void) { ngx_rbtree_t *node; @@ -33,7 +33,8 @@ int ngx_event_find_timer(void) return 0; } else { - return node->key * NGX_TIMER_RESOLUTION - ngx_elapsed_msec; + return (ngx_msec_t) + (node->key * NGX_TIMER_RESOLUTION - ngx_elapsed_msec); } } @@ -50,11 +51,11 @@ void ngx_event_expire_timers(ngx_msec_t timer) break; } - if ((ngx_msec_t) node->key <= + if ((ngx_msec_t) node->key <= (ngx_msec_t) (ngx_elapsed_msec + timer) / NGX_TIMER_RESOLUTION) { ev = (ngx_event_t *) - ((char *) node - offsetof(ngx_event_t, rbtree)); + ((char *) node - offsetof(ngx_event_t, rbtree_key)); ngx_del_timer(ev); diff --git a/src/event/ngx_event_timer.h b/src/event/ngx_event_timer.h index ea8105ee3..0985cf1ad 100644 --- a/src/event/ngx_event_timer.h +++ b/src/event/ngx_event_timer.h @@ -8,6 +8,8 @@ /* + * 32 bit key value resolution + * * 1 msec - 49 days * 10 msec - 1 years 4 months * 50 msec - 6 years 10 months @@ -19,7 +21,7 @@ int ngx_event_timer_init(ngx_cycle_t *cycle); void ngx_event_timer_done(ngx_cycle_t *cycle); -int ngx_event_find_timer(void); +ngx_msec_t ngx_event_find_timer(void); void ngx_event_expire_timers(ngx_msec_t timer); #if 0 @@ -37,7 +39,8 @@ extern ngx_rbtree_t *ngx_event_timer_rbtree; ngx_inline static void ngx_event_del_timer(ngx_event_t *ev) { - ngx_rbtree_delete(&ngx_event_timer_rbtree, &ev->rbtree); + ngx_rbtree_delete(&ngx_event_timer_rbtree, + (ngx_rbtree_t *) &ev->rbtree_key); ev->timer_set = 0; } @@ -49,10 +52,11 @@ ngx_inline static void ngx_event_add_timer(ngx_event_t *ev, ngx_msec_t timer) ngx_del_timer(ev); } - ev->rbtree.key = (ngx_int_t) + ev->rbtree_key = (ngx_int_t) (ngx_elapsed_msec + timer) / NGX_TIMER_RESOLUTION; - ngx_rbtree_insert(&ngx_event_timer_rbtree, &ev->rbtree); + ngx_rbtree_insert(&ngx_event_timer_rbtree, + (ngx_rbtree_t *) &ev->rbtree_key); ev->timer_set = 1; } diff --git a/src/http/ngx_http_core_module.c b/src/http/ngx_http_core_module.c index 547e028e5..3046ca882 100644 --- a/src/http/ngx_http_core_module.c +++ b/src/http/ngx_http_core_module.c @@ -514,7 +514,13 @@ ngx_log_debug(r->connection->log, "trans: %s: %d" _ } if (clcf->handler) { + /* + * if the location already has content handler then skip + * the translation phase + */ + r->content_handler = clcf->handler; + r->phase++; } return NGX_OK;