changeset 346:55e496a8ece3

nginx-0.0.3-2004-06-06-23:49:18 import
author Igor Sysoev <igor@sysoev.ru>
date Sun, 06 Jun 2004 19:49:18 +0000
parents fade4edd61f8
children f48d579daf78
files auto/cc auto/sources auto/unix src/core/ngx_alloc.c src/core/ngx_alloc.h src/core/ngx_config.h src/core/ngx_connection.c src/core/ngx_connection.h src/core/ngx_core.h src/core/ngx_palloc.c src/core/ngx_palloc.h src/event/modules/ngx_rtsig_module.c src/event/ngx_event.c src/event/ngx_event.h src/event/ngx_event_accept.c src/http/modules/ngx_http_charset_filter.c src/http/modules/ngx_http_gzip_filter.c src/http/modules/ngx_http_range_filter.c src/http/modules/ngx_http_static_handler.c src/http/ngx_http.h src/http/ngx_http_copy_filter.c src/http/ngx_http_core_module.c src/http/ngx_http_core_module.h src/http/ngx_http_filter.h src/http/ngx_http_request.c src/http/ngx_http_request.h src/os/unix/ngx_alloc.c src/os/unix/ngx_alloc.h src/os/unix/ngx_freebsd_rfork_thread.c src/os/unix/ngx_posix_init.c src/os/unix/ngx_socket.c src/os/unix/ngx_time.h src/os/win32/ngx_alloc.c src/os/win32/ngx_alloc.h src/os/win32/ngx_win32_init.c
diffstat 35 files changed, 533 insertions(+), 335 deletions(-) [+]
line wrap: on
line diff
--- a/auto/cc	Fri Jun 04 14:57:33 2004 +0000
+++ b/auto/cc	Sun Jun 06 19:49:18 2004 +0000
@@ -5,7 +5,7 @@
 
     *gcc*)
          # gcc 2.7.2.3, 2.8.1, 2.95.4,
-         #     3.2.3, 3.3.2, 3.3.3, 3.3.4, 3.4
+         #     3.0.4, 3.1.1, 3.2.3, 3.3.2, 3.3.3, 3.3.4, 3.4
 
          # optimization
          #CFLAGS="$CFLAGS -O2 -fomit-frame-pointer"
--- a/auto/sources	Fri Jun 04 14:57:33 2004 +0000
+++ b/auto/sources	Sun Jun 06 19:49:18 2004 +0000
@@ -8,7 +8,7 @@
             src/core/ngx_core.h \
             src/core/ngx_atomic.h \
             src/core/ngx_log.h \
-            src/core/ngx_alloc.h \
+            src/core/ngx_palloc.h \
             src/core/ngx_array.h \
             src/core/ngx_table.h \
             src/core/ngx_buf.h \
@@ -27,7 +27,7 @@
 
 CORE_SRCS="src/core/nginx.c \
             src/core/ngx_log.c \
-            src/core/ngx_alloc.c \
+            src/core/ngx_palloc.c \
             src/core/ngx_array.c \
             src/core/ngx_buf.c \
             src/core/ngx_output_chain.c \
@@ -103,6 +103,7 @@
             src/os/unix/ngx_time.h \
             src/os/unix/ngx_types.h \
             src/os/unix/ngx_errno.h \
+            src/os/unix/ngx_alloc.h \
             src/os/unix/ngx_files.h \
             src/os/unix/ngx_process.h \
             src/os/unix/ngx_thread.h \
@@ -113,6 +114,7 @@
 UNIX_SRCS="$CORE_SRCS $EVENT_SRCS \
             src/os/unix/ngx_time.c \
             src/os/unix/ngx_errno.c \
+            src/os/unix/ngx_alloc.c \
             src/os/unix/ngx_files.c \
             src/os/unix/ngx_socket.c \
             src/os/unix/ngx_recv.c \
@@ -146,6 +148,7 @@
             src/os/win32/ngx_time.h \
             src/os/win32/ngx_types.h \
             src/os/win32/ngx_errno.h \
+            src/os/win32/ngx_alloc.h \
             src/os/win32/ngx_files.h \
             src/os/win32/ngx_process.h \
             src/os/win32/ngx_socket.h \
@@ -156,6 +159,7 @@
 
 WIN32_SRCS="$CORE_SRCS $EVENT_SRCS \
             src/os/win32/ngx_errno.c \
+            src/os/win32/ngx_alloc.c \
             src/os/win32/ngx_files.c \
             src/os/win32/ngx_time.c \
             src/os/win32/ngx_process.c \
@@ -194,7 +198,6 @@
 
 HTTP_DEPS="src/http/ngx_http.h \
             src/http/ngx_http_request.h \
-            src/http/ngx_http_filter.h \
             src/http/ngx_http_config.h \
             src/http/ngx_http_core_module.h \
             src/http/ngx_http_cache.h \
--- a/auto/unix	Fri Jun 04 14:57:33 2004 +0000
+++ b/auto/unix	Sun Jun 06 19:49:18 2004 +0000
@@ -110,3 +110,15 @@
 ngx_func_inc="#include <time.h>"
 ngx_func_test="struct tm t; time_t c=0; localtime_r(&c, &t)"
 . auto/func
+
+
+ngx_func="posix_memalign()"
+ngx_func_inc="#include <stdlib.h>"
+ngx_func_test="void *p, int n; n = posix_memalign(&p, 4096, 4096)"
+. auto/func
+
+
+ngx_func="memalign()"
+ngx_func_inc="#include <stdlib.h>"
+ngx_func_test="void *p; p = memalign(4096, 4096)"
+. auto/func
--- a/src/core/ngx_alloc.c	Fri Jun 04 14:57:33 2004 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,200 +0,0 @@
-
-#include <ngx_config.h>
-#include <ngx_core.h>
-
-
-void *ngx_alloc(size_t size, ngx_log_t *log)
-{
-    void  *p;
-
-    if (!(p = malloc(size))) {
-        ngx_log_error(NGX_LOG_EMERG, log, ngx_errno,
-                      "malloc() " SIZE_T_FMT " bytes failed", size);
-    }
-
-    ngx_log_debug2(NGX_LOG_DEBUG_ALLOC, log, 0,
-                   "malloc: " PTR_FMT ":" SIZE_T_FMT, p, size);
-
-    return p;
-}
-
-
-void *ngx_calloc(size_t size, ngx_log_t *log)
-{
-    void  *p;
-
-    p = ngx_alloc(size, log);
-    if (p) {
-        ngx_memzero(p, size);
-    }
-
-    return p;
-}
-
-
-ngx_pool_t *ngx_create_pool(size_t size, ngx_log_t *log)
-{
-    ngx_pool_t  *p;
-
-    if (!(p = ngx_alloc(size, log))) {
-       return NULL;
-    }
-
-    p->last = (char *) p + sizeof(ngx_pool_t);
-    p->end = (char *) p + size;
-    p->next = NULL;
-    p->large = NULL;
-    p->log = log;
-
-    return p;
-}
-
-
-void ngx_destroy_pool(ngx_pool_t *pool)
-{
-    ngx_pool_t        *p, *n;
-    ngx_pool_large_t  *l;
-
-    for (l = pool->large; l; l = l->next) {
-
-        ngx_log_debug1(NGX_LOG_DEBUG_ALLOC, pool->log, 0,
-                       "free: " PTR_FMT, l->alloc);
-
-        if (l->alloc) {
-            free(l->alloc);
-        }
-    }
-
-#if (NGX_DEBUG)
-
-    /*
-     * we could allocate the pool->log from this pool
-     * so we can not use this log while the free()ing the pool
-     */
-
-    for (p = pool, n = pool->next; /* void */; p = n, n = n->next) {
-        ngx_log_debug1(NGX_LOG_DEBUG_ALLOC, pool->log, 0,
-                       "free: " PTR_FMT, p);
-
-        if (n == NULL) {
-            break;
-        }
-    }
-
-#endif
-
-    for (p = pool, n = pool->next; /* void */; p = n, n = n->next) {
-        free(p);
-
-        if (n == NULL) {
-            break;
-        }
-    }
-}
-
-
-void *ngx_palloc(ngx_pool_t *pool, size_t size)
-{
-    char              *m;
-    ngx_pool_t        *p, *n;
-    ngx_pool_large_t  *large, *last;
-
-    if (size <= NGX_MAX_ALLOC_FROM_POOL) {
-
-        for (p = pool, n = pool->next; /* void */; p = n, n = n->next) {
-            m = ngx_align(p->last);
-
-            if ((size_t) (p->end - m) >= size) {
-                p->last = m + size ;
-
-                return m;
-            }
-
-            if (n == NULL) {
-                break;
-            }
-        }
-
-        /* alloc a new pool block */
-
-        if (!(n = ngx_create_pool((size_t) (p->end - (char *) p), p->log))) {
-            return NULL;
-        }
-
-        p->next = n;
-        m = n->last;
-        n->last += size;
-
-        return m;
-    }
-
-    /* alloc a large block */
-
-    large = NULL;
-    last = NULL;
-
-    if (pool->large) {
-        for (last = pool->large; /* void */; last = last->next) {
-            if (last->alloc == NULL) {
-                large = last;
-                last = NULL;
-                break;
-            }
-
-            if (last->next == NULL) {
-                break;
-            }
-        }
-    }
-
-    if (large == NULL) {
-        if (!(large = ngx_palloc(pool, sizeof(ngx_pool_large_t)))) {
-            return NULL;
-        }
-
-        large->next = NULL;
-    }
-
-    if (!(p = ngx_alloc(size, pool->log))) {
-        return NULL;
-    }
-
-    if (pool->large == NULL) {
-        pool->large = large;
-
-    } else if (last) {
-        last->next = large;
-    }
-
-    large->alloc = p;
-
-    return p;
-}
-
-
-void ngx_pfree(ngx_pool_t *pool, void *p)
-{
-    ngx_pool_large_t  *l;
-
-    for (l = pool->large; l; l = l->next) {
-        if (p == l->alloc) {
-            ngx_log_debug1(NGX_LOG_DEBUG_ALLOC, pool->log, 0,
-                           "free: " PTR_FMT, l->alloc);
-            free(l->alloc);
-            l->alloc = NULL;
-        }
-    }
-}
-
-
-void *ngx_pcalloc(ngx_pool_t *pool, size_t size)
-{
-    void *p;
-
-    p = ngx_palloc(pool, size);
-    if (p) {
-        ngx_memzero(p, size);
-    }
-
-    return p;
-}
--- a/src/core/ngx_alloc.h	Fri Jun 04 14:57:33 2004 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,54 +0,0 @@
-#ifndef _NGX_ALLOC_H_INCLUDED_
-#define _NGX_ALLOC_H_INCLUDED_
-
-
-#include <ngx_config.h>
-#include <ngx_core.h>
-
-
-/*
- * NGX_MAX_ALLOC_FROM_POOL should be (NGX_PAGE_SIZE - 1), i.e. 4095 on x86.
- * On FreeBSD 5.x it allows to use zero copy send.
- * On Windows NT it decreases a number of locked pages in a kernel.
- */
-#define NGX_MAX_ALLOC_FROM_POOL 4095
-
-#define NGX_DEFAULT_POOL_SIZE   (16 * 1024)
-
-#define ngx_test_null(p, alloc, rc)  if ((p = alloc) == NULL) { return rc; }
-
-
-typedef struct ngx_pool_large_s  ngx_pool_large_t;
-
-struct ngx_pool_large_s {
-    ngx_pool_large_t  *next;
-    void              *alloc;
-};
-
-
-typedef struct ngx_pool_s        ngx_pool_t;
-
-struct ngx_pool_s {
-    char              *last;
-    char              *end;
-    ngx_pool_t        *next;
-    ngx_pool_large_t  *large;
-    ngx_log_t         *log;
-};
-
-
-void *ngx_alloc(size_t size, ngx_log_t *log);
-void *ngx_calloc(size_t size, ngx_log_t *log);
-
-ngx_pool_t *ngx_create_pool(size_t size, ngx_log_t *log);
-void ngx_destroy_pool(ngx_pool_t *pool);
-
-void *ngx_palloc(ngx_pool_t *pool, size_t size);
-void *ngx_pcalloc(ngx_pool_t *pool, size_t size);
-void ngx_pfree(ngx_pool_t *pool, void *p);
-
-
-#define ngx_free   free
-
-
-#endif /* _NGX_ALLOC_H_INCLUDED_ */
--- a/src/core/ngx_config.h	Fri Jun 04 14:57:33 2004 +0000
+++ b/src/core/ngx_config.h	Sun Jun 06 19:49:18 2004 +0000
@@ -40,19 +40,9 @@
 /* STUB: autoconf */
 typedef int    ngx_int_t;
 typedef u_int  ngx_uint_t;
-
-
 typedef int    ngx_flag_t;
 
 
-#ifndef NGX_SERVER_ROOT
-#define NGX_SERVER_ROOT   "./"
-#if 0
-#define NGX_SERVER_ROOT   "/usr/local/nginx/"
-#endif
-#endif
-
-
 #if !(WIN32)
 
 #define ngx_signal_helper(n)     SIG##n
--- a/src/core/ngx_connection.c	Fri Jun 04 14:57:33 2004 +0000
+++ b/src/core/ngx_connection.c	Sun Jun 06 19:49:18 2004 +0000
@@ -228,7 +228,7 @@
         fd /= 4;
 #endif
 
-        if (ngx_event_flags & NGX_USE_SIGIO_EVENT) {
+        if (ngx_event_flags & NGX_USE_RTSIG_EVENT) {
             if (cycle->connections[fd].read->active) {
                 ngx_del_conn(&cycle->connections[fd], NGX_CLOSE_EVENT);
             }
--- a/src/core/ngx_connection.h	Fri Jun 04 14:57:33 2004 +0000
+++ b/src/core/ngx_connection.h	Sun Jun 06 19:49:18 2004 +0000
@@ -103,6 +103,7 @@
 
     unsigned          pipeline:1;
     unsigned          unexpected_eof:1;
+    unsigned          timedout:1;
     signed            tcp_nopush:2;
 #if (HAVE_IOCP)
     unsigned          accept_context_updated:1;
--- a/src/core/ngx_core.h	Fri Jun 04 14:57:33 2004 +0000
+++ b/src/core/ngx_core.h	Sun Jun 06 19:49:18 2004 +0000
@@ -26,6 +26,7 @@
 #include <ngx_parse.h>
 #include <ngx_log.h>
 #include <ngx_alloc.h>
+#include <ngx_palloc.h>
 #include <ngx_buf.h>
 #include <ngx_array.h>
 #include <ngx_table.h>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/core/ngx_palloc.c	Sun Jun 06 19:49:18 2004 +0000
@@ -0,0 +1,198 @@
+
+#include <ngx_config.h>
+#include <ngx_core.h>
+
+
+ngx_pool_t *ngx_create_pool(size_t size, ngx_log_t *log)
+{
+    ngx_pool_t  *p;
+
+    if (!(p = ngx_alloc(size, log))) {
+       return NULL;
+    }
+
+    p->last = (char *) p + sizeof(ngx_pool_t);
+    p->end = (char *) p + size;
+    p->next = NULL;
+    p->large = NULL;
+    p->log = log;
+
+    return p;
+}
+
+
+void ngx_destroy_pool(ngx_pool_t *pool)
+{
+    ngx_pool_t        *p, *n;
+    ngx_pool_large_t  *l;
+
+    for (l = pool->large; l; l = l->next) {
+
+        ngx_log_debug1(NGX_LOG_DEBUG_ALLOC, pool->log, 0,
+                       "free: " PTR_FMT, l->alloc);
+
+        if (l->alloc) {
+            free(l->alloc);
+        }
+    }
+
+#if (NGX_DEBUG)
+
+    /*
+     * we could allocate the pool->log from this pool
+     * so we can not use this log while the free()ing the pool
+     */
+
+    for (p = pool, n = pool->next; /* void */; p = n, n = n->next) {
+        ngx_log_debug1(NGX_LOG_DEBUG_ALLOC, pool->log, 0,
+                       "free: " PTR_FMT, p);
+
+        if (n == NULL) {
+            break;
+        }
+    }
+
+#endif
+
+    for (p = pool, n = pool->next; /* void */; p = n, n = n->next) {
+        free(p);
+
+        if (n == NULL) {
+            break;
+        }
+    }
+}
+
+
+void *ngx_palloc(ngx_pool_t *pool, size_t size)
+{
+    char              *m;
+    ngx_pool_t        *p, *n;
+    ngx_pool_large_t  *large, *last;
+
+    if (size <= (size_t) NGX_MAX_ALLOC_FROM_POOL) {
+
+        for (p = pool, n = pool->next; /* void */; p = n, n = n->next) {
+            m = ngx_align(p->last);
+
+            if ((size_t) (p->end - m) >= size) {
+                p->last = m + size ;
+
+                return m;
+            }
+
+            if (n == NULL) {
+                break;
+            }
+        }
+
+        /* alloc a new pool block */
+
+        if (!(n = ngx_create_pool((size_t) (p->end - (char *) p), p->log))) {
+            return NULL;
+        }
+
+        p->next = n;
+        m = n->last;
+        n->last += size;
+
+        return m;
+    }
+
+    /* alloc a large block */
+
+    large = NULL;
+    last = NULL;
+
+    if (pool->large) {
+        for (last = pool->large; /* void */; last = last->next) {
+            if (last->alloc == NULL) {
+                large = last;
+                last = NULL;
+                break;
+            }
+
+            if (last->next == NULL) {
+                break;
+            }
+        }
+    }
+
+    if (large == NULL) {
+        if (!(large = ngx_palloc(pool, sizeof(ngx_pool_large_t)))) {
+            return NULL;
+        }
+
+        large->next = NULL;
+    }
+
+    if (!(p = ngx_memalign(ngx_pagesize, size, pool->log))) {
+        return NULL;
+    }
+
+    if (pool->large == NULL) {
+        pool->large = large;
+
+    } else if (last) {
+        last->next = large;
+    }
+
+    large->alloc = p;
+
+    return p;
+}
+
+
+void ngx_pfree(ngx_pool_t *pool, void *p)
+{
+    ngx_pool_large_t  *l;
+
+    for (l = pool->large; l; l = l->next) {
+        if (p == l->alloc) {
+            ngx_log_debug1(NGX_LOG_DEBUG_ALLOC, pool->log, 0,
+                           "free: " PTR_FMT, l->alloc);
+            free(l->alloc);
+            l->alloc = NULL;
+        }
+    }
+}
+
+
+void *ngx_pcalloc(ngx_pool_t *pool, size_t size)
+{
+    void *p;
+
+    p = ngx_palloc(pool, size);
+    if (p) {
+        ngx_memzero(p, size);
+    }
+
+    return p;
+}
+
+#if 0
+
+static void *ngx_get_cached_block(size_t size)
+{
+    void                     *p;
+    ngx_cached_block_slot_t  *slot;
+
+    if (ngx_cycle->cache == NULL) {
+        return NULL;
+    }
+
+    slot = &ngx_cycle->cache[(size + ngx_pagesize - 1) / ngx_pagesize];
+
+    slot->tries++;
+
+    if (slot->number) {
+        p = slot->block;
+        slot->block = slot->block->next;
+        slot->number--;
+        return p;
+    }
+
+    return NULL;
+}
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/core/ngx_palloc.h	Sun Jun 06 19:49:18 2004 +0000
@@ -0,0 +1,51 @@
+#ifndef _NGX_PALLOC_H_INCLUDED_
+#define _NGX_PALLOC_H_INCLUDED_
+
+
+#include <ngx_config.h>
+#include <ngx_core.h>
+
+
+/*
+ * NGX_MAX_ALLOC_FROM_POOL should be (ngx_page_size - 1), i.e. 4095 on x86.
+ * On FreeBSD 5.x it allows to use zero copy send.
+ * On Windows NT it decreases a number of locked pages in a kernel.
+ */
+#define NGX_MAX_ALLOC_FROM_POOL  (ngx_pagesize - 1)
+
+#define NGX_DEFAULT_POOL_SIZE   (16 * 1024)
+
+#define ngx_test_null(p, alloc, rc)  if ((p = alloc) == NULL) { return rc; }
+
+
+typedef struct ngx_pool_large_s  ngx_pool_large_t;
+
+struct ngx_pool_large_s {
+    ngx_pool_large_t  *next;
+    void              *alloc;
+};
+
+
+typedef struct ngx_pool_s        ngx_pool_t;
+
+struct ngx_pool_s {
+    char              *last;
+    char              *end;
+    ngx_pool_t        *next;
+    ngx_pool_large_t  *large;
+    ngx_log_t         *log;
+};
+
+
+void *ngx_alloc(size_t size, ngx_log_t *log);
+void *ngx_calloc(size_t size, ngx_log_t *log);
+
+ngx_pool_t *ngx_create_pool(size_t size, ngx_log_t *log);
+void ngx_destroy_pool(ngx_pool_t *pool);
+
+void *ngx_palloc(ngx_pool_t *pool, size_t size);
+void *ngx_pcalloc(ngx_pool_t *pool, size_t size);
+void ngx_pfree(ngx_pool_t *pool, void *p);
+
+
+#endif /* _NGX_PALLOC_H_INCLUDED_ */
--- a/src/event/modules/ngx_rtsig_module.c	Fri Jun 04 14:57:33 2004 +0000
+++ b/src/event/modules/ngx_rtsig_module.c	Sun Jun 06 19:49:18 2004 +0000
@@ -114,7 +114,7 @@
 
     ngx_event_actions = ngx_rtsig_module_ctx.actions;
 
-    ngx_event_flags = NGX_USE_SIGIO_EVENT
+    ngx_event_flags = NGX_USE_RTSIG_EVENT
                       |NGX_HAVE_GREEDY_EVENT
                       |NGX_HAVE_INSTANCE_EVENT;
 
@@ -423,7 +423,7 @@
 {
     if (ngx_poll_module_ctx.actions.process(cycle) == NGX_OK) {
         ngx_event_actions = ngx_rtsig_module_ctx.actions;
-        ngx_event_flags = NGX_USE_SIGIO_EVENT;
+        ngx_event_flags = NGX_USE_RTSIG_EVENT;
     }
 
     return NGX_OK;
--- a/src/event/ngx_event.c	Fri Jun 04 14:57:33 2004 +0000
+++ b/src/event/ngx_event.c	Sun Jun 06 19:49:18 2004 +0000
@@ -375,7 +375,7 @@
             continue;
         }
 
-        if (ngx_event_flags & NGX_USE_SIGIO_EVENT) {
+        if (ngx_event_flags & NGX_USE_RTSIG_EVENT) {
             if (ngx_add_conn(c) == NGX_ERROR) {
                 return NGX_ERROR;
             }
--- a/src/event/ngx_event.h	Fri Jun 04 14:57:33 2004 +0000
+++ b/src/event/ngx_event.h	Sun Jun 06 19:49:18 2004 +0000
@@ -101,6 +101,8 @@
 
     unsigned short   deferred_accept:1;
 
+    unsigned short   overflow: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;
@@ -244,7 +246,7 @@
 /*
  * No need to add or delete the event filters - rt signals.
  */
-#define NGX_USE_SIGIO_EVENT      0x00000100
+#define NGX_USE_RTSIG_EVENT      0x00000100
 
 /*
  * The alternative event method after the rt signals queue overflow.
--- a/src/event/ngx_event_accept.c	Fri Jun 04 14:57:33 2004 +0000
+++ b/src/event/ngx_event_accept.c	Sun Jun 06 19:49:18 2004 +0000
@@ -30,7 +30,7 @@
 
     ecf = ngx_event_get_conf(ngx_cycle->conf_ctx, ngx_event_core_module);
 
-    if (ngx_event_flags & (NGX_USE_EDGE_EVENT|NGX_USE_SIGIO_EVENT)) {
+    if (ngx_event_flags & (NGX_USE_EDGE_EVENT|NGX_USE_RTSIG_EVENT)) {
         ev->available = 1;
 
     } else if (!(ngx_event_flags & NGX_HAVE_KQUEUE_EVENT)) {
@@ -52,9 +52,9 @@
         if (pool == NULL) {
 
             /*
-             * Create the pool before accept() to avoid copy the sockaddr.
-             * Although accept() can fail it's an uncommon case
-             * and besides the pool can be got from the free pool list
+             * Create the pool before accept() to avoid the copying of
+             * the sockaddr.  Although accept() can fail it is uncommon
+             * case and besides the pool can be got from the free pool list
              */
 
             if (!(pool = ngx_create_pool(ls->listening->pool_size, ev->log))) {
@@ -80,7 +80,7 @@
             return;
         }
 
-        /* -1 disable logging the connection number */
+        /* -1 disables the connection number logging */
         ctx->flag = -1;
         ctx->name = ls->listening->addr_text.data;
 
@@ -95,7 +95,7 @@
 
             if (err == NGX_EAGAIN) {
                 if (!(ngx_event_flags
-                      & (NGX_USE_EDGE_EVENT|NGX_USE_SIGIO_EVENT)))
+                      & (NGX_USE_EDGE_EVENT|NGX_USE_RTSIG_EVENT)))
                 {
                     ngx_log_error(NGX_LOG_NOTICE, log, err,
                                   "EAGAIN after %d accepted connection(s)",
@@ -167,7 +167,7 @@
             }
 
         } else {
-            if (!(ngx_event_flags & NGX_USE_AIO_EVENT)) {
+            if (!(ngx_event_flags & (NGX_USE_AIO_EVENT|NGX_USE_RTSIG_EVENT))) {
                 if (ngx_nonblocking(s) == -1) {
                     ngx_log_error(NGX_LOG_ALERT, log, ngx_socket_errno,
                                   ngx_nonblocking_n " failed");
@@ -246,9 +246,9 @@
         wev->ready = 1;
 
         if (ngx_event_flags
-            & (NGX_USE_AIO_EVENT|NGX_USE_EDGE_EVENT|NGX_USE_SIGIO_EVENT))
+            & (NGX_USE_AIO_EVENT|NGX_USE_EDGE_EVENT|NGX_USE_RTSIG_EVENT))
         {
-            /* aio, iocp, sigio, epoll */
+            /* epoll, rtsig, aio, iocp */
             rev->ready = 1;
         }
 
@@ -366,12 +366,12 @@
     for (i = 0; i < cycle->listening.nelts; i++) {
 
         /*
-         * we do not need to handle the Winsock sockets here (divde a socket
+         * we do not need to handle the Winsock sockets here (divide a socket
          * number by 4) because this function would never called
          * in the Winsock environment
          */
 
-        if (ngx_event_flags & NGX_USE_SIGIO_EVENT) {
+        if (ngx_event_flags & NGX_USE_RTSIG_EVENT) {
             if (ngx_add_conn(&cycle->connections[s[i].fd]) == NGX_ERROR) {
                 return NGX_ERROR;
             }
@@ -398,12 +398,12 @@
     for (i = 0; i < cycle->listening.nelts; i++) {
 
         /*
-         * we do not need to handle the Winsock sockets here (divde a socket
+         * we do not need to handle the Winsock sockets here (divide a socket
          * number by 4) because this function would never called
          * in the Winsock environment
          */
 
-        if (ngx_event_flags & NGX_USE_SIGIO_EVENT) {
+        if (ngx_event_flags & NGX_USE_RTSIG_EVENT) {
             if (!cycle->connections[s[i].fd].read->active) {
                 continue;
             }
--- a/src/http/modules/ngx_http_charset_filter.c	Fri Jun 04 14:57:33 2004 +0000
+++ b/src/http/modules/ngx_http_charset_filter.c	Sun Jun 06 19:49:18 2004 +0000
@@ -184,7 +184,7 @@
     ngx_http_create_ctx(r, ctx, ngx_http_charset_filter_module,
                         sizeof(ngx_http_charset_ctx_t), NGX_ERROR);
 
-    r->filter |= NGX_HTTP_FILTER_NEED_IN_MEMORY;
+    r->filter_need_in_memory = 1;
 
     return ngx_http_next_header_filter(r);
 }
--- a/src/http/modules/ngx_http_gzip_filter.c	Fri Jun 04 14:57:33 2004 +0000
+++ b/src/http/modules/ngx_http_gzip_filter.c	Sun Jun 06 19:49:18 2004 +0000
@@ -317,7 +317,7 @@
         r->headers_out.content_length->key.len = 0;
         r->headers_out.content_length = NULL;
     }
-    r->filter |= NGX_HTTP_FILTER_NEED_IN_MEMORY;
+    r->filter_need_in_memory = 1;
 
     return ngx_http_next_header_filter(r);
 }
@@ -438,12 +438,12 @@
          * We preallocate a memory for zlib in one buffer (200K-400K), this
          * dicreases a number of malloc() and free() calls and also probably
          * dicreases a number of syscalls (sbrk() or so).
-         * Besides we free() this memory as soon as the gzipping will complete
+         * Besides we free this memory as soon as the gzipping will complete
          * and do not wait while a whole response will be sent to a client.
          *
          * 8K is for zlib deflate_state (~6K).
          *
-         * TODO: 64-bit, round to PAGE_SIZE, autoconf of deflate_state size
+         * TODO: 64-bit, autoconf of deflate_state size
          */
 
         ctx->allocated = 8192 + (1 << (wbits + 2)) + (1 << (memlevel + 9));
@@ -739,10 +739,12 @@
     alloc = items * size;
     if (alloc % 512 != 0) {
 
-        /* we allocate 8K for zlib deflate_state (~6K) */
-        /* TODO: PAGE_SIZE */
+        /*
+         * allocate the zlib deflate_state, it takes about 6K on x86,
+         * we allocate 8K
+         */
 
-        alloc = (alloc + 4095) & ~4095;
+        alloc = (alloc + ngx_pagesize - 1) & ~(ngx_pagesize - 1);
     }
 
     if (alloc <= ctx->allocated) {
@@ -900,8 +902,7 @@
 
     ngx_conf_merge_value(conf->enable, prev->enable, 0);
 
-    ngx_conf_merge_bufs_value(conf->bufs, prev->bufs, 4,
-                              /* STUB: PAGE_SIZE */ 4096);
+    ngx_conf_merge_bufs_value(conf->bufs, prev->bufs, 4, ngx_pagesize);
 
     ngx_conf_merge_unsigned_value(conf->http_version, prev->http_version,
                                   NGX_HTTP_VERSION_11);
--- a/src/http/modules/ngx_http_range_filter.c	Fri Jun 04 14:57:33 2004 +0000
+++ b/src/http/modules/ngx_http_range_filter.c	Sun Jun 06 19:49:18 2004 +0000
@@ -113,7 +113,7 @@
     if (r->http_version < NGX_HTTP_VERSION_10
         || r->headers_out.status != NGX_HTTP_OK
         || r->headers_out.content_length_n == -1
-        || !(r->filter & NGX_HTTP_FILTER_ALLOW_RANGES))
+        || !r->filter_allow_ranges)
     {
         return ngx_http_next_header_filter(r);
     }
--- a/src/http/modules/ngx_http_static_handler.c	Fri Jun 04 14:57:33 2004 +0000
+++ b/src/http/modules/ngx_http_static_handler.c	Sun Jun 06 19:49:18 2004 +0000
@@ -480,7 +480,7 @@
         return NGX_HTTP_INTERNAL_SERVER_ERROR;
     }
 
-    r->filter |= NGX_HTTP_FILTER_ALLOW_RANGES;
+    r->filter_allow_ranges = 1;
     rc = ngx_http_send_header(r);
 
     if (rc == NGX_ERROR || rc > NGX_OK || r->header_only) {
--- a/src/http/ngx_http.h	Fri Jun 04 14:57:33 2004 +0000
+++ b/src/http/ngx_http.h	Sun Jun 06 19:49:18 2004 +0000
@@ -16,7 +16,6 @@
 #include <ngx_http_request.h>
 #include <ngx_http_config.h>
 #include <ngx_http_busy_lock.h>
-#include <ngx_http_filter.h>
 #include <ngx_http_log_handler.h>
 #include <ngx_http_core_module.h>
 
--- a/src/http/ngx_http_copy_filter.c	Fri Jun 04 14:57:33 2004 +0000
+++ b/src/http/ngx_http_copy_filter.c	Sun Jun 06 19:49:18 2004 +0000
@@ -75,8 +75,8 @@
                             sizeof(ngx_output_chain_ctx_t), NGX_ERROR);
 
         ctx->sendfile = r->sendfile;
-        ctx->need_in_memory = r->filter & NGX_HTTP_FILTER_NEED_IN_MEMORY;
-        ctx->need_in_temp = r->filter & NGX_HTTP_FILTER_NEED_TEMP;
+        ctx->need_in_memory = r->filter_need_in_memory;
+        ctx->need_in_temp = r->filter_need_temporary;
 
         ctx->pool = r->pool;
         ctx->bufs = conf->bufs;
--- a/src/http/ngx_http_core_module.c	Fri Jun 04 14:57:33 2004 +0000
+++ b/src/http/ngx_http_core_module.c	Sun Jun 06 19:49:18 2004 +0000
@@ -227,6 +227,13 @@
       offsetof(ngx_http_core_loc_conf_t, lingering_timeout),
       NULL },
 
+    { ngx_string("reset_timedout_connection"),
+      NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
+      ngx_conf_set_flag_slot,
+      NGX_HTTP_LOC_CONF_OFFSET,
+      offsetof(ngx_http_core_loc_conf_t, reset_timedout_connection),
+      NULL },
+
     { ngx_string("msie_padding"),
       NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
       ngx_conf_set_flag_slot,
@@ -1238,7 +1245,7 @@
     lcf->keepalive_timeout = NGX_CONF_UNSET_MSEC;
     lcf->lingering_time = NGX_CONF_UNSET_MSEC;
     lcf->lingering_timeout = NGX_CONF_UNSET_MSEC;
-
+    lcf->reset_timedout_connection = NGX_CONF_UNSET;
     lcf->msie_padding = NGX_CONF_UNSET;
 
     return lcf;
@@ -1326,6 +1333,8 @@
     ngx_conf_merge_msec_value(conf->lingering_timeout,
                               prev->lingering_timeout, 5000);
 
+    ngx_conf_merge_value(conf->reset_timedout_connection,
+                         prev->reset_timedout_connection, 0);
     ngx_conf_merge_value(conf->msie_padding, prev->msie_padding, 1);
 
     if (conf->open_files == NULL) {
--- a/src/http/ngx_http_core_module.h	Fri Jun 04 14:57:33 2004 +0000
+++ b/src/http/ngx_http_core_module.h	Sun Jun 06 19:49:18 2004 +0000
@@ -137,6 +137,7 @@
 
     ngx_flag_t    sendfile;                /* sendfile */
     ngx_flag_t    tcp_nopush;              /* tcp_nopush */
+    ngx_flag_t    reset_timedout_connection; /* reset_timedout_connection */
     ngx_flag_t    msie_padding;            /* msie_padding */
 
     ngx_array_t  *error_pages;             /* error_page */
@@ -172,4 +173,17 @@
                                ngx_str_t *uri, ngx_str_t *args);
 
 
+typedef int (*ngx_http_output_header_filter_pt)(ngx_http_request_t *r);
+typedef int (*ngx_http_output_body_filter_pt)
+                                   (ngx_http_request_t *r, ngx_chain_t *chain);
+
+
+int ngx_http_output_filter(ngx_http_request_t *r, ngx_chain_t *chain);
+int ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *chain);
+
+
+extern ngx_http_output_header_filter_pt  ngx_http_top_header_filter;
+extern ngx_http_output_body_filter_pt    ngx_http_top_body_filter;
+
+
 #endif /* _NGX_HTTP_CORE_H_INCLUDED_ */
--- a/src/http/ngx_http_filter.h	Fri Jun 04 14:57:33 2004 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,24 +0,0 @@
-#ifndef _NGX_HTTP_FILTER_H_INCLUDED_
-#define _NGX_HTTP_FILTER_H_INCLUDED_
-
-
-#define NGX_HTTP_FILTER_NEED_IN_MEMORY      1
-#define NGX_HTTP_FILTER_SSI_NEED_IN_MEMORY  2
-#define NGX_HTTP_FILTER_NEED_TEMP           4
-#define NGX_HTTP_FILTER_ALLOW_RANGES        8
-
-
-typedef int (*ngx_http_output_header_filter_pt)(ngx_http_request_t *r);
-typedef int (*ngx_http_output_body_filter_pt)
-                                   (ngx_http_request_t *r, ngx_chain_t *chain);
-
-
-int ngx_http_output_filter(ngx_http_request_t *r, ngx_chain_t *chain);
-int ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *chain);
-
-
-extern ngx_http_output_header_filter_pt  ngx_http_top_header_filter;
-extern ngx_http_output_body_filter_pt    ngx_http_top_body_filter;
-
-
-#endif /* _NGX_HTTP_FILTER_H_INCLUDED_ */
--- a/src/http/ngx_http_request.c	Fri Jun 04 14:57:33 2004 +0000
+++ b/src/http/ngx_http_request.c	Sun Jun 06 19:49:18 2004 +0000
@@ -90,7 +90,7 @@
     /* STUB: epoll edge */ c->write->event_handler = ngx_http_empty_handler;
 
     if (rev->ready) {
-        /* deferred accept, aio, iocp */
+        /* the deferred accept(), rtsig, aio, iocp */
 
         if (ngx_accept_mutex) {
             if (ngx_mutex_lock(ngx_posted_events_mutex) == NGX_ERROR) {
@@ -1542,10 +1542,12 @@
 
 void ngx_http_close_request(ngx_http_request_t *r, int error)
 {
-    ngx_uint_t           i;
-    ngx_log_t           *log;
-    ngx_http_log_ctx_t  *ctx;
-    ngx_http_cleanup_t  *cleanup;
+    ngx_uint_t                 i;
+    ngx_log_t                 *log;
+    ngx_http_log_ctx_t        *ctx;
+    ngx_http_cleanup_t        *cleanup;
+    ngx_http_core_loc_conf_t  *clcf;
+    struct linger              l;
 
     log = r->connection->log;
 
@@ -1610,6 +1612,22 @@
         }
     }
 
+    if (r->connection->timedout) {
+        clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
+
+        if (clcf->reset_timedout_connection) {
+            l.l_onoff = 1;
+            l.l_linger = 0;
+
+            if (setsockopt(r->connection->fd, SOL_SOCKET, SO_LINGER,
+                           (const void *) &l, sizeof(struct linger)) == -1)
+            {
+                ngx_log_error(NGX_LOG_ALERT, log, ngx_socket_errno,
+                              "setsockopt(SO_LINGER) failed");
+            }
+        }
+    }
+
     /* ctx->url was allocated from r->pool */
     ctx = log->data;
     ctx->url = NULL;
@@ -1676,6 +1694,7 @@
     if (error == NGX_HTTP_REQUEST_TIME_OUT) {
         ngx_log_error(NGX_LOG_INFO, r->connection->log, NGX_ETIMEDOUT,
                       "client timed out");
+        r->connection->timedout = 1;
         ngx_http_close_request(r, error);
         ngx_http_close_connection(r->connection);
         return;
--- a/src/http/ngx_http_request.h	Fri Jun 04 14:57:33 2004 +0000
+++ b/src/http/ngx_http_request.h	Sun Jun 06 19:49:18 2004 +0000
@@ -287,8 +287,10 @@
     unsigned             lingering_close:1;
     unsigned             closed:1;
 
-    /* TODO: use the filter flags or the separate bits ???? */
-    u_int                filter;
+    unsigned             filter_need_in_memory:1;
+    unsigned             filter_ssi_need_in_memory:1;
+    unsigned             filter_need_temporary:1;
+    unsigned             filter_allow_ranges:1;
 
     /* used to parse HTTP headers */
     ngx_int_t            state;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/os/unix/ngx_alloc.c	Sun Jun 06 19:49:18 2004 +0000
@@ -0,0 +1,75 @@
+
+#include <ngx_config.h>
+#include <ngx_core.h>
+
+
+int ngx_pagesize;
+
+
+void *ngx_alloc(size_t size, ngx_log_t *log)
+{
+    void  *p;
+
+    if (!(p = malloc(size))) {
+        ngx_log_error(NGX_LOG_EMERG, log, ngx_errno,
+                      "malloc() " SIZE_T_FMT " bytes failed", size);
+    }
+
+    ngx_log_debug2(NGX_LOG_DEBUG_ALLOC, log, 0,
+                   "malloc: " PTR_FMT ":" SIZE_T_FMT, p, size);
+
+    return p;
+}
+
+
+void *ngx_calloc(size_t size, ngx_log_t *log)
+{
+    void  *p;
+
+    p = ngx_alloc(size, log);
+
+    if (p) {
+        ngx_memzero(p, size);
+    }
+
+    return p;
+}
+
+
+#if (HAVE_POSIX_MEMALIGN)
+
+void *ngx_memalign(size_t aligment, size_t size, ngx_log_t *log)
+{
+    void  *p;
+
+    if (posix_memalign(&p, aligment, size) == -1) {
+        ngx_log_error(NGX_LOG_EMERG, log, ngx_errno,
+                      "posix_memalign() " SIZE_T_FMT " bytes aligned to "
+                      SIZE_T_FMT " failed", size, alignment);
+    }
+
+    ngx_log_debug2(NGX_LOG_DEBUG_ALLOC, log, 0,
+                   "posix_memalign: " PTR_FMT ":" SIZE_T_FMT, p, size);
+
+    return p;
+}
+
+#esif (HAVE_MEMALIGN)
+
+void *ngx_memalign(size_t aligment, size_t size, ngx_log_t *log)
+{
+    void  *p;
+
+    if (!(p = memalign(aligment, size))) {
+        ngx_log_error(NGX_LOG_EMERG, log, ngx_errno,
+                      "memalign() " SIZE_T_FMT " bytes aligned to "
+                      SIZE_T_FMT " failed", size, alignment);
+    }
+
+    ngx_log_debug2(NGX_LOG_DEBUG_ALLOC, log, 0,
+                   "memalign: " PTR_FMT ":" SIZE_T_FMT, p, size);
+
+    return p;
+}
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/os/unix/ngx_alloc.h	Sun Jun 06 19:49:18 2004 +0000
@@ -0,0 +1,36 @@
+#ifndef _NGX_ALLOC_H_INCLUDED_
+#define _NGX_ALLOC_H_INCLUDED_
+
+
+#include <ngx_config.h>
+#include <ngx_core.h>
+
+
+void *ngx_alloc(size_t size, ngx_log_t *log);
+void *ngx_calloc(size_t size, ngx_log_t *log);
+
+#define ngx_free          free
+
+
+/*
+ * Linux has memalign() or posix_memalign()
+ * Solaris has memalign()
+ * FreeBSD has not memalign() or posix_memalign() but its malloc() alignes
+ * allocations bigger than page size at page boundary.
+ */
+
+#if (HAVE_POSIX_MEMALIGN || HAVE_MEMALIGN)
+
+void *ngx_memalign(size_t alignment, size_t size, ngx_log_t *log);
+
+#else
+
+#define ngx_memalign(alignment, size, log)  ngx_alloc(size, log)
+
+#endif
+
+
+extern int ngx_pagesize;
+
+
+#endif /* _NGX_ALLOC_H_INCLUDED_ */
--- a/src/os/unix/ngx_freebsd_rfork_thread.c	Fri Jun 04 14:57:33 2004 +0000
+++ b/src/os/unix/ngx_freebsd_rfork_thread.c	Sun Jun 06 19:49:18 2004 +0000
@@ -30,7 +30,7 @@
 size_t      ngx_thread_stack_size;
 
 
-static size_t       rz_size = /* STUB: PAGE_SIZE */ 4096;
+static size_t       rz_size;
 static size_t       usable_stack_size;
 static char        *last_stack;
 
@@ -187,6 +187,7 @@
     }
 
     /* the main thread stack red zone */
+    rz_size = ngx_pagesize;
     red_zone = ngx_freebsd_kern_usrstack - (size + rz_size);
 
     ngx_log_debug2(NGX_LOG_DEBUG_CORE, cycle->log, 0,
--- a/src/os/unix/ngx_posix_init.c	Fri Jun 04 14:57:33 2004 +0000
+++ b/src/os/unix/ngx_posix_init.c	Sun Jun 06 19:49:18 2004 +0000
@@ -60,6 +60,8 @@
     struct rlimit      rlmt;
     struct sigaction   sa;
 
+    ngx_pagesize = getpagesize();
+
     for (sig = signals; sig->signo != 0; sig++) {
         ngx_memzero(&sa, sizeof(struct sigaction));
         sa.sa_handler = sig->handler;
--- a/src/os/unix/ngx_socket.c	Fri Jun 04 14:57:33 2004 +0000
+++ b/src/os/unix/ngx_socket.c	Sun Jun 06 19:49:18 2004 +0000
@@ -9,7 +9,9 @@
  * a previous state using fcntl(F_GETFL).
  *
  * ioctl() and fcntl() are syscalls on at least FreeBSD 2.x, Linux 2.2
- * and Solaris 7
+ * and Solaris 7.
+ *
+ * ioctl() in Linux 2.4 and 2.6 uses BKL, however fcntl(F_SETFL) uses it too.
  */
 
 
--- a/src/os/unix/ngx_time.h	Fri Jun 04 14:57:33 2004 +0000
+++ b/src/os/unix/ngx_time.h	Sun Jun 06 19:49:18 2004 +0000
@@ -38,7 +38,7 @@
 #if (SOLARIS)
 #define HAVE_TIMEZONE  1
 
-#define ngx_timezone() (-((daylight) ? altzone : timezone) / 60)
+#define ngx_timezone() (- (daylight ? altzone : timezone) / 60)
 
 #elif defined __linux__
 #define HAVE_TIMEZONE  1
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/os/win32/ngx_alloc.c	Sun Jun 06 19:49:18 2004 +0000
@@ -0,0 +1,36 @@
+
+#include <ngx_config.h>
+#include <ngx_core.h>
+
+
+int ngx_pagesize;
+
+
+void *ngx_alloc(size_t size, ngx_log_t *log)
+{
+    void  *p;
+
+    if (!(p = malloc(size))) {
+        ngx_log_error(NGX_LOG_EMERG, log, ngx_errno,
+                      "malloc() " SIZE_T_FMT " bytes failed", size);
+    }
+
+    ngx_log_debug2(NGX_LOG_DEBUG_ALLOC, log, 0,
+                   "malloc: " PTR_FMT ":" SIZE_T_FMT, p, size);
+
+    return p;
+}
+
+
+void *ngx_calloc(size_t size, ngx_log_t *log)
+{
+    void  *p;
+
+    p = ngx_alloc(size, log);
+
+    if (p) {
+        ngx_memzero(p, size);
+    }
+
+    return p;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/os/win32/ngx_alloc.h	Sun Jun 06 19:49:18 2004 +0000
@@ -0,0 +1,18 @@
+#ifndef _NGX_ALLOC_H_INCLUDED_
+#define _NGX_ALLOC_H_INCLUDED_
+
+
+#include <ngx_config.h>
+#include <ngx_core.h>
+
+
+void *ngx_alloc(size_t size, ngx_log_t *log);
+void *ngx_calloc(size_t size, ngx_log_t *log);
+
+#define ngx_free          free
+#define ngx_memalign(alignment, size, log)  ngx_alloc(size, log)
+
+extern int ngx_pagesize;
+
+
+#endif /* _NGX_ALLOC_H_INCLUDED_ */
--- a/src/os/win32/ngx_win32_init.c	Fri Jun 04 14:57:33 2004 +0000
+++ b/src/os/win32/ngx_win32_init.c	Sun Jun 06 19:49:18 2004 +0000
@@ -40,6 +40,7 @@
     DWORD               bytes;
     SOCKET              s;
     WSADATA             wsd;
+    SYSTEM_INFO         si;
     OSVERSIONINFOEX     osvi;
     ngx_osviex_stub_t  *osviex_stub;
 
@@ -121,6 +122,9 @@
         }
     }
 
+    GetSystemInfo(&si);
+    ngx_pagesize = si.dwPageSize;
+
 
     /* init Winsock */