]> git.kaiwu.me - nginx.git/commitdiff
nginx-0.0.3-2004-06-06-23:49:18 import
authorIgor Sysoev <igor@sysoev.ru>
Sun, 6 Jun 2004 19:49:18 +0000 (19:49 +0000)
committerIgor Sysoev <igor@sysoev.ru>
Sun, 6 Jun 2004 19:49:18 +0000 (19:49 +0000)
33 files changed:
auto/cc
auto/sources
auto/unix
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 [moved from src/core/ngx_alloc.c with 84% similarity]
src/core/ngx_palloc.h [moved from src/core/ngx_alloc.h with 81% similarity]
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 [deleted file]
src/http/ngx_http_request.c
src/http/ngx_http_request.h
src/os/unix/ngx_alloc.c [new file with mode: 0644]
src/os/unix/ngx_alloc.h [new file with mode: 0644]
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 [new file with mode: 0644]
src/os/win32/ngx_alloc.h [new file with mode: 0644]
src/os/win32/ngx_win32_init.c

diff --git a/auto/cc b/auto/cc
index 59cbfbfe6e351b026787b210dd58c89c4522c1c2..29e94d0555a997dd4eb71edbc890aa591f650721 100644 (file)
--- a/auto/cc
+++ b/auto/cc
@@ -5,7 +5,7 @@ case $CC in
 
     *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"
index 86a1cddd866373282e7f596a029720993a9adbc5..c48443392f594e16dee973ea3908e91f3a40188f 100644 (file)
@@ -8,7 +8,7 @@ CORE_DEPS="src/core/nginx.h \
             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_DEPS="src/core/nginx.h \
 
 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 @@ UNIX_DEPS="$CORE_DEPS $EVENT_DEPS \
             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_DEPS="$CORE_DEPS $EVENT_DEPS \
 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 @@ WIN32_DEPS="$CORE_DEPS $EVENT_DEPS \
             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_CONFIG=src/os/win32/ngx_win32_config.h
 
 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_INCS="src/http src/http/modules"
 
 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 \
index 55b66bf9332d108b9a99f5dceef329bb4ed944b7..c150f2e9c5abf843b9bb03c24acc13a48facd3ef 100755 (executable)
--- a/auto/unix
+++ b/auto/unix
@@ -110,3 +110,15 @@ ngx_func="localtime_r()"
 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
index 448e63ab62aecb3e155db730252151ab16bcdcbb..02983151ab5eb4e508ac3b8277acbcf0ee98d9db 100644 (file)
 /* 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
index 6382ec10c60e9e124babfe2c982179fab07e9868..d5de0767590f5ffd83667228fffb241881251c07 100644 (file)
@@ -228,7 +228,7 @@ void ngx_close_listening_sockets(ngx_cycle_t *cycle)
         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);
             }
index ecd3c8bc49690ed290300364ec7a67ba12a529fc..8dbc4e49fb4b94c069cd7df130fc8dca82b10e21 100644 (file)
@@ -103,6 +103,7 @@ struct ngx_connection_s {
 
     unsigned          pipeline:1;
     unsigned          unexpected_eof:1;
+    unsigned          timedout:1;
     signed            tcp_nopush:2;
 #if (HAVE_IOCP)
     unsigned          accept_context_updated:1;
index ccb357bfe03ce7c05dec74a4e65d22f689f1db2c..1e194e71982d8df19d9fb14b624ead519d88ce09 100644 (file)
@@ -26,6 +26,7 @@ typedef struct ngx_connection_s  ngx_connection_t;
 #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>
similarity index 84%
rename from src/core/ngx_alloc.c
rename to src/core/ngx_palloc.c
index de583fc09a7a33958ed4b1e81c849b038da16a97..65e2eed66d43fed4af733e79ed3e350c0f88e651 100644 (file)
@@ -3,35 +3,6 @@
 #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;
@@ -99,7 +70,7 @@ void *ngx_palloc(ngx_pool_t *pool, size_t size)
     ngx_pool_t        *p, *n;
     ngx_pool_large_t  *large, *last;
 
-    if (size <= NGX_MAX_ALLOC_FROM_POOL) {
+    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);
@@ -155,7 +126,7 @@ void *ngx_palloc(ngx_pool_t *pool, size_t size)
         large->next = NULL;
     }
 
-    if (!(p = ngx_alloc(size, pool->log))) {
+    if (!(p = ngx_memalign(ngx_pagesize, size, pool->log))) {
         return NULL;
     }
 
@@ -198,3 +169,30 @@ void *ngx_pcalloc(ngx_pool_t *pool, size_t 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
similarity index 81%
rename from src/core/ngx_alloc.h
rename to src/core/ngx_palloc.h
index e64f84f4a0aa59c8984b0bb5c5809a98bad6a04c..7774d356c4032bd0bbc709b24ba0c9e8d21b89fa 100644 (file)
@@ -1,5 +1,5 @@
-#ifndef _NGX_ALLOC_H_INCLUDED_
-#define _NGX_ALLOC_H_INCLUDED_
+#ifndef _NGX_PALLOC_H_INCLUDED_
+#define _NGX_PALLOC_H_INCLUDED_
 
 
 #include <ngx_config.h>
@@ -7,11 +7,11 @@
 
 
 /*
- * NGX_MAX_ALLOC_FROM_POOL should be (NGX_PAGE_SIZE - 1), i.e. 4095 on x86.
+ * 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_MAX_ALLOC_FROM_POOL  (ngx_pagesize - 1)
 
 #define NGX_DEFAULT_POOL_SIZE   (16 * 1024)
 
@@ -48,7 +48,4 @@ 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_ */
+#endif /* _NGX_PALLOC_H_INCLUDED_ */
index 120624594374f4a520165e92d3beb655f5ad8992..ec7dd17bc1a0efc39d862fc921460729c00a62ec 100644 (file)
@@ -114,7 +114,7 @@ static int ngx_rtsig_init(ngx_cycle_t *cycle)
 
     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 @@ static int ngx_rtsig_process_overflow(ngx_cycle_t *cycle)
 {
     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;
index e9ec48ece5726ff3f31eda00cb3df68213b9092c..b8bed8950e81c8caf7b296fc9e2cbfc0550a3462 100644 (file)
@@ -375,7 +375,7 @@ static ngx_int_t ngx_event_process_init(ngx_cycle_t *cycle)
             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;
             }
index e85f531b7a20e79b5ec50d7b90c5c6bb33151fab..1b9dfb29080a77decb5145507c0d3eb4bb4bfe87 100644 (file)
@@ -101,6 +101,8 @@ struct ngx_event_s {
 
     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 @@ extern ngx_event_actions_t   ngx_event_actions;
 /*
  * 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.
index 5a3a451e725f94ede579d81e4638e78c0570496e..9b53edbb525ab462c3e5bddd1a4cfe7f2f9c8ab5 100644 (file)
@@ -30,7 +30,7 @@ void ngx_event_accept(ngx_event_t *ev)
 
     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 @@ void ngx_event_accept(ngx_event_t *ev)
         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 @@ void ngx_event_accept(ngx_event_t *ev)
             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 @@ void ngx_event_accept(ngx_event_t *ev)
 
             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 @@ void ngx_event_accept(ngx_event_t *ev)
             }
 
         } 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 @@ void ngx_event_accept(ngx_event_t *ev)
         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 @@ ngx_int_t ngx_enable_accept_events(ngx_cycle_t *cycle)
     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 @@ ngx_int_t ngx_disable_accept_events(ngx_cycle_t *cycle)
     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;
             }
index 279001bafc769538f098d5944f6ce3bec7b179fe..b79a4606c85c824113b4d11af3ee5c2b9791fdc8 100644 (file)
@@ -184,7 +184,7 @@ static int ngx_http_charset_header_filter(ngx_http_request_t *r)
     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);
 }
index eb949751776089b3e443d161102aa4aaa8e85ea0..cc7ba9c28d75b413c05c6bba312bdac01700e0d7 100644 (file)
@@ -317,7 +317,7 @@ static int ngx_http_gzip_header_filter(ngx_http_request_t *r)
         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 @@ static int ngx_http_gzip_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
          * 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 @@ static void *ngx_http_gzip_filter_alloc(void *opaque, u_int items, u_int size)
     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 @@ static char *ngx_http_gzip_merge_conf(ngx_conf_t *cf,
 
     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);
index 484bcb07b442149e5fb6f050ce34c0173f2738a8..65a5fd0551eed18232c61084e5d15979e520fe48 100644 (file)
@@ -113,7 +113,7 @@ static ngx_int_t ngx_http_range_header_filter(ngx_http_request_t *r)
     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);
     }
index 532e8faabd87efa594636f9f8efee9b7a27703fd..9c11c7eb1aaf38acf9c95909bdad44201dc5e2f7 100644 (file)
@@ -480,7 +480,7 @@ static ngx_int_t ngx_http_static_handler(ngx_http_request_t *r)
         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) {
index bb718549b9163ca07f8c6e9d3f5f6387aa24d788..87eabd1d22b5b6103d91522306bf0623372f7765 100644 (file)
@@ -16,7 +16,6 @@ typedef struct ngx_http_cleanup_s  ngx_http_cleanup_t;
 #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>
 
index 96da0a5171f3341c2010893ef8251ed93e3beca7..6d901a46790bc10d4ce21cc8b1cc21245731efb1 100644 (file)
@@ -75,8 +75,8 @@ ngx_int_t ngx_http_copy_filter(ngx_http_request_t *r, ngx_chain_t *in)
                             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;
index aeec7d21cd09720fc1bc3bbf75122a15831f9aa3..f68a60573685629340f202404176650f763ecebd 100644 (file)
@@ -227,6 +227,13 @@ static ngx_command_t  ngx_http_core_commands[] = {
       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 @@ static void *ngx_http_core_create_loc_conf(ngx_conf_t *cf)
     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 @@ static char *ngx_http_core_merge_loc_conf(ngx_conf_t *cf,
     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) {
index a8a6cf0ef2d51b4e20a40bacee37841314a02637..9224e955357261e72511c9a51a401f4add2b7e22 100644 (file)
@@ -137,6 +137,7 @@ typedef struct {
 
     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 @@ int ngx_http_internal_redirect(ngx_http_request_t *r,
                                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_ */
diff --git a/src/http/ngx_http_filter.h b/src/http/ngx_http_filter.h
deleted file mode 100644 (file)
index d90947f..0000000
+++ /dev/null
@@ -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_ */
index 97e1b9439014f6294d75fa02f8f9ccdf8a3a9e68..98fbc28a6fb815c67ea72a4226f49f679af72e99 100644 (file)
@@ -90,7 +90,7 @@ void ngx_http_init_connection(ngx_connection_t *c)
     /* 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 @@ int ngx_http_send_last(ngx_http_request_t *r)
 
 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 @@ void ngx_http_close_request(ngx_http_request_t *r, int error)
         }
     }
 
+    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 @@ static void ngx_http_client_error(ngx_http_request_t *r,
     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;
index cac8aed372896c3c8615fc4990a077a38fb9f8ed..3cf7307b21bde7647c8fd318174c2221a94bb07b 100644 (file)
@@ -287,8 +287,10 @@ struct ngx_http_request_s {
     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;
diff --git a/src/os/unix/ngx_alloc.c b/src/os/unix/ngx_alloc.c
new file mode 100644 (file)
index 0000000..69925d1
--- /dev/null
@@ -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
diff --git a/src/os/unix/ngx_alloc.h b/src/os/unix/ngx_alloc.h
new file mode 100644 (file)
index 0000000..650f8be
--- /dev/null
@@ -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_ */
index 1cdfee4e9987e30ce84131037e91690a8c5e739b..740fb525d16bb99e2906624b8c805ee237a8390b 100644 (file)
@@ -30,7 +30,7 @@ char       *ngx_freebsd_kern_usrstack;
 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 @@ ngx_int_t ngx_init_threads(int n, size_t size, ngx_cycle_t *cycle)
     }
 
     /* 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,
index 65c04a95908786d3cd68e3338ebe5a4ea9ee941e..dc96ddd856c23b75b6ea37e64962681481dd5d7e 100644 (file)
@@ -60,6 +60,8 @@ int ngx_posix_init(ngx_log_t *log)
     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;
index 69d3f459b3e769a20814c6a7f252315bf4d84db5..443c93bbf0003e80e2414ddd42b2a3bf1dba9afc 100644 (file)
@@ -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.
  */
 
 
index 0b44c5ad47b830a0dc176cf04318206183f26f83..dbb7a0a54b5cc041cfacf9294cf3422c219bc06e 100644 (file)
@@ -38,7 +38,7 @@ typedef struct tm      ngx_tm_t;
 #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
diff --git a/src/os/win32/ngx_alloc.c b/src/os/win32/ngx_alloc.c
new file mode 100644 (file)
index 0000000..591e61b
--- /dev/null
@@ -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;
+}
diff --git a/src/os/win32/ngx_alloc.h b/src/os/win32/ngx_alloc.h
new file mode 100644 (file)
index 0000000..d6ea00a
--- /dev/null
@@ -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_ */
index c4ffc11218a3c61bcc6d86684a2ccd1df0fd9dc9..7a25b28452668f0fc884d57e04c03a3a7f966fbf 100644 (file)
@@ -40,6 +40,7 @@ int ngx_os_init(ngx_log_t *log)
     DWORD               bytes;
     SOCKET              s;
     WSADATA             wsd;
+    SYSTEM_INFO         si;
     OSVERSIONINFOEX     osvi;
     ngx_osviex_stub_t  *osviex_stub;
 
@@ -121,6 +122,9 @@ int ngx_os_init(ngx_log_t *log)
         }
     }
 
+    GetSystemInfo(&si);
+    ngx_pagesize = si.dwPageSize;
+
 
     /* init Winsock */