nginx-0.0.1-2003-04-28-19:06:39 import
diff --git a/src/core/nginx.c b/src/core/nginx.c
index 36a28f8..30c0680 100644
--- a/src/core/nginx.c
+++ b/src/core/nginx.c
@@ -89,6 +89,8 @@
return 1;
}
+ ngx_init_temp_number();
+
for (i = 0; ngx_modules[i]; i++) {
if (ngx_modules[i]->init_module) {
if (ngx_modules[i]->init_module(ngx_pool) == NGX_ERROR) {
@@ -97,14 +99,6 @@
}
}
-
-#if 0
- /* STUB */
- /* TODO: init chain of global modules (like ngx_http.c),
- they would init its modules and ngx_listening_sockets */
- ngx_http_init(ngx_pool, &ngx_log);
-#endif
-
ngx_open_listening_sockets(&ngx_log);
/* TODO: daemon */
diff --git a/src/core/ngx_conf_file.c b/src/core/ngx_conf_file.c
index 12537bd..45533be 100644
--- a/src/core/ngx_conf_file.c
+++ b/src/core/ngx_conf_file.c
@@ -432,16 +432,34 @@
char *ngx_conf_set_size_slot(ngx_conf_t *cf, ngx_command_t *cmd, char *conf)
{
- int size;
+ int size, len, scale;
+ char last;
ngx_str_t *value;
value = (ngx_str_t *) cf->args->elts;
- size = atoi(value[1].data);
- if (size < 0) {
+ len = value[1].len;
+ last = value[1].data[len - 1];
+
+ if (last == 'K' || last == 'k') {
+ len--;
+ scale = 1024;
+
+ } else if (last == 'M' || last == 'm') {
+ len--;
+ scale = 1024 * 1024;
+
+ } else {
+ scale = 1;
+ }
+
+ size = ngx_atoi(value[1].data, len);
+ if (size == NGX_ERROR) {
return "value must be greater or equal to zero";
}
+ size *= scale;
+
*(int *) (conf + cmd->offset) = size;
return NGX_CONF_OK;
@@ -450,17 +468,65 @@
char *ngx_conf_set_time_slot(ngx_conf_t *cf, ngx_command_t *cmd, char *conf)
{
- int size;
+ int size, len, scale;
+ char last;
ngx_str_t *value;
value = (ngx_str_t *) cf->args->elts;
- size = atoi(value[1].data);
+ len = value[1].len;
+ last = value[1].data[len - 1];
+
+ if (last == 'm') {
+ len--;
+ scale = 1000 * 60;
+
+ } else if (last == 'h') {
+ len--;
+ scale = 1000 * 60 * 60;
+
+ } else if (last == 'd') {
+ len--;
+ scale = 1000 * 60 * 60 * 24;
+
+ } else if (last == 'w') {
+ len--;
+ scale = 1000 * 60 * 60 * 24 * 7;
+
+#if 0 /* overflow */
+
+ } else if (last == 'M') {
+ len--;
+ scale = 1000 * 60 * 60 * 24 * 30;
+
+ } else if (last == 'y') {
+ len--;
+ scale = 1000 * 60 * 60 * 24 * 365;
+
+#endif
+
+ } else if (last == 's') {
+ len--;
+ if (value[1].data[len - 1] == 'm') {
+ len--;
+ scale = 1;
+
+ } else {
+ scale = 1000;
+ }
+
+ } else {
+ scale = 1000;
+ }
+
+ size = ngx_atoi(value[1].data, len);
if (size < 0) {
return "value must be greater or equal to zero";
}
- *(int *) (conf + cmd->offset) = size * 1000;
+ size *= scale;
+
+ *(int *) (conf + cmd->offset) = size;
return NGX_CONF_OK;
}
diff --git a/src/core/ngx_conf_file.h b/src/core/ngx_conf_file.h
index beb148a..f6c9e02 100644
--- a/src/core/ngx_conf_file.h
+++ b/src/core/ngx_conf_file.h
@@ -45,6 +45,7 @@
char *(*set)(ngx_conf_t *cf, ngx_command_t *cmd, char *conf);
int conf;
int offset;
+ void *bounds;
};
diff --git a/src/core/ngx_file.c b/src/core/ngx_file.c
index 7576c9b..b8f15e1 100644
--- a/src/core/ngx_file.c
+++ b/src/core/ngx_file.c
@@ -7,10 +7,14 @@
#include <ngx_files.h>
+static int ngx_temp_number;
+static int ngx_random;
+
+
int ngx_create_temp_file(ngx_file_t *file, ngx_path_t *path,
- ngx_pool_t *pool, int num, int step, int persistent)
+ ngx_pool_t *pool, int persistent)
{
- int i;
+ int i, num;
ngx_err_t err;
file->name.len = path->name.len + 1 + path->len + 10;
@@ -26,6 +30,8 @@
ngx_memcpy(file->name.data, path->name.data, path->name.len);
+ num = ngx_next_temp_number(0);
+
for ( ;; ) {
snprintf(file->name.data + path->name.len + 1 + path->len, 11,
"%010u", num);
@@ -58,7 +64,7 @@
err = ngx_errno;
if (err == NGX_EEXIST) {
- num = (num + 1) * step;
+ num = ngx_next_temp_number(1);
continue;
}
@@ -140,3 +146,25 @@
return NGX_OK;
}
+
+
+void ngx_init_temp_number()
+{
+ ngx_random = 0;
+
+ ngx_temp_number = ngx_random;
+
+ while (ngx_random < 10000) {
+ ngx_random = 123456;
+ }
+}
+
+
+int ngx_next_temp_number(int collision)
+{
+ if (collision) {
+ ngx_temp_number += ngx_random;
+ }
+
+ return ngx_temp_number++;
+}
diff --git a/src/core/ngx_file.h b/src/core/ngx_file.h
index d073848..2cd2f76 100644
--- a/src/core/ngx_file.h
+++ b/src/core/ngx_file.h
@@ -30,10 +30,12 @@
int ngx_create_temp_file(ngx_file_t *file, ngx_path_t *path,
- ngx_pool_t *pool, int num, int step, int persistent);
+ ngx_pool_t *pool, int persistent);
void ngx_create_hashed_filename(ngx_file_t *file, ngx_path_t *path);
int ngx_create_path(ngx_file_t *file, ngx_path_t *path);
+void ngx_init_temp_number();
+int ngx_next_temp_number(int collision);
#endif /* _NGX_FILE_H_INCLUDED_ */
diff --git a/src/core/ngx_log.c b/src/core/ngx_log.c
index 30e42ad..4057d7a 100644
--- a/src/core/ngx_log.c
+++ b/src/core/ngx_log.c
@@ -4,7 +4,7 @@
*/
/*
- "[time as ctime()] [alert] 412:3 (32)Broken pipe: anything"
+ "[time as ctime()] [alert] 412#3 (32)Broken pipe: anything"
"[time as ctime()] [alert] (32)Broken pipe: anything"
"[time as ctime()] [alert] anything"
@@ -58,14 +58,19 @@
#endif
if (err) {
+
#if (WIN32)
- if ((unsigned) err >= 0x80000000)
+ if ((unsigned) err >= 0x80000000) {
len += ngx_snprintf(errstr + len, sizeof(errstr) - len - 1,
" (%X: ", err);
- else
-#endif
+ } else {
len += ngx_snprintf(errstr + len, sizeof(errstr) - len - 1,
" (%d: ", err);
+ }
+#else
+ len += ngx_snprintf(errstr + len, sizeof(errstr) - len - 1,
+ " (%d: ", err);
+#endif
len += ngx_strerror_r(err, errstr + len, sizeof(errstr) - len - 1);
if (len < sizeof(errstr) - 2) {
diff --git a/src/core/ngx_string.c b/src/core/ngx_string.c
index 4beb11d..1510498 100644
--- a/src/core/ngx_string.c
+++ b/src/core/ngx_string.c
@@ -27,14 +27,18 @@
int value;
for (value = 0; n--; line++) {
- if (*line < '0' || *line > '9') {
- return NGX_ERROR;
- }
+ if (*line < '0' || *line > '9') {
+ return NGX_ERROR;
+ }
- value = value * 10 + (*line - '0');
+ value = value * 10 + (*line - '0');
}
- return value;
+ if (value < 0) {
+ return NGX_ERROR;
+ } else {
+ return value;
+ }
}
diff --git a/src/event/modules/ngx_select_module.c b/src/event/modules/ngx_select_module.c
index e7abfaa..f325a65 100644
--- a/src/event/modules/ngx_select_module.c
+++ b/src/event/modules/ngx_select_module.c
@@ -242,6 +242,7 @@
#endif
if (timer) {
+ /* TODO: Linux returns time in tv */
delta = ngx_msec() - delta;
ngx_event_expire_timers(delta);
diff --git a/src/event/ngx_event_proxy.c b/src/event/ngx_event_proxy.c
index 47530f6..9609d4c 100644
--- a/src/event/ngx_event_proxy.c
+++ b/src/event/ngx_event_proxy.c
@@ -600,7 +600,7 @@
if (p->temp_file->fd == NGX_INVALID_FILE) {
rc = ngx_create_temp_file(p->temp_file, p->temp_path, p->pool,
- p->number, p->random, p->cachable);
+ p->cachable);
if (rc == NGX_ERROR) {
p->fatal_error = 1;
diff --git a/src/event/ngx_event_proxy.h b/src/event/ngx_event_proxy.h
index 520b837..267533e 100644
--- a/src/event/ngx_event_proxy.h
+++ b/src/event/ngx_event_proxy.h
@@ -75,8 +75,6 @@
ngx_file_t *temp_file;
ngx_path_t *temp_path;
- int number;
- int random;
char *temp_file_warn;
};
diff --git a/src/http/modules/proxy/ngx_http_event_proxy_handler.c b/src/http/modules/proxy/ngx_http_event_proxy_handler.c
index 26ccf4f..9b1ddc4 100644
--- a/src/http/modules/proxy/ngx_http_event_proxy_handler.c
+++ b/src/http/modules/proxy/ngx_http_event_proxy_handler.c
@@ -902,9 +902,6 @@
ep->temp_file->fd = NGX_INVALID_FILE;
ep->temp_file->log = p->log;
- ep->number = 10;
- ep->random = 5;
-
ep->max_temp_file_size = p->lcf->max_temp_file_size;
ep->temp_file_write_size = p->lcf->temp_file_write_size;
ep->temp_file_warn = "an upstream response is buffered "
@@ -1396,7 +1393,7 @@
path.len += path.level[i] + 1;
}
- return ngx_create_temp_file(&file, &path, pool, 123456789, 2, 0);
+ return ngx_create_temp_file(&file, &path, pool, 0);
}
diff --git a/src/http/ngx_http.h b/src/http/ngx_http.h
index 8bb2cc1..906eb29 100644
--- a/src/http/ngx_http.h
+++ b/src/http/ngx_http.h
@@ -86,6 +86,18 @@
typedef struct {
+ ngx_chain_t chain[4];
+ ngx_hunk_t *header_out;
+ ngx_hunk_t *hunk;
+ ngx_hunk_t *file_hunk;
+ ngx_file_t temp_file;
+ ngx_path_t *temp_path;
+ off_t offset;
+ char *header_in_pos;
+} ngx_http_request_body_t;
+
+
+typedef struct {
int status;
ngx_str_t status_line;
@@ -116,11 +128,12 @@
ngx_file_t file;
- ngx_pool_t *pool;
- ngx_hunk_t *header_in;
+ ngx_pool_t *pool;
+ ngx_hunk_t *header_in;
+ ngx_http_request_body_t *request_body;
- ngx_http_headers_in_t headers_in;
- ngx_http_headers_out_t headers_out;
+ ngx_http_headers_in_t headers_in;
+ ngx_http_headers_out_t headers_out;
int (*handler)(ngx_http_request_t *r);
@@ -224,6 +237,12 @@
int ngx_http_handler(ngx_http_request_t *r);
+int ngx_http_init_client_request_body(ngx_http_request_t *r, int size);
+int ngx_http_read_client_request_body(ngx_http_request_t *r);
+int ngx_http_init_client_request_body_chain(ngx_http_request_t *r);
+void ngx_http_reinit_client_request_body_hunks(ngx_http_request_t *r);
+
+
int ngx_http_send_header(ngx_http_request_t *r);
int ngx_http_special_response_handler(ngx_http_request_t *r, int error);
diff --git a/src/http/ngx_http_output_filter.c b/src/http/ngx_http_output_filter.c
index 485aae3..2a7ada7 100644
--- a/src/http/ngx_http_output_filter.c
+++ b/src/http/ngx_http_output_filter.c
@@ -26,9 +26,10 @@
NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
ngx_conf_set_size_slot,
NGX_HTTP_LOC_CONF_OFFSET,
- offsetof(ngx_http_output_filter_conf_t, hunk_size)},
+ offsetof(ngx_http_output_filter_conf_t, hunk_size),
+ NULL},
- {ngx_null_string, 0, NULL, 0, 0}
+ {ngx_null_string, 0, NULL, 0, 0, NULL}
};
diff --git a/src/http/ngx_http_request_body.c b/src/http/ngx_http_request_body.c
index b21331e..b954066 100644
--- a/src/http/ngx_http_request_body.c
+++ b/src/http/ngx_http_request_body.c
@@ -1,56 +1,55 @@
+#include <ngx_config.h>
+#include <ngx_core.h>
+#include <ngx_http.h>
-
-int ngx_http_start_read_client_body(ngx_http_proxy_ctx_t *p)
+int ngx_http_init_client_request_body(ngx_http_request_t *r, int size)
{
- int first_part, size;
- ngx_hunk_t *h;
- ngx_http_request_t *r;
+ int header_in_part, len;
+ ngx_hunk_t *h;
+ ngx_http_request_body_t *rb;
- r = p->request;
+ ngx_test_null(rb, ngx_pcalloc(r->pool, sizeof(ngx_http_request_body_t)),
+ NGX_HTTP_INTERNAL_SERVER_ERROR);
- first_part = r->header_in->last - r->header_in->pos;
+ header_in_part = r->header_in->end - r->header_in->pos;
- if (first_part > r->headers_in.content_length_n) {
- first_part = r->headers_in.content_length_n;
- size = 0;
+ if (header_in_part) {
+ rb->header_in_pos = r->header_in->pos;
+ }
+
+ if (header_in_part > r->headers_in.content_length_n) {
+ header_in_part = r->headers_in.content_length_n;
} else {
- size = r->headers_in.content_length_n - first_part;
- if (size > p->lcf->client_request_buffer_size) {
- size = p->lcf->client_request_buffer_size;
+ len = r->headers_in.content_length_n - header_in_part;
+ if (len > size) {
+ len = size;
- } else if (size > NGX_PAGE_SIZE) {
- size = ((size + NGX_PAGE_SIZE) / NGX_PAGE_SIZE) * NGX_PAGE_SIZE;
+ } else if (len > NGX_PAGE_SIZE) {
+ len = ((len + NGX_PAGE_SIZE - 1) / NGX_PAGE_SIZE) * NGX_PAGE_SIZE;
}
- if (size) {
- ngx_test_null(p->client_request_hunk, ngx_palloc(r->pool, size),
- NGX_ERROR);
+ if (len) {
+ ngx_test_null(rb->hunk, ngx_create_temp_hunk(r->pool, len, 0, 0),
+ NGX_HTTP_INTERNAL_SERVER_ERROR);
}
}
- if (first_part) {
- ngx_test_null(h, ngx_alloc_hunk(r->pool), NGX_ERROR);
-
- h->type = NGX_HUNK_IN_MEMORY|NGX_HUNK_TEMP;
- h->pos = h->start = h->pre_start = r->header_in->pos;
- h->last = h->end = h->post_end = r->header_in->pos + first_part;
- h->file_pos = h->file_last = 0;
- h->file = NULL;
- h->shadow = NULL;
- h->tag = 0;
-
- p->client_first_part_hunk = h;
- }
+ r->request_body = rb;
return NGX_OK;
}
-int ngx_http_read_client_body(ngx_event_t *rev)
+int ngx_http_read_client_request_body(ngx_http_request_t *r)
{
+ int size, n, rc;
+ ngx_chain_t *entry;
+ ngx_http_request_body_t *rb;
+
+ rb = r->request_body;
do {
if (r->header_in->last < r->header_in->end) {
@@ -70,7 +69,7 @@
rb->chain[0].next = NULL;
}
- n = ngx_recv_chain(c, &rb->chain);
+ n = ngx_recv_chain(r->connection, rb->chain);
if (n == NGX_ERROR) {
return NGX_ERROR;
@@ -80,7 +79,7 @@
return NGX_AGAIN;
}
- for (entry = &rb->chain; entry; entry = entry->next) {
+ for (entry = rb->chain; entry; entry = entry->next) {
size = entry->hunk->end - entry->hunk->last;
if (n >= size) {
@@ -96,9 +95,9 @@
}
if (rb->hunk && rb->hunk->last == rb->hunk->end) {
- if (rb->temp_file->fd == NGX_INVALID_FILE) {
- rc = ngx_create_temp_file(rb->temp_file, rb->temp_path, r->pool,
- rb->number, rb->random, 0);
+ if (rb->temp_file.fd == NGX_INVALID_FILE) {
+ rc = ngx_create_temp_file(&rb->temp_file, rb->temp_path,
+ r->pool, 0);
if (rc == NGX_ERROR) {
return NGX_ERROR;
@@ -109,7 +108,7 @@
}
}
- n = ngx_write_file(rb->temp_file, rb->hunk,
+ n = ngx_write_file(&rb->temp_file, rb->hunk->pos,
rb->hunk->last - rb->hunk->pos, rb->offset);
if (rc == NGX_ERROR) {
@@ -120,13 +119,13 @@
rb->hunk->last = rb->hunk->pos;
}
- } while (rev->ready);
+ } while (r->connection->read->ready);
return NGX_OK;
}
-int ngx_init_client_request_body_chain(ngx_http_reuqest_t *r)
+int ngx_http_init_client_request_body_chain(ngx_http_request_t *r)
{
int i;
ngx_hunk_t *h;
@@ -143,7 +142,8 @@
rb->chain[i].hunk = r->header_in;
}
- if (rb->temp_file->fd != NGX_INVALID_FILE) {
+ if (rb->temp_file.fd != NGX_INVALID_FILE) {
+
if (rb->file_hunk == NULL) {
ngx_test_null(h, ngx_alloc_hunk(r->pool), NGX_ERROR);
@@ -152,7 +152,7 @@
h->last = h->end = h->post_end = 0;
h->file_pos = 0;
h->file_last = rb->offset;
- h->file = rb->temp_file;
+ h->file = &rb->temp_file;
h->shadow = NULL;
h->tag = 0;
@@ -176,7 +176,7 @@
}
-int ngx_reinit_client_request_body_hunks(ngx_http_reuqest_t *r)
+void ngx_http_reinit_client_request_body_hunks(ngx_http_request_t *r)
{
ngx_http_request_body_t *rb;
@@ -187,7 +187,7 @@
}
if (rb->file_hunk) {
- rb->file_hunk->file_pos = rb->file_hunk->file_start;
+ rb->file_hunk->file_pos = 0;
}
if (rb->hunk) {
diff --git a/src/http/ngx_http_write_filter.c b/src/http/ngx_http_write_filter.c
index 4d7b958..752a932 100644
--- a/src/http/ngx_http_write_filter.c
+++ b/src/http/ngx_http_write_filter.c
@@ -25,9 +25,10 @@
NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
ngx_conf_set_size_slot,
NGX_HTTP_LOC_CONF_OFFSET,
- offsetof(ngx_http_write_filter_conf_t, buffer_output)},
+ offsetof(ngx_http_write_filter_conf_t, buffer_output),
+ NULL},
- {ngx_null_string, 0, NULL, 0, 0}
+ {ngx_null_string, 0, NULL, 0, 0, NULL}
};
diff --git a/src/os/unix/freebsd/ngx_rfork_thread.h b/src/os/unix/freebsd/ngx_rfork_thread.h
index bd500e1..2ab114e 100644
--- a/src/os/unix/freebsd/ngx_rfork_thread.h
+++ b/src/os/unix/freebsd/ngx_rfork_thread.h
@@ -16,6 +16,7 @@
char *sp;
__asm__ ("mov %%esp,%0" : "=r" (sp));
+
return (sp > ngx_stacks_end) ? 0:
(sp - ngx_stacks_start) / ngx_stack_size + 1;
}
diff --git a/src/os/unix/ngx_recv_chain.c b/src/os/unix/ngx_recv_chain.c
index de3de73..7a8a3b8 100644
--- a/src/os/unix/ngx_recv_chain.c
+++ b/src/os/unix/ngx_recv_chain.c
@@ -6,20 +6,20 @@
#include <ngx_connection.h>
-ssize_t ngx_recv_chain(ngx_connection_t *c, ngx_chain_t *ce)
+ssize_t ngx_recv_chain(ngx_connection_t *c, ngx_chain_t *entry)
{
- ssize_t n;
+ ssize_t n;
struct iovec *iov;
ngx_err_t err;
ngx_array_t io;
ngx_init_array(io, c->pool, 10, sizeof(struct iovec), NGX_ERROR);
- while (ce) {
+ while (entry) {
ngx_test_null(iov, ngx_push_array(&io), NGX_ERROR);
- iov->iov_base = ce->hunk->pos;
- iov->iov_len = ce->hunk->end - ce->hunk->last;
- ce = ce->next;
+ iov->iov_base = entry->hunk->pos;
+ iov->iov_len = entry->hunk->end - entry->hunk->last;
+ entry = entry->next;
}
ngx_log_debug(c->log, "recv: %d:%d" _ io.nelts _ iov->iov_len);
diff --git a/src/os/unix/ngx_x86_mutex.h b/src/os/unix/ngx_x86_mutex.h
new file mode 100644
index 0000000..a8ed2ee
--- /dev/null
+++ b/src/os/unix/ngx_x86_mutex.h
@@ -0,0 +1,30 @@
+
+
+typedef struct {
+ int lock;
+} ngx_mutex_t;
+
+
+static inline int ngx_spin_lock(ngx_mutex_t *m, int count)
+{
+ int lock;
+
+ __asm__ __volatile("
+
+get_lock:
+ mov $1, %1
+ xchg %1, %2
+ cmp $0, %1
+ jne spin_lock
+
+spin_lock:
+ cmp $0, %3
+ je failed
+
+ dec %3
+ rep nop
+ cmp $0, %2
+ jne spin_lock
+
+ ": "=q" (lock), "m" (m->lock), "q" (count));
+}