aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorIgor Sysoev <igor@sysoev.ru>2003-11-10 21:09:22 +0000
committerIgor Sysoev <igor@sysoev.ru>2003-11-10 21:09:22 +0000
commitd59a047a7070dc6af13b2e35c097efccc8ce38d0 (patch)
tree7efbd7a8fd2e4d871da3165dab7287c49fb0341e /src
parent7832933eed3cb0187eca4fba87076f10c897925e (diff)
downloadnginx-d59a047a7070dc6af13b2e35c097efccc8ce38d0.tar.gz
nginx-d59a047a7070dc6af13b2e35c097efccc8ce38d0.zip
nginx-0.0.1-2003-11-11-00:09:22 import
Diffstat (limited to 'src')
-rw-r--r--src/core/ngx_core.h1
-rw-r--r--src/core/ngx_times.c51
-rw-r--r--src/core/ngx_times.h18
-rw-r--r--src/event/modules/ngx_devpoll_module.c8
-rw-r--r--src/event/modules/ngx_iocp_module.c2
-rw-r--r--src/event/modules/ngx_kqueue_module.c22
-rw-r--r--src/event/modules/ngx_poll_module.c2
-rw-r--r--src/event/modules/ngx_select_module.c2
-rw-r--r--src/http/modules/proxy/ngx_http_proxy_cache.c2
-rw-r--r--src/http/modules/proxy/ngx_http_proxy_handler.c17
-rw-r--r--src/http/modules/proxy/ngx_http_proxy_upstream.c13
-rw-r--r--src/http/ngx_http.h2
-rw-r--r--src/http/ngx_http_busy_lock.c11
-rw-r--r--src/http/ngx_http_busy_lock.h4
-rw-r--r--src/http/ngx_http_core_module.c18
-rw-r--r--src/http/ngx_http_header_filter.c4
-rw-r--r--src/http/ngx_http_log_handler.c8
-rw-r--r--src/http/ngx_http_log_handler.h6
-rw-r--r--src/http/ngx_http_request.h2
-rw-r--r--src/os/unix/ngx_time.c7
-rw-r--r--src/os/unix/ngx_time.h6
21 files changed, 171 insertions, 35 deletions
diff --git a/src/core/ngx_core.h b/src/core/ngx_core.h
index 1db2e41df..7a19d1b71 100644
--- a/src/core/ngx_core.h
+++ b/src/core/ngx_core.h
@@ -27,6 +27,7 @@ typedef struct ngx_connection_s ngx_connection_t;
#include <ngx_table.h>
#include <ngx_file.h>
#include <ngx_files.h>
+#include <ngx_times.h>
#include <ngx_inet.h>
#include <ngx_conf_file.h>
#include <ngx_os_init.h>
diff --git a/src/core/ngx_times.c b/src/core/ngx_times.c
new file mode 100644
index 000000000..423e4cd35
--- /dev/null
+++ b/src/core/ngx_times.c
@@ -0,0 +1,51 @@
+
+#include <ngx_config.h>
+#include <ngx_core.h>
+
+
+time_t ngx_cached_time;
+
+static char cached_http_time[] = "Mon, 28 Sep 1970 06:00:00 GMT";
+ngx_str_t ngx_cached_http_time;
+
+static char cached_http_log_time[] = "28/Sep/1970:12:00:00";
+ngx_str_t ngx_cached_http_log_time;
+
+
+time_t ngx_time()
+{
+ return ngx_cached_time;
+}
+
+
+/* TODO: remove strftime() */
+
+void ngx_time_update()
+{
+ ngx_tm_t *tp, tm;
+ static char *months[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun",
+ "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
+
+ /* STUB: need to move to ngx_init_time() */
+ ngx_cached_http_time.data = cached_http_time;
+ ngx_cached_http_log_time.data = cached_http_log_time;
+
+ tp = gmtime(&ngx_cached_time);
+
+ ngx_cached_http_time.len = strftime(ngx_cached_http_time.data,
+ sizeof("Mon, 28 Sep 1970 06:00:00 GMT"),
+ "%a, %d %b %Y %H:%M:%S GMT", tp);
+
+
+ ngx_localtime(&tm);
+
+ ngx_cached_http_log_time.len = ngx_snprintf(ngx_cached_http_log_time.data,
+ sizeof("28/Sep/1970:12:00:00"),
+ "%02d/%s/%d:%02d:%02d:%02d",
+ tm.ngx_tm_mday,
+ months[tm.ngx_tm_mon - 1],
+ tm.ngx_tm_year,
+ tm.ngx_tm_hour,
+ tm.ngx_tm_min,
+ tm.ngx_tm_sec);
+}
diff --git a/src/core/ngx_times.h b/src/core/ngx_times.h
new file mode 100644
index 000000000..2cbcc7249
--- /dev/null
+++ b/src/core/ngx_times.h
@@ -0,0 +1,18 @@
+#ifndef _NGX_TIMES_H_INCLUDED_
+#define _NGX_TIMES_H_INCLUDED_
+
+
+#include <ngx_config.h>
+#include <ngx_core.h>
+
+
+time_t ngx_time();
+void ngx_time_update();
+
+
+extern time_t ngx_cached_time;
+extern ngx_str_t ngx_cached_http_time;
+extern ngx_str_t ngx_cached_http_log_time;
+
+
+#endif /* _NGX_TIMES_H_INCLUDED_ */
diff --git a/src/event/modules/ngx_devpoll_module.c b/src/event/modules/ngx_devpoll_module.c
index d652ac297..9bc743426 100644
--- a/src/event/modules/ngx_devpoll_module.c
+++ b/src/event/modules/ngx_devpoll_module.c
@@ -366,8 +366,14 @@ int ngx_devpoll_process_events(ngx_log_t *log)
nchanges = 0;
+ gettimeofday(&tv, NULL);
+
+ if (ngx_cached_time != tv.tv_sec) {
+ ngx_cached_time = tv.tv_sec;
+ ngx_time_update();
+ }
+
if ((int) timer != INFTIM) {
- gettimeofday(&tv, NULL);
delta = tv.tv_sec * 1000 + tv.tv_usec / 1000 - delta;
#if (NGX_DEBUG_EVENT)
diff --git a/src/event/modules/ngx_iocp_module.c b/src/event/modules/ngx_iocp_module.c
index 86d763b71..0a5ac5bd7 100644
--- a/src/event/modules/ngx_iocp_module.c
+++ b/src/event/modules/ngx_iocp_module.c
@@ -189,6 +189,8 @@ static int ngx_iocp_process_events(ngx_log_t *log)
err = 0;
}
+ /* TODO: timer */
+
if (timer != INFINITE) {
delta = ngx_msec() - delta;
ngx_event_expire_timers(delta);
diff --git a/src/event/modules/ngx_kqueue_module.c b/src/event/modules/ngx_kqueue_module.c
index c896a8380..831bc7720 100644
--- a/src/event/modules/ngx_kqueue_module.c
+++ b/src/event/modules/ngx_kqueue_module.c
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2002-2003 Igor Sysoev, http://sysoev.ru
+ * Copyright (C) 2002-2003 Igor Sysoev, http://sysoev.ru/en/
*/
@@ -347,16 +347,24 @@ static int ngx_kqueue_process_events(ngx_log_t *log)
nchanges = 0;
+ gettimeofday(&tv, NULL);
+
+ if (ngx_cached_time != tv.tv_sec) {
+ ngx_cached_time = tv.tv_sec;
+ ngx_time_update();
+ }
+
if (timer) {
- gettimeofday(&tv, NULL);
delta = tv.tv_sec * 1000 + tv.tv_usec / 1000 - delta;
#if (NGX_DEBUG_EVENT)
ngx_log_debug(log, "kevent timer: %d, delta: %d" _ timer _ delta);
#endif
- /* The expired timers must be handled before a processing of the events
- because the new timers can be added during a processing */
+ /*
+ * The expired timers must be handled before a processing of the events
+ * because the new timers can be added during a processing
+ */
ngx_event_expire_timers(delta);
@@ -413,8 +421,10 @@ static int ngx_kqueue_process_events(ngx_log_t *log)
instance = (uintptr_t) ev & 1;
ev = (void *) ((uintptr_t) ev & ~1);
- /* It's a stale event from a file descriptor
- that was just closed in this iteration */
+ /*
+ * it's a stale event from a file descriptor
+ * that was just closed in this iteration
+ */
if (ev->active == 0 || ev->instance != instance) {
ngx_log_debug(log, "stale kevent");
diff --git a/src/event/modules/ngx_poll_module.c b/src/event/modules/ngx_poll_module.c
index 9d2f8aca3..34f2b1191 100644
--- a/src/event/modules/ngx_poll_module.c
+++ b/src/event/modules/ngx_poll_module.c
@@ -259,6 +259,8 @@ static int ngx_poll_process_events(ngx_log_t *log)
ngx_log_debug(log, "poll ready %d" _ ready);
+ /* TODO: time */
+
if ((int) timer != INFTIM) {
delta = ngx_msec() - delta;
diff --git a/src/event/modules/ngx_select_module.c b/src/event/modules/ngx_select_module.c
index 792476669..082c0e335 100644
--- a/src/event/modules/ngx_select_module.c
+++ b/src/event/modules/ngx_select_module.c
@@ -314,6 +314,8 @@ static int ngx_select_process_events(ngx_log_t *log)
ngx_log_debug(log, "select ready %d" _ ready);
#endif
+ /* TODO: time */
+
if (timer) {
#if (HAVE_SELECT_CHANGE_TIMEOUT)
delta = timer - (tv.tv_sec * 1000 + tv.tv_usec / 1000);
diff --git a/src/http/modules/proxy/ngx_http_proxy_cache.c b/src/http/modules/proxy/ngx_http_proxy_cache.c
index 3c4f5cad3..a8c9d7754 100644
--- a/src/http/modules/proxy/ngx_http_proxy_cache.c
+++ b/src/http/modules/proxy/ngx_http_proxy_cache.c
@@ -288,6 +288,8 @@ void ngx_http_proxy_cache_busy_lock(ngx_http_proxy_ctx_t *p)
return;
}
+ ngx_http_busy_unlock(p->lcf->busy_lock, &p->busy_lock);
+
if (rc == NGX_DONE) {
ft_type = NGX_HTTP_PROXY_FT_BUSY_LOCK;
diff --git a/src/http/modules/proxy/ngx_http_proxy_handler.c b/src/http/modules/proxy/ngx_http_proxy_handler.c
index ad719ca11..ecfe65831 100644
--- a/src/http/modules/proxy/ngx_http_proxy_handler.c
+++ b/src/http/modules/proxy/ngx_http_proxy_handler.c
@@ -503,7 +503,7 @@ static char *ngx_http_proxy_log_proxy_state(ngx_http_request_t *r, char *buf,
{
ngx_http_proxy_ctx_t *p;
- p = ngx_http_get_module_ctx(r, ngx_http_proxy_module);
+ p = ngx_http_get_module_err_ctx(r, ngx_http_proxy_module);
if (p == NULL) {
*buf = '-';
@@ -520,11 +520,15 @@ static char *ngx_http_proxy_log_proxy_state(ngx_http_request_t *r, char *buf,
*buf++ = '/';
- *buf++ = 'X';
+ *buf++ = '_';
+
+ *buf++ = '/';
+
+ *buf++ = '_';
*buf++ = '/';
- *buf++ = 'X';
+ *buf++ = '_';
*buf++ = ' ';
@@ -554,6 +558,9 @@ static char *ngx_http_proxy_log_proxy_state(ngx_http_request_t *r, char *buf,
buf += ngx_snprintf(buf, NGX_TIME_LEN, TIME_FMT, p->state->expires);
}
+ *buf++ = ' ';
+ *buf++ = '_';
+
return buf;
}
@@ -563,7 +570,7 @@ static char *ngx_http_proxy_log_cache_state(ngx_http_request_t *r, char *buf,
{
ngx_http_proxy_ctx_t *p;
- p = ngx_http_get_module_ctx(r, ngx_http_proxy_module);
+ p = ngx_http_get_module_err_ctx(r, ngx_http_proxy_module);
if (p == NULL || p->state->cache_state == 0) {
*buf = '-';
@@ -580,7 +587,7 @@ static char *ngx_http_proxy_log_reason(ngx_http_request_t *r, char *buf,
{
ngx_http_proxy_ctx_t *p;
- p = ngx_http_get_module_ctx(r, ngx_http_proxy_module);
+ p = ngx_http_get_module_err_ctx(r, ngx_http_proxy_module);
if (p == NULL || p->state->reason == 0) {
*buf = '-';
diff --git a/src/http/modules/proxy/ngx_http_proxy_upstream.c b/src/http/modules/proxy/ngx_http_proxy_upstream.c
index d4049935d..0a5ecd2fc 100644
--- a/src/http/modules/proxy/ngx_http_proxy_upstream.c
+++ b/src/http/modules/proxy/ngx_http_proxy_upstream.c
@@ -337,6 +337,8 @@ void ngx_http_proxy_upstream_busy_lock(ngx_http_proxy_ctx_t *p)
return;
}
+ ngx_http_busy_unlock(p->lcf->busy_lock, &p->busy_lock);
+
if (rc == NGX_DONE) {
ft_type = NGX_HTTP_PROXY_FT_BUSY_LOCK;
@@ -1053,27 +1055,24 @@ static void ngx_http_proxy_process_body(ngx_event_t *ev)
if (p->upstream->peer.connection) {
if (ep->upstream_done && p->cachable) {
if (ngx_http_proxy_update_cache(p) == NGX_ERROR) {
- ngx_http_busy_unlock_cachable(p->lcf->busy_lock, &p->busy_lock);
+ ngx_http_busy_unlock(p->lcf->busy_lock, &p->busy_lock);
ngx_http_proxy_finalize_request(p, 0);
return;
}
- ngx_http_busy_unlock_cachable(p->lcf->busy_lock, &p->busy_lock);
-
} else if (ep->upstream_eof && p->cachable) {
/* TODO: check length & update cache */
if (ngx_http_proxy_update_cache(p) == NGX_ERROR) {
- ngx_http_busy_unlock_cachable(p->lcf->busy_lock, &p->busy_lock);
+ ngx_http_busy_unlock(p->lcf->busy_lock, &p->busy_lock);
ngx_http_proxy_finalize_request(p, 0);
return;
}
-
- ngx_http_busy_unlock_cachable(p->lcf->busy_lock, &p->busy_lock);
}
if (ep->upstream_done || ep->upstream_eof || ep->upstream_error) {
+ ngx_http_busy_unlock(p->lcf->busy_lock, &p->busy_lock);
ngx_http_proxy_close_connection(p);
}
}
@@ -1104,6 +1103,8 @@ static void ngx_http_proxy_next_upstream(ngx_http_proxy_ctx_t *p, int ft_type)
ngx_log_debug(p->request->connection->log, "next upstream: %d" _ ft_type);
+ ngx_http_busy_unlock(p->lcf->busy_lock, &p->busy_lock);
+
if (ft_type != NGX_HTTP_PROXY_FT_HTTP_404) {
ngx_event_connect_peer_failed(&p->upstream->peer);
}
diff --git a/src/http/ngx_http.h b/src/http/ngx_http.h
index 26dde7fca..aef53e891 100644
--- a/src/http/ngx_http.h
+++ b/src/http/ngx_http.h
@@ -21,6 +21,8 @@ typedef struct {
#define ngx_http_get_module_ctx(r, module) r->ctx[module.ctx_index]
+#define ngx_http_get_module_err_ctx(r, module) \
+ (r->err_ctx ? r->err_ctx[module.ctx_index] : r->ctx[module.ctx_index])
#define ngx_http_create_ctx(r, cx, module, size, error) \
do { \
diff --git a/src/http/ngx_http_busy_lock.c b/src/http/ngx_http_busy_lock.c
index 2ed66dc0b..085cd56ce 100644
--- a/src/http/ngx_http_busy_lock.c
+++ b/src/http/ngx_http_busy_lock.c
@@ -100,11 +100,14 @@ ngx_log_debug(bc->event->log, "BUSYLOCK: %d" _ rc);
}
-void ngx_http_busy_unlock_cachable(ngx_http_busy_lock_t *bl,
- ngx_http_busy_lock_ctx_t *bc)
+void ngx_http_busy_unlock(ngx_http_busy_lock_t *bl,
+ ngx_http_busy_lock_ctx_t *bc)
{
- bl->md5_mask[bc->slot / 8] &= ~(1 << (bc->slot & 7));
- bl->cachable--;
+ if (bl->md5) {
+ bl->md5_mask[bc->slot / 8] &= ~(1 << (bc->slot & 7));
+ bl->cachable--;
+ }
+
bl->busy--;
}
diff --git a/src/http/ngx_http_busy_lock.h b/src/http/ngx_http_busy_lock.h
index d36b9b741..e600b0180 100644
--- a/src/http/ngx_http_busy_lock.h
+++ b/src/http/ngx_http_busy_lock.h
@@ -38,8 +38,8 @@ typedef struct {
int ngx_http_busy_lock(ngx_http_busy_lock_t *bl, ngx_http_busy_lock_ctx_t *bc);
int ngx_http_busy_lock_cachable(ngx_http_busy_lock_t *bl,
ngx_http_busy_lock_ctx_t *bc, int lock);
-void ngx_http_busy_unlock_cachable(ngx_http_busy_lock_t *bl,
- ngx_http_busy_lock_ctx_t *bc);
+void ngx_http_busy_unlock(ngx_http_busy_lock_t *bl,
+ ngx_http_busy_lock_ctx_t *bc);
char *ngx_http_set_busy_lock_slot(ngx_conf_t *cf, ngx_command_t *cmd,
void *conf);
diff --git a/src/http/ngx_http_core_module.c b/src/http/ngx_http_core_module.c
index a5f5c38ca..3a0ec8bfc 100644
--- a/src/http/ngx_http_core_module.c
+++ b/src/http/ngx_http_core_module.c
@@ -429,6 +429,11 @@ int ngx_http_send_header(ngx_http_request_t *r)
return NGX_OK;
}
+ if (r->err_status) {
+ r->headers_out.status = r->err_status;
+ r->headers_out.status_line.len = 0;
+ }
+
return (*ngx_http_top_header_filter)(r);
}
@@ -495,7 +500,18 @@ int ngx_http_internal_redirect(ngx_http_request_t *r,
}
/* clear the modules contexts */
- ngx_memzero(r->ctx, sizeof(void *) * ngx_http_max_module);
+
+ if (r->error_page) {
+ r->err_status = r->headers_out.status;
+ r->err_ctx = r->ctx;
+ r->ctx = ngx_pcalloc(r->pool, sizeof(void *) * ngx_http_max_module);
+ if (r->ctx == NULL) {
+ return NGX_HTTP_INTERNAL_SERVER_ERROR;
+ }
+
+ } else {
+ ngx_memzero(r->ctx, sizeof(void *) * ngx_http_max_module);
+ }
r->phase = 0;
r->phase_handler = 0;
diff --git a/src/http/ngx_http_header_filter.c b/src/http/ngx_http_header_filter.c
index 64cf4bbce..f67c56828 100644
--- a/src/http/ngx_http_header_filter.c
+++ b/src/http/ngx_http_header_filter.c
@@ -116,6 +116,7 @@ static int ngx_http_header_filter(ngx_http_request_t *r)
#endif
} else {
+
if (r->headers_out.status < NGX_HTTP_MOVED_PERMANENTLY) {
/* 2XX */
status = r->headers_out.status - NGX_HTTP_OK;
@@ -240,7 +241,8 @@ static int ngx_http_header_filter(ngx_http_request_t *r)
#if (NGX_HTTP_LOG_ALL_HEADERS_OUT)
p = h->last;
#endif
- h->last += ngx_http_get_time(h->last, ngx_time());
+ h->last = ngx_cpymem(h->last, ngx_cached_http_time.data,
+ ngx_cached_http_time.len);
#if (NGX_HTTP_LOG_ALL_HEADERS_OUT)
r->headers_out.date = ngx_palloc(r->pool, sizeof(ngx_table_elt_t));
diff --git a/src/http/ngx_http_log_handler.c b/src/http/ngx_http_log_handler.c
index 7a2bf9e9c..9d4f65e9a 100644
--- a/src/http/ngx_http_log_handler.c
+++ b/src/http/ngx_http_log_handler.c
@@ -210,6 +210,10 @@ static char *ngx_http_log_pipe(ngx_http_request_t *r, char *buf, uintptr_t data)
static char *ngx_http_log_time(ngx_http_request_t *r, char *buf, uintptr_t data)
{
+ return ngx_cpymem(buf, ngx_cached_http_log_time.data,
+ ngx_cached_http_log_time.len);
+
+#if 0
ngx_tm_t tm;
ngx_localtime(&tm);
@@ -219,6 +223,7 @@ static char *ngx_http_log_time(ngx_http_request_t *r, char *buf, uintptr_t data)
tm.ngx_tm_mday, months[tm.ngx_tm_mon - 1],
tm.ngx_tm_year,
tm.ngx_tm_hour, tm.ngx_tm_min, tm.ngx_tm_sec);
+#endif
}
@@ -237,7 +242,8 @@ static char *ngx_http_log_request(ngx_http_request_t *r, char *buf,
static char *ngx_http_log_status(ngx_http_request_t *r, char *buf,
uintptr_t data)
{
- return buf + ngx_snprintf(buf, 4, "%d", r->headers_out.status);
+ return buf + ngx_snprintf(buf, 4, "%d",
+ r->err_status ? r->err_status : r->headers_out.status);
}
diff --git a/src/http/ngx_http_log_handler.h b/src/http/ngx_http_log_handler.h
index 40e70dfe3..3d8481c96 100644
--- a/src/http/ngx_http_log_handler.h
+++ b/src/http/ngx_http_log_handler.h
@@ -16,9 +16,9 @@ typedef char *(*ngx_http_log_op_pt) (ngx_http_request_t *r, char *buf,
#define NGX_HTTP_LOG_ARG (u_int) -1
/* STUB */
-#define NGX_INT32_LEN sizeof("4294967296") - 1
-#define NGX_TIME_LEN sizeof("4294967296") - 1
-#define NGX_OFF_LEN sizeof("18446744073709551616") - 1
+#define NGX_INT32_LEN sizeof("-2147483648") - 1
+#define NGX_TIME_LEN sizeof("-2147483648") - 1
+#define NGX_OFF_LEN sizeof("-9223372036854775808") - 1
typedef struct {
diff --git a/src/http/ngx_http_request.h b/src/http/ngx_http_request.h
index 526e13d11..a87c6dc4e 100644
--- a/src/http/ngx_http_request.h
+++ b/src/http/ngx_http_request.h
@@ -192,6 +192,8 @@ struct ngx_http_request_s {
void *data;
char *discarded_buffer;
+ void **err_ctx;
+ int err_status;
/* URI is not started with '/' - "GET http://" */
unsigned unusual_uri:1;
diff --git a/src/os/unix/ngx_time.c b/src/os/unix/ngx_time.c
index 12256e13a..bf3432ba7 100644
--- a/src/os/unix/ngx_time.c
+++ b/src/os/unix/ngx_time.c
@@ -1,11 +1,12 @@
#include <ngx_config.h>
-#include <ngx_time.h>
+#include <ngx_core.h>
+
void ngx_localtime(ngx_tm_t *tm)
{
- time_t clock = time(NULL);
- localtime_r(&clock, tm);
+ localtime_r(&ngx_cached_time, tm);
+
tm->ngx_tm_mon++;
tm->ngx_tm_year += 1900;
}
diff --git a/src/os/unix/ngx_time.h b/src/os/unix/ngx_time.h
index ee5b47f9d..cdec417e2 100644
--- a/src/os/unix/ngx_time.h
+++ b/src/os/unix/ngx_time.h
@@ -23,8 +23,10 @@ void ngx_localtime(ngx_tm_t *tm);
ngx_msec_t ngx_msec(void);
-/* STUB */
-#define ngx_time() time(NULL)
+time_t ngx_time();
+
+extern time_t ngx_cached_time;
+
#endif /* _NGX_TIME_H_INCLUDED_ */