Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nginx/nginx.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorIgor Sysoev <igor@sysoev.ru>2003-06-03 19:42:58 +0400
committerIgor Sysoev <igor@sysoev.ru>2003-06-03 19:42:58 +0400
commit1c10462e88491d52a23e22fbc3ca0012591df095 (patch)
tree5a71cf54dda493188473693e5b66a08fc8cdf161 /src
parent7578ec9df43bbb31db5291f1b76359d10900a679 (diff)
nginx-0.0.1-2003-06-03-19:42:58 import
Diffstat (limited to 'src')
-rw-r--r--src/core/nginx.c25
-rw-r--r--src/core/ngx_alloc.c6
-rw-r--r--src/core/ngx_alloc.h7
-rw-r--r--src/core/ngx_array.c5
-rw-r--r--src/core/ngx_array.h2
-rw-r--r--src/core/ngx_conf_file.c3
-rw-r--r--src/core/ngx_conf_file.h18
-rw-r--r--src/core/ngx_connection.h20
-rw-r--r--src/core/ngx_core.h12
-rw-r--r--src/core/ngx_file.c4
-rw-r--r--src/core/ngx_file.h6
-rw-r--r--src/core/ngx_hunk.c2
-rw-r--r--src/core/ngx_hunk.h16
-rw-r--r--src/core/ngx_inet.c3
-rw-r--r--src/core/ngx_log.c120
-rw-r--r--src/core/ngx_log.h12
-rw-r--r--src/core/ngx_modules.c8
-rw-r--r--src/core/ngx_sendfile.c25
-rw-r--r--src/core/ngx_sendfile.h23
-rw-r--r--src/core/ngx_server.h17
-rw-r--r--src/core/ngx_string.c1
-rw-r--r--src/core/ngx_string.h1
-rw-r--r--src/core/ngx_table.h6
-rw-r--r--src/event/ngx_event_accept.c2
-rw-r--r--src/event/ngx_event_acceptex.c39
-rw-r--r--src/http/modules/ngx_http_log_handler.c14
-rw-r--r--src/http/modules/ngx_http_range_filter.c2
-rw-r--r--src/http/ngx_http.c7
-rw-r--r--src/http/ngx_http.h10
-rw-r--r--src/http/ngx_http_core_module.c4
-rw-r--r--src/http/ngx_http_event.c4
-rw-r--r--src/http/ngx_http_header_filter.c1
-rw-r--r--src/os/unix/ngx_errno.h1
-rw-r--r--src/os/unix/ngx_time.h2
-rw-r--r--src/os/win32/ngx_errno.h22
-rw-r--r--src/os/win32/ngx_files.c16
-rw-r--r--src/os/win32/ngx_files.h14
-rw-r--r--src/os/win32/ngx_init.c64
-rw-r--r--src/os/win32/ngx_os_init.h2
-rw-r--r--src/os/win32/ngx_socket.c70
-rw-r--r--src/os/win32/ngx_socket.h4
-rw-r--r--src/os/win32/ngx_time.h6
-rw-r--r--src/os/win32/ngx_types.h1
43 files changed, 340 insertions, 287 deletions
diff --git a/src/core/nginx.c b/src/core/nginx.c
index 820d6e3f4..295e2a946 100644
--- a/src/core/nginx.c
+++ b/src/core/nginx.c
@@ -31,21 +31,25 @@ ngx_array_t ngx_listening_sockets;
int main(int argc, char *const *argv)
{
int i;
- ngx_str_t conf_file;
- ngx_conf_t conf;
+ ngx_str_t conf_file;
+ ngx_log_t *log;
+ ngx_conf_t conf;
ngx_max_sockets = -1;
+#if 0
ngx_log.fd = STDERR_FILENO;
ngx_log.log_level = NGX_LOG_INFO;
/* STUB */ ngx_log.log_level = NGX_LOG_DEBUG;
+#endif
+ log = ngx_log_init_errlog();
- if (ngx_os_init(&ngx_log) == NGX_ERROR) {
+ if (ngx_os_init(log) == NGX_ERROR) {
return 1;
}
- ngx_pool = ngx_create_pool(16 * 1024, &ngx_log);
+ ngx_pool = ngx_create_pool(16 * 1024, log);
/* */
ngx_max_module = 0;
@@ -72,7 +76,7 @@ int main(int argc, char *const *argv)
conf.ctx = ngx_conf_ctx;
conf.pool = ngx_pool;
- conf.log = &ngx_log;
+ conf.log = log;
conf.module_type = NGX_CORE_MODULE;
conf.cmd_type = NGX_MAIN_CONF;
@@ -83,6 +87,11 @@ int main(int argc, char *const *argv)
return 1;
}
+#if 0
+ log = (ngx_log_t *) ngx_get_conf(ngx_errlog_module);
+ /* STUB */ log->log_level = NGX_LOG_DEBUG;
+#endif
+
ngx_init_temp_number();
ngx_io = ngx_os_io;
@@ -95,7 +104,7 @@ int main(int argc, char *const *argv)
}
}
- if (ngx_open_listening_sockets(&ngx_log) == NGX_ERROR) {
+ if (ngx_open_listening_sockets(log) == NGX_ERROR) {
return 1;
}
@@ -103,12 +112,12 @@ int main(int argc, char *const *argv)
/* TODO: fork */
- ngx_pre_thread(&ngx_listening_sockets, ngx_pool, &ngx_log);
+ ngx_pre_thread(&ngx_listening_sockets, ngx_pool, log);
/* TODO: threads */
/* STUB */
- ngx_worker(&ngx_log);
+ ngx_worker(log);
}
return 0;
diff --git a/src/core/ngx_alloc.c b/src/core/ngx_alloc.c
index f2608f77d..af59a223c 100644
--- a/src/core/ngx_alloc.c
+++ b/src/core/ngx_alloc.c
@@ -1,10 +1,6 @@
#include <ngx_config.h>
-
-#include <ngx_errno.h>
-#include <ngx_log.h>
-#include <ngx_string.h>
-#include <ngx_alloc.h>
+#include <ngx_core.h>
void *ngx_alloc(size_t size, ngx_log_t *log)
diff --git a/src/core/ngx_alloc.h b/src/core/ngx_alloc.h
index 1d2f2f7ea..b63f4bdc1 100644
--- a/src/core/ngx_alloc.h
+++ b/src/core/ngx_alloc.h
@@ -3,8 +3,8 @@
#include <ngx_config.h>
+#include <ngx_core.h>
-#include <ngx_log.h>
/* NGX_MAX_ALLOC_FROM_POOL should be (PAGE_SIZE - 1), i.e. 4095 on x86.
On FreeBSD 5.x it allows to use zero copy send.
@@ -18,12 +18,15 @@
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;
+
+typedef struct ngx_pool_s ngx_pool_t;
+
struct ngx_pool_s {
char *last;
char *end;
diff --git a/src/core/ngx_array.c b/src/core/ngx_array.c
index dd91141c2..8d5cec989 100644
--- a/src/core/ngx_array.c
+++ b/src/core/ngx_array.c
@@ -1,9 +1,6 @@
#include <ngx_config.h>
-
-#include <ngx_alloc.h>
-#include <ngx_string.h>
-#include <ngx_array.h>
+#include <ngx_core.h>
ngx_array_t *ngx_create_array(ngx_pool_t *p, int n, size_t size)
diff --git a/src/core/ngx_array.h b/src/core/ngx_array.h
index 22cb3fc35..d6443d6a7 100644
--- a/src/core/ngx_array.h
+++ b/src/core/ngx_array.h
@@ -3,8 +3,8 @@
#include <ngx_config.h>
+#include <ngx_core.h>
-#include <ngx_alloc.h>
typedef struct {
void *elts;
diff --git a/src/core/ngx_conf_file.c b/src/core/ngx_conf_file.c
index 241c7a897..306bf1ccd 100644
--- a/src/core/ngx_conf_file.c
+++ b/src/core/ngx_conf_file.c
@@ -1,9 +1,6 @@
#include <ngx_config.h>
-
#include <ngx_core.h>
-#include <ngx_files.h>
-#include <ngx_conf_file.h>
char ngx_conf_errstr[MAX_CONF_ERRSTR];
diff --git a/src/core/ngx_conf_file.h b/src/core/ngx_conf_file.h
index 20747b624..b517ff0f9 100644
--- a/src/core/ngx_conf_file.h
+++ b/src/core/ngx_conf_file.h
@@ -3,14 +3,7 @@
#include <ngx_config.h>
-#include <ngx_files.h>
-#include <ngx_log.h>
-#include <ngx_file.h>
-#include <ngx_time.h>
-#include <ngx_string.h>
-#include <ngx_alloc.h>
-#include <ngx_hunk.h>
-#include <ngx_array.h>
+#include <ngx_core.h>
/*
@@ -51,10 +44,6 @@
extern char ngx_conf_errstr[MAX_CONF_ERRSTR];
-typedef struct ngx_conf_s ngx_conf_t;
-
-
-typedef struct ngx_command_s ngx_command_t;
struct ngx_command_s {
ngx_str_t name;
int type;
@@ -66,14 +55,15 @@ struct ngx_command_s {
#define ngx_null_command {ngx_null_string, 0, NULL, 0, 0, NULL}
-typedef struct {
+
+struct ngx_module_s {
int ctx_index;
int index;
void *ctx;
ngx_command_t *commands;
int type;
int (*init_module)(ngx_pool_t *p);
-} ngx_module_t;
+};
typedef struct {
diff --git a/src/core/ngx_connection.h b/src/core/ngx_connection.h
index c3e9e0902..c75fd1f06 100644
--- a/src/core/ngx_connection.h
+++ b/src/core/ngx_connection.h
@@ -1,26 +1,10 @@
#ifndef _NGX_CONNECTION_H_INCLUDED_
#define _NGX_CONNECTION_H_INCLUDED_
+#include <ngx_config.h>
#include <ngx_core.h>
-
-#if 0
-#include <ngx_socket.h>
-#include <ngx_log.h>
-#include <ngx_alloc.h>
-#include <ngx_hunk.h>
-#include <ngx_array.h>
-#include <ngx_string.h>
-
-#include <ngx_server.h>
-#endif
-
-#if 0
-typedef struct ngx_connection_s ngx_connection_t;
-#endif
-
-#ifdef NGX_EVENT
#include <ngx_event.h>
-#endif
+
struct ngx_connection_s {
ngx_socket_t fd;
diff --git a/src/core/ngx_core.h b/src/core/ngx_core.h
index a612200d1..8963d08ff 100644
--- a/src/core/ngx_core.h
+++ b/src/core/ngx_core.h
@@ -5,19 +5,25 @@
#include <ngx_types.h>
#include <ngx_time.h>
#include <ngx_socket.h>
-#include <ngx_files.h>
#include <ngx_errno.h>
#include <ngx_process.h>
-typedef struct ngx_connection_s ngx_connection_t;
+typedef struct ngx_module_s ngx_module_t;
+typedef struct ngx_conf_s ngx_conf_t;
+typedef struct ngx_command_s ngx_command_t;
+
+typedef struct ngx_file_s ngx_file_t;
typedef struct ngx_event_s ngx_event_t;
+typedef struct ngx_connection_s ngx_connection_t;
#include <ngx_log.h>
#include <ngx_alloc.h>
+#include <ngx_string.h>
#include <ngx_hunk.h>
#include <ngx_array.h>
-#include <ngx_string.h>
+#include <ngx_table.h>
#include <ngx_file.h>
+#include <ngx_files.h>
#include <ngx_inet.h>
#include <ngx_conf_file.h>
#include <ngx_os_init.h>
diff --git a/src/core/ngx_file.c b/src/core/ngx_file.c
index b85b4729e..455b785fd 100644
--- a/src/core/ngx_file.c
+++ b/src/core/ngx_file.c
@@ -1,10 +1,6 @@
#include <ngx_config.h>
#include <ngx_core.h>
-#include <ngx_hunk.h>
-#include <ngx_array.h>
-#include <ngx_file.h>
-#include <ngx_files.h>
static int ngx_temp_number;
diff --git a/src/core/ngx_file.h b/src/core/ngx_file.h
index 442f843b6..6f521c251 100644
--- a/src/core/ngx_file.h
+++ b/src/core/ngx_file.h
@@ -2,11 +2,9 @@
#define _NGX_FILE_H_INCLUDED_
-#include <ngx_log.h>
-#include <ngx_alloc.h>
-#include <ngx_string.h>
+#include <ngx_config.h>
+#include <ngx_core.h>
-typedef struct ngx_file_s ngx_file_t;
struct ngx_file_s {
ngx_fd_t fd;
diff --git a/src/core/ngx_hunk.c b/src/core/ngx_hunk.c
index 691387f96..32a52c928 100644
--- a/src/core/ngx_hunk.c
+++ b/src/core/ngx_hunk.c
@@ -1,6 +1,6 @@
#include <ngx_config.h>
-#include <ngx_hunk.h>
+#include <ngx_core.h>
ngx_hunk_t *ngx_create_temp_hunk(ngx_pool_t *pool, int size,
diff --git a/src/core/ngx_hunk.h b/src/core/ngx_hunk.h
index c0e0dbf7b..b948895a9 100644
--- a/src/core/ngx_hunk.h
+++ b/src/core/ngx_hunk.h
@@ -1,11 +1,9 @@
-#ifndef _NGX_CHUNK_H_INCLUDED_
-#define _NGX_CHUNK_H_INCLUDED_
+#ifndef _NGX_HUNK_H_INCLUDED_
+#define _NGX_HUNK_H_INCLUDED_
#include <ngx_config.h>
-#include <ngx_types.h>
-#include <ngx_file.h>
-#include <ngx_alloc.h>
+#include <ngx_core.h>
/* hunk type */
@@ -35,7 +33,8 @@
-typedef struct ngx_hunk_s ngx_hunk_t;
+typedef struct ngx_hunk_s ngx_hunk_t;
+
struct ngx_hunk_s {
char *pos;
char *last;
@@ -53,7 +52,8 @@ struct ngx_hunk_s {
};
-typedef struct ngx_chain_s ngx_chain_t;
+typedef struct ngx_chain_s ngx_chain_t;
+
struct ngx_chain_s {
ngx_hunk_t *hunk;
ngx_chain_t *next;
@@ -83,4 +83,4 @@ ngx_hunk_t *ngx_create_temp_hunk(ngx_pool_t *pool, int size,
} while (0);
-#endif /* _NGX_CHUNK_H_INCLUDED_ */
+#endif /* _NGX_HUNK_H_INCLUDED_ */
diff --git a/src/core/ngx_inet.c b/src/core/ngx_inet.c
index b566e1a25..55b8354bd 100644
--- a/src/core/ngx_inet.c
+++ b/src/core/ngx_inet.c
@@ -1,7 +1,6 @@
#include <ngx_config.h>
-#include <ngx_string.h>
-#include <ngx_inet.h>
+#include <ngx_core.h>
/* AF_INET only */
diff --git a/src/core/ngx_log.c b/src/core/ngx_log.c
index aff3998eb..55807ef7c 100644
--- a/src/core/ngx_log.c
+++ b/src/core/ngx_log.c
@@ -14,6 +14,36 @@
#include <ngx_core.h>
+static char *ngx_set_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
+
+
+static ngx_str_t errlog_name = ngx_string("errlog");
+
+static ngx_command_t ngx_errlog_commands[] = {
+
+ {ngx_string("error_log"),
+ NGX_MAIN_CONF|NGX_CONF_TAKE1,
+ ngx_set_error_log,
+ 0,
+ 0,
+ NULL},
+
+ ngx_null_command
+};
+
+
+ngx_module_t ngx_errlog_module = {
+ NGX_MODULE,
+ &errlog_name, /* module context */
+ ngx_errlog_commands, /* module directives */
+ NGX_CORE_MODULE, /* module type */
+ NULL /* init module */
+};
+
+
+static ngx_log_t ngx_log;
+
+
static const char *err_levels[] = {
"stderr", "emerg", "alert", "crit", "error",
"warn", "notice", "info", "debug"
@@ -33,6 +63,9 @@ void ngx_log_error_core(int level, ngx_log_t *log, ngx_err_t err,
#if (HAVE_VARIADIC_MACROS)
va_list args;
#endif
+#if (WIN32)
+ int written;
+#endif
ngx_localtime(&tm);
len = ngx_snprintf(errstr, sizeof(errstr), "%4d/%02d/%02d %02d:%02d:%02d",
@@ -87,10 +120,15 @@ void ngx_log_error_core(int level, ngx_log_t *log, ngx_err_t err,
#if (WIN32)
errstr[len++] = '\r';
-#endif
errstr[len++] = '\n';
-
+ if (log->fd) {
+ WriteFile(log->fd, errstr, len, &written, NULL);
+ }
+#else
+ errstr[len++] = '\n';
write(log->fd, errstr, len);
+#endif
+
#if 0
errstr[len] = '\0';
@@ -137,6 +175,8 @@ void ngx_assert_core(ngx_log_t *log, const char *fmt, ...)
#endif
+#if 0
+
void ngx_log_stderr(ngx_event_t *ev)
{
char errstr[MAX_ERROR_STR];
@@ -165,3 +205,79 @@ void ngx_log_stderr(ngx_event_t *ev)
ngx_log_error(NGX_LOG_STDERR, &ngx_log, 0, "%s", errstr);
}
}
+
+#endif
+
+
+static char *ngx_set_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
+{
+ return ngx_log_set_errlog(cf, cmd, &ngx_log);
+}
+
+
+
+ngx_log_t *ngx_log_init_errlog()
+{
+#if (WIN32)
+ ngx_log.fd = GetStdHandle(STD_ERROR_HANDLE);
+
+ if (ngx_log.fd == NGX_INVALID_FILE) {
+ /* TODO: where we can log error ? */
+ return NULL;
+
+ } else if (ngx_log.fd == NULL) {
+ /* there are no associated standard handles */
+ /* TODO: where we can log possible errors ? */
+ }
+
+#else
+ ngx_log.fd = STDERR_FILENO;
+#endif
+
+ ngx_log.log_level = NGX_LOG_INFO;
+ /* STUB */ ngx_log.log_level = NGX_LOG_DEBUG;
+
+ return &ngx_log;
+}
+
+
+char *ngx_log_set_errlog(ngx_conf_t *cf, ngx_command_t *cmd, ngx_log_t *log)
+{
+ int len;
+ ngx_err_t err;
+ ngx_str_t *value;
+
+ value = cf->args->elts;
+
+ log->fd = ngx_open_file(value[1].data,
+ NGX_FILE_RDWR,
+ NGX_FILE_CREATE_OR_OPEN|NGX_FILE_APPEND);
+
+ if (log->fd == NGX_INVALID_FILE) {
+ err = ngx_errno;
+ len = ngx_snprintf(ngx_conf_errstr, sizeof(ngx_conf_errstr) - 1,
+ ngx_open_file_n " \"%s\" failed (%d: ",
+ value[1].data, err);
+ len += ngx_strerror_r(err, ngx_conf_errstr + len,
+ sizeof(ngx_conf_errstr) - len - 1);
+ ngx_conf_errstr[len++] = ')';
+ ngx_conf_errstr[len++] = '\0';
+ return ngx_conf_errstr;
+ }
+
+#if (WIN32)
+ if (ngx_file_append_mode(log->fd) == NGX_ERROR) {
+ err = ngx_errno;
+ len = ngx_snprintf(ngx_conf_errstr, sizeof(ngx_conf_errstr) - 1,
+ ngx_file_append_mode_n " \"%s\" failed (%d: ",
+ value[1].data, err);
+ len += ngx_strerror_r(err, ngx_conf_errstr + len,
+ sizeof(ngx_conf_errstr) - len - 1);
+ ngx_conf_errstr[len++] = ')';
+ ngx_conf_errstr[len++] = '\0';
+ return ngx_conf_errstr;
+ }
+#endif
+
+ return NGX_CONF_OK;
+}
diff --git a/src/core/ngx_log.h b/src/core/ngx_log.h
index b549d80d9..d1d382c45 100644
--- a/src/core/ngx_log.h
+++ b/src/core/ngx_log.h
@@ -2,8 +2,9 @@
#define _NGX_LOG_H_INCLUDED_
-#include <ngx_types.h>
-#include <ngx_errno.h>
+#include <ngx_config.h>
+#include <ngx_core.h>
+
typedef enum {
NGX_LOG_STDERR = 0,
@@ -160,4 +161,11 @@ void ngx_assert_core(ngx_log_t *log, const char *fmt, ...);
#endif /* VARIADIC MACROS */
+ngx_log_t *ngx_log_init_errlog();
+char *ngx_log_set_errlog(ngx_conf_t *cf, ngx_command_t *cmd, ngx_log_t *log);
+
+
+extern ngx_module_t ngx_errlog_module;
+
+
#endif /* _NGX_LOG_H_INCLUDED_ */
diff --git a/src/core/ngx_modules.c b/src/core/ngx_modules.c
index 27d150cd2..b25c413e1 100644
--- a/src/core/ngx_modules.c
+++ b/src/core/ngx_modules.c
@@ -1,9 +1,9 @@
#include <ngx_config.h>
-
-#include <ngx_conf_file.h>
+#include <ngx_core.h>
+extern ngx_module_t ngx_errlog_module;
extern ngx_module_t ngx_events_module;
extern ngx_module_t ngx_event_module;
@@ -42,6 +42,10 @@ extern ngx_module_t ngx_http_log_module;
ngx_module_t *ngx_modules[] = {
+ /* core */
+
+ &ngx_errlog_module,
+
/* events */
&ngx_events_module,
diff --git a/src/core/ngx_sendfile.c b/src/core/ngx_sendfile.c
deleted file mode 100644
index e930fe53b..000000000
--- a/src/core/ngx_sendfile.c
+++ /dev/null
@@ -1,25 +0,0 @@
-
-#include <ngx_config.h>
-
-#if !(HAVE_SENDFILE)
-
-#include <ngx_core.h>
-#include <ngx_log.h>
-#include <ngx_socket.h>
-#include <ngx_sendv.h>
-
-int ngx_sendfile(ngx_socket_t s,
- ngx_iovec_t *headers, int hdr_cnt,
- ngx_fd_t fd, off_t offset, size_t nbytes,
- ngx_iovec_t *trailers, int trl_cnt,
- off_t *sent,
- ngx_log_t *log)
-{
- ngx_log_error(NGX_LOG_INFO, log, 0,
- "ngx_sendfile: sendfile is not implemented");
-
-
- return NGX_ERROR;
-}
-
-#endif
diff --git a/src/core/ngx_sendfile.h b/src/core/ngx_sendfile.h
deleted file mode 100644
index 3c211f51d..000000000
--- a/src/core/ngx_sendfile.h
+++ /dev/null
@@ -1,23 +0,0 @@
-#ifndef _NGX_SENDFILE_H_INCLUDED_
-#define _NGX_SENDFILE_H_INCLUDED_
-
-
-#include <ngx_config.h>
-#include <ngx_types.h>
-#include <ngx_files.h>
-#include <ngx_socket.h>
-#include <ngx_log.h>
-#include <ngx_connection.h>
-#include <ngx_sendv.h>
-
-int ngx_sendfile(ngx_connection_t *c,
- ngx_iovec_t *headers, int hdr_cnt,
- ngx_fd_t fd, off_t offset, size_t nbytes,
- ngx_iovec_t *trailers, int trl_cnt,
- off_t *sent, u_int flags);
-
-
-extern u_int ngx_sendfile_flags;
-
-
-#endif /* _NGX_SENDFILE_H_INCLUDED_ */
diff --git a/src/core/ngx_server.h b/src/core/ngx_server.h
deleted file mode 100644
index 6372b9add..000000000
--- a/src/core/ngx_server.h
+++ /dev/null
@@ -1,17 +0,0 @@
-#ifndef _NGX_SERVER_H_INCLUDED_
-#define _NGX_SERVER_H_INCLUDED_
-
-
-#include <ngx_config.h>
-#include <ngx_types.h>
-#include <ngx_alloc.h>
-
-typedef struct {
- int log_level;
- ngx_pool_t *pool;
- int (*handler)(void *data);
- int buff_size;
-} ngx_server_t;
-
-
-#endif /* _NGX_SERVER_H_INCLUDED_ */
diff --git a/src/core/ngx_string.c b/src/core/ngx_string.c
index 56a9861c4..312e81992 100644
--- a/src/core/ngx_string.c
+++ b/src/core/ngx_string.c
@@ -1,7 +1,6 @@
#include <ngx_config.h>
#include <ngx_core.h>
-#include <ngx_string.h>
char *ngx_cpystrn(char *dst, char *src, size_t n)
diff --git a/src/core/ngx_string.h b/src/core/ngx_string.h
index daf5f00b7..036194bde 100644
--- a/src/core/ngx_string.h
+++ b/src/core/ngx_string.h
@@ -3,6 +3,7 @@
#include <ngx_config.h>
+#include <ngx_core.h>
typedef struct {
diff --git a/src/core/ngx_table.h b/src/core/ngx_table.h
index 99366482f..f49ec3af5 100644
--- a/src/core/ngx_table.h
+++ b/src/core/ngx_table.h
@@ -3,9 +3,8 @@
#include <ngx_config.h>
-#include <ngx_string.h>
-#include <ngx_alloc.h>
-#include <ngx_array.h>
+#include <ngx_core.h>
+
typedef ngx_array_t ngx_table_t;
@@ -14,6 +13,7 @@ typedef struct {
ngx_str_t value;
} ngx_table_elt_t;
+
#define ngx_create_table(p, n) ngx_create_array(p, n, 2 * sizeof(ngx_str_t))
#define ngx_push_table(t) ngx_push_array(t)
diff --git a/src/event/ngx_event_accept.c b/src/event/ngx_event_accept.c
index 77ba8edfa..6f6e5a4ff 100644
--- a/src/event/ngx_event_accept.c
+++ b/src/event/ngx_event_accept.c
@@ -78,7 +78,7 @@ void ngx_event_accept(ngx_event_t *ev)
ls->addr_text.data);
}
- sleep(1);
+ ngx_msleep(1000);
ngx_destroy_pool(pool);
return;
diff --git a/src/event/ngx_event_acceptex.c b/src/event/ngx_event_acceptex.c
index fceb725d5..288fd2b43 100644
--- a/src/event/ngx_event_acceptex.c
+++ b/src/event/ngx_event_acceptex.c
@@ -1,11 +1,9 @@
#include <ngx_config.h>
-
#include <ngx_core.h>
-#include <ngx_types.h>
-#include <ngx_log.h>
+
#include <ngx_listen.h>
-#include <ngx_connection.h>
+
#include <ngx_event.h>
#include <ngx_event_close.h>
#include <ngx_iocp_module.h>
@@ -14,10 +12,7 @@
-/* This function should always return NGX_OK even there are some failures
- because if we return NGX_ERROR then listening socket would be closed */
-
-int ngx_event_acceptex(ngx_event_t *ev)
+void ngx_event_acceptex(ngx_event_t *ev)
{
ngx_connection_t *c;
@@ -25,25 +20,23 @@ int ngx_event_acceptex(ngx_event_t *ev)
if (ev->ovlp.error) {
ngx_log_error(NGX_LOG_CRIT, ev->log, ev->ovlp.error,
- "AcceptEx(%s) falied", c->addr_text.data);
- return NGX_OK;
+ "AcceptEx() falied for %s", c->addr_text.data);
+ return;
}
-#if 0
-
- /* can we do SO_UPDATE_ACCEPT_CONTEXT just before shutdown() ???
+ /* TODO: can we do SO_UPDATE_ACCEPT_CONTEXT just before shutdown() ???
or AcceptEx's context will be lost ??? */
/* SO_UPDATE_ACCEPT_CONTEXT is required for shutdown() to work */
- if (setsockopt(context->accept_socket, SOL_SOCKET,
- SO_UPDATE_ACCEPT_CONTEXT, (char *)&nsd,
- sizeof(nsd))) {
- ap_log_error(APLOG_MARK, APLOG_ERR, WSAGetLastError(), server_conf,
- "setsockopt(SO_UPDATE_ACCEPT_CONTEXT) failed.");
-
- /* non fatal - we can not only do lingering close */
-
-#endif
+ if (setsockopt(c->fd, SOL_SOCKET, SO_UPDATE_ACCEPT_CONTEXT,
+ (char *)&c->listening->fd, sizeof(ngx_socket_t)) == -1)
+ {
+ ngx_log_error(NGX_LOG_CRIT, ev->log, ngx_socket_errno,
+ "setsockopt(SO_UPDATE_ACCEPT_CONTEXT) failed for %s",
+ c->addr_text.data);
+
+ /* non fatal - we can not only do lingering close */
+ }
getacceptexsockaddrs(c->data, 0,
c->socklen + 16, c->socklen + 16,
@@ -57,7 +50,7 @@ int ngx_event_acceptex(ngx_event_t *ev)
c->handler(c);
- return NGX_OK;
+ return;
}
diff --git a/src/http/modules/ngx_http_log_handler.c b/src/http/modules/ngx_http_log_handler.c
index f61461ce7..38aa2331d 100644
--- a/src/http/modules/ngx_http_log_handler.c
+++ b/src/http/modules/ngx_http_log_handler.c
@@ -198,5 +198,19 @@ static char *ngx_http_log_set_log(ngx_conf_t *cf, ngx_command_t *cmd,
return ngx_conf_errstr;
}
+#if (WIN32)
+ if (ngx_file_append_mode(lcf->file.fd) == NGX_ERROR) {
+ err = ngx_errno;
+ len = ngx_snprintf(ngx_conf_errstr, sizeof(ngx_conf_errstr) - 1,
+ ngx_file_appned_mode_n " \"%s\" failed (%d: ",
+ lcf->file.name.data, err);
+ len += ngx_strerror_r(err, ngx_conf_errstr + len,
+ sizeof(ngx_conf_errstr) - len - 1);
+ ngx_conf_errstr[len++] = ')';
+ ngx_conf_errstr[len++] = '\0';
+ return ngx_conf_errstr;
+ }
+#endif
+
return NGX_CONF_OK;
}
diff --git a/src/http/modules/ngx_http_range_filter.c b/src/http/modules/ngx_http_range_filter.c
index d2696fd2d..d32123b12 100644
--- a/src/http/modules/ngx_http_range_filter.c
+++ b/src/http/modules/ngx_http_range_filter.c
@@ -252,7 +252,7 @@ static int ngx_http_range_header_filter(ngx_http_request_t *r)
r->headers_out.content_length);
len += ctx->boundary_header.len + range[i].content_range.len
- + range[i].end - range[i].start;
+ + (size_t) (range[i].end - range[i].start);
}
r->headers_out.content_length = len;
diff --git a/src/http/ngx_http.c b/src/http/ngx_http.c
index 5612d6367..44b650e0c 100644
--- a/src/http/ngx_http.c
+++ b/src/http/ngx_http.c
@@ -1,13 +1,10 @@
#include <ngx_config.h>
+#include <ngx_core.h>
-#include <ngx_string.h>
-#include <ngx_socket.h>
#include <ngx_listen.h>
-#include <ngx_inet.h>
+
#include <ngx_http.h>
-#include <ngx_http_config.h>
-#include <ngx_http_core_module.h>
static void ngx_http_init_filters(ngx_pool_t *pool, ngx_module_t **modules);
diff --git a/src/http/ngx_http.h b/src/http/ngx_http.h
index 4a6e3ced2..c2608a34b 100644
--- a/src/http/ngx_http.h
+++ b/src/http/ngx_http.h
@@ -3,15 +3,7 @@
#include <ngx_config.h>
-
-#include <ngx_types.h>
-#include <ngx_string.h>
-#include <ngx_table.h>
-#include <ngx_hunk.h>
-#include <ngx_files.h>
-#include <ngx_connection.h>
-#include <ngx_conf_file.h>
-
+#include <ngx_core.h>
#include <ngx_http_request.h>
#include <ngx_http_config.h>
#include <ngx_http_filter.h>
diff --git a/src/http/ngx_http_core_module.c b/src/http/ngx_http_core_module.c
index b390c9438..08a9980ea 100644
--- a/src/http/ngx_http_core_module.c
+++ b/src/http/ngx_http_core_module.c
@@ -798,8 +798,12 @@ static char *ngx_http_core_merge_srv_conf(ngx_pool_t *pool,
if (conf->listen.nelts == 0) {
ngx_test_null(l, ngx_push_array(&conf->listen), NGX_CONF_ERROR);
l->addr = INADDR_ANY;
+#if (WIN32)
+ l->port = 80;
+#else
/* STUB: getuid() should be cached */
l->port = (getuid() == 0) ? 80 : 8000;
+#endif
l->family = AF_INET;
}
diff --git a/src/http/ngx_http_event.c b/src/http/ngx_http_event.c
index d65fdde48..b4a9ae97d 100644
--- a/src/http/ngx_http_event.c
+++ b/src/http/ngx_http_event.c
@@ -279,6 +279,10 @@ static void ngx_http_process_request_line(ngx_event_t *rev)
/* STUB: we need to handle such URIs */
if (r->complex_uri || r->unusual_uri) {
+ r->request_line.len = r->request_end - r->request_start;
+ r->request_line.data = r->request_start;
+ r->request_line.data[r->request_line.len] = '\0';
+
ngx_http_header_parse_error(r, NGX_HTTP_PARSE_INVALID_REQUEST);
ngx_http_finalize_request(r, NGX_HTTP_BAD_REQUEST);
return;
diff --git a/src/http/ngx_http_header_filter.c b/src/http/ngx_http_header_filter.c
index 583b56dc0..8989f7c0a 100644
--- a/src/http/ngx_http_header_filter.c
+++ b/src/http/ngx_http_header_filter.c
@@ -93,7 +93,6 @@ static int ngx_http_header_filter(ngx_http_request_t *r)
ngx_hunk_t *h;
ngx_chain_t *ch;
ngx_table_elt_t *header;
- ngx_http_range_t *range;
if (r->http_version < NGX_HTTP_VERSION_10) {
return NGX_OK;
diff --git a/src/os/unix/ngx_errno.h b/src/os/unix/ngx_errno.h
index 91ac3ba69..feb9e4a08 100644
--- a/src/os/unix/ngx_errno.h
+++ b/src/os/unix/ngx_errno.h
@@ -5,6 +5,7 @@
#include <errno.h>
#include <string.h>
+
typedef int ngx_err_t;
#define NGX_ENOENT ENOENT
diff --git a/src/os/unix/ngx_time.h b/src/os/unix/ngx_time.h
index 5cd791d0e..4b5fa5949 100644
--- a/src/os/unix/ngx_time.h
+++ b/src/os/unix/ngx_time.h
@@ -24,7 +24,7 @@ void ngx_localtime(ngx_tm_t *tm);
ngx_msec_t ngx_msec(void);
/* STUB */
-#define ngx_time() time(NULL)
+#define ngx_time() time(NULL)
#endif /* _NGX_TIME_H_INCLUDED_ */
diff --git a/src/os/win32/ngx_errno.h b/src/os/win32/ngx_errno.h
index 2378811fe..e94dbe066 100644
--- a/src/os/win32/ngx_errno.h
+++ b/src/os/win32/ngx_errno.h
@@ -3,22 +3,24 @@
#include <ngx_config.h>
+#include <ngx_core.h>
-typedef DWORD ngx_err_t;
+
+typedef DWORD ngx_err_t;
#define ngx_errno GetLastError()
#define ngx_socket_errno WSAGetLastError()
#define ngx_set_socket_errno(err) WSASetLastError(err)
-#define NGX_ENOENT ERROR_FILE_NOT_FOUND
-#define NGX_EACCES ERROR_ACCESS_DENIED
-#define NGX_EEXIST ERROR_FILE_EXISTS
-#define NGX_ENOTDIR ERROR_PATH_NOT_FOUND
-#define NGX_EAGAIN WSAEWOULDBLOCK
-#define NGX_EINPROGRESS WSAEINPROGRESS
-#define NGX_EADDRINUSE WSAEADDRINUSE
-#define NGX_ECONNRESET ECONNRESET
-#define NGX_ETIMEDOUT WSAETIMEDOUT
+#define NGX_ENOENT ERROR_FILE_NOT_FOUND
+#define NGX_EACCES ERROR_ACCESS_DENIED
+#define NGX_EEXIST ERROR_FILE_EXISTS
+#define NGX_ENOTDIR ERROR_PATH_NOT_FOUND
+#define NGX_EAGAIN WSAEWOULDBLOCK
+#define NGX_EINPROGRESS WSAEINPROGRESS
+#define NGX_EADDRINUSE WSAEADDRINUSE
+#define NGX_ECONNRESET ECONNRESET
+#define NGX_ETIMEDOUT WSAETIMEDOUT
int ngx_strerror_r(ngx_err_t err, char *errstr, size_t size);
diff --git a/src/os/win32/ngx_files.c b/src/os/win32/ngx_files.c
index 60e132b2a..3734bdc83 100644
--- a/src/os/win32/ngx_files.c
+++ b/src/os/win32/ngx_files.c
@@ -1,9 +1,7 @@
#include <ngx_config.h>
-
#include <ngx_core.h>
-#include <ngx_types.h>
-#include <ngx_file.h>
+
ssize_t ngx_read_file(ngx_file_t *file, char *buf, size_t size, off_t offset)
{
@@ -18,3 +16,15 @@ ssize_t ngx_read_file(ngx_file_t *file, char *buf, size_t size, off_t offset)
return n;
}
+
+
+int ngx_file_append_mode(ngx_fd_t *fd)
+{
+ if (SetFilePointer(fd, 0, NULL, FILE_END) == 0xFFFFFFFF) {
+ if (GetLastError() != NO_ERROR) {
+ return NGX_ERROR;
+ }
+ }
+
+ return NGX_OK;
+}
diff --git a/src/os/win32/ngx_files.h b/src/os/win32/ngx_files.h
index 08525b992..a23c0e2a0 100644
--- a/src/os/win32/ngx_files.h
+++ b/src/os/win32/ngx_files.h
@@ -3,14 +3,12 @@
#include <ngx_config.h>
-
-#include <ngx_types.h>
-#include <ngx_file.h>
+#include <ngx_core.h>
/* INVALID_FILE_ATTRIBUTES specified but never defined at least in VC6SP2 */
#ifndef INVALID_FILE_ATTRIBUTES
-#define INVALID_FILE_ATTRIBUTES 0xFFFFFFFF
+#define INVALID_FILE_ATTRIBUTES 0xFFFFFFFF
#endif
#define NGX_INVALID_FILE INVALID_HANDLE_VALUE
@@ -19,7 +17,7 @@
#define ngx_open_file(name, access, create) \
- CreateFile(name, flags, \
+ CreateFile(name, access, \
FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, \
NULL, create, FILE_FLAG_BACKUP_SEMANTICS, NULL)
/*
@@ -31,6 +29,11 @@
#define NGX_FILE_RDWR GENERIC_READ|GENERIC_WRITE
#define NGX_FILE_CREATE_OR_OPEN OPEN_ALWAYS
#define NGX_FILE_OPEN OPEN_EXISTING
+#define NGX_FILE_APPEND 0
+
+
+int ngx_file_append_mode(ngx_fd_t fd);
+#define ngx_file_append_mode_n "SetFilePointer()"
#define ngx_open_tempfile(name, persistent) \
@@ -46,7 +49,6 @@
#define ngx_open_tempfile_n "CreateFile()"
-
#define ngx_close_file CloseHandle
#define ngx_close_file_n "CloseHandle()"
diff --git a/src/os/win32/ngx_init.c b/src/os/win32/ngx_init.c
index 4f356a1c2..529233046 100644
--- a/src/os/win32/ngx_init.c
+++ b/src/os/win32/ngx_init.c
@@ -14,11 +14,73 @@ ngx_os_io_t ngx_os_io = {
};
+/* Should these pointers be per protocol ? */
+LPFN_ACCEPTEX acceptex;
+LPFN_GETACCEPTEXSOCKADDRS getacceptexsockaddrs;
+LPFN_TRANSMITFILE transmitfile;
+
+static GUID ae_guid = WSAID_ACCEPTEX;
+static GUID as_guid = WSAID_GETACCEPTEXSOCKADDRS;
+static GUID tf_guid = WSAID_TRANSMITFILE;
+
+
int ngx_os_init(ngx_log_t *log)
{
- if (ngx_init_sockets(log) == NGX_ERROR) {
+ DWORD bytes;
+ SOCKET s;
+ WSADATA wsd;
+
+ /* init Winsock */
+
+ if (WSAStartup(MAKEWORD(2,2), &wsd) != 0) {
+ ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno,
+ "WSAStartup failed");
+ return NGX_ERROR;
+ }
+
+ ngx_log_error(NGX_LOG_INFO, log, 0, "max sockets: %d", wsd.iMaxSockets);
+
+ /* get AcceptEx(), GetAcceptExSockAddrs() and TransmitFile() addresses */
+
+ s = ngx_socket(AF_INET, SOCK_STREAM, IPPROTO_IP, 0);
+ if (s == -1) {
+ ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno,
+ ngx_socket_n " %s falied");
return NGX_ERROR;
}
+ if (WSAIoctl(s, SIO_GET_EXTENSION_FUNCTION_POINTER, &ae_guid, sizeof(GUID),
+ &acceptex, sizeof(LPFN_ACCEPTEX), &bytes, NULL, NULL) == -1) {
+
+ ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno,
+ "WSAIoctl(SIO_GET_EXTENSION_FUNCTION_POINTER, "
+ "WSAID_ACCEPTEX) failed");
+ return NGX_ERROR;
+ }
+
+ if (WSAIoctl(s, SIO_GET_EXTENSION_FUNCTION_POINTER, &as_guid, sizeof(GUID),
+ &getacceptexsockaddrs, sizeof(LPFN_GETACCEPTEXSOCKADDRS),
+ &bytes, NULL, NULL) == -1) {
+
+ ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno,
+ "WSAIoctl(SIO_GET_EXTENSION_FUNCTION_POINTER, "
+ "WSAID_ACCEPTEX) failed");
+ return NGX_ERROR;
+ }
+
+ if (WSAIoctl(s, SIO_GET_EXTENSION_FUNCTION_POINTER, &tf_guid, sizeof(GUID),
+ &transmitfile, sizeof(LPFN_TRANSMITFILE), &bytes,
+ NULL, NULL) == -1) {
+ ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno,
+ "WSAIoctl(SIO_GET_EXTENSION_FUNCTION_POINTER, "
+ "WSAID_TRANSMITFILE) failed");
+ return NGX_ERROR;
+ }
+
+ if (ngx_close_socket(s) == -1) {
+ ngx_log_error(NGX_LOG_ALERT, log, ngx_socket_errno,
+ ngx_close_socket_n " failed");
+ }
+
return NGX_OK;
}
diff --git a/src/os/win32/ngx_os_init.h b/src/os/win32/ngx_os_init.h
index 5c445ace6..4a00a3a05 100644
--- a/src/os/win32/ngx_os_init.h
+++ b/src/os/win32/ngx_os_init.h
@@ -3,7 +3,7 @@
#include <ngx_config.h>
-#include <ngx_log.h>
+#include <ngx_core.h>
int ngx_os_init(ngx_log_t *log);
diff --git a/src/os/win32/ngx_socket.c b/src/os/win32/ngx_socket.c
index f289a33e7..e3f6f5c96 100644
--- a/src/os/win32/ngx_socket.c
+++ b/src/os/win32/ngx_socket.c
@@ -1,76 +1,7 @@
#include <ngx_config.h>
-
#include <ngx_core.h>
-#include <ngx_log.h>
-#include <ngx_errno.h>
-#include <ngx_socket.h>
-
-
-/* These pointers should be per protocol ? */
-LPFN_ACCEPTEX acceptex;
-LPFN_GETACCEPTEXSOCKADDRS getacceptexsockaddrs;
-LPFN_TRANSMITFILE transmitfile;
-
-static GUID ae_guid = WSAID_ACCEPTEX;
-static GUID as_guid = WSAID_GETACCEPTEXSOCKADDRS;
-static GUID tf_guid = WSAID_TRANSMITFILE;
-
-
-int ngx_init_sockets(ngx_log_t *log)
-{
- DWORD bytes;
- SOCKET s;
- WSADATA wsd;
-
- if (WSAStartup(MAKEWORD(2,2), &wsd) != 0) {
- ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno,
- "WSAStartup failed");
- return NGX_ERROR;
- }
-
- s = ngx_socket(AF_INET, SOCK_STREAM, IPPROTO_IP, 0);
- if (s == -1) {
- ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno,
- ngx_socket_n " %s falied");
- return NGX_ERROR;
- }
- if (WSAIoctl(s, SIO_GET_EXTENSION_FUNCTION_POINTER, &ae_guid, sizeof(GUID),
- &acceptex, sizeof(LPFN_ACCEPTEX), &bytes, NULL, NULL) == -1) {
-
- ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno,
- "WSAIoctl(SIO_GET_EXTENSION_FUNCTION_POINTER, "
- "WSAID_ACCEPTEX) failed");
- return NGX_ERROR;
- }
-
- if (WSAIoctl(s, SIO_GET_EXTENSION_FUNCTION_POINTER, &as_guid, sizeof(GUID),
- &getacceptexsockaddrs, sizeof(LPFN_GETACCEPTEXSOCKADDRS),
- &bytes, NULL, NULL) == -1) {
-
- ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno,
- "WSAIoctl(SIO_GET_EXTENSION_FUNCTION_POINTER, "
- "WSAID_ACCEPTEX) failed");
- return NGX_ERROR;
- }
-
- if (WSAIoctl(s, SIO_GET_EXTENSION_FUNCTION_POINTER, &tf_guid, sizeof(GUID),
- &transmitfile, sizeof(LPFN_TRANSMITFILE), &bytes,
- NULL, NULL) == -1) {
- ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno,
- "WSAIoctl(SIO_GET_EXTENSION_FUNCTION_POINTER, "
- "WSAID_TRANSMITFILE) failed");
- return NGX_ERROR;
- }
-
- if (ngx_close_socket(s) == -1) {
- ngx_log_error(NGX_LOG_ALERT, log, ngx_socket_errno,
- ngx_close_socket_n " failed");
- }
-
- return NGX_OK;
-}
int ngx_nonblocking(ngx_socket_t s)
{
@@ -79,6 +10,7 @@ int ngx_nonblocking(ngx_socket_t s)
return ioctlsocket(s, FIONBIO, &nb);
}
+
int ngx_blocking(ngx_socket_t s)
{
unsigned long nb = 0;
diff --git a/src/os/win32/ngx_socket.h b/src/os/win32/ngx_socket.h
index f94d45c31..f86a39aff 100644
--- a/src/os/win32/ngx_socket.h
+++ b/src/os/win32/ngx_socket.h
@@ -3,7 +3,8 @@
#include <ngx_config.h>
-#include <ngx_log.h>
+#include <ngx_core.h>
+
#define NGX_WRITE_SHUTDOWN SD_SEND
@@ -12,7 +13,6 @@
typedef SOCKET ngx_socket_t;
typedef int socklen_t;
-int ngx_init_sockets(ngx_log_t *log);
#define ngx_socket(af, type, proto, flags) \
WSASocket(af, type, proto, NULL, 0, flags)
diff --git a/src/os/win32/ngx_time.h b/src/os/win32/ngx_time.h
index 25eef9556..4cd84e564 100644
--- a/src/os/win32/ngx_time.h
+++ b/src/os/win32/ngx_time.h
@@ -2,7 +2,9 @@
#define _NGX_TIME_H_INCLUDED_
-#include <windows.h>
+#include <ngx_config.h>
+#include <ngx_core.h>
+
typedef unsigned int ngx_msec_t;
#define NGX_MAX_MSEC ~0
@@ -24,7 +26,7 @@ typedef FILETIME ngx_mtime_t;
#define ngx_msec GetTickCount
/* STUB */
-#define ngx_time() time(NULL)
+#define ngx_time() time(NULL)
#endif /* _NGX_TIME_H_INCLUDED_ */
diff --git a/src/os/win32/ngx_types.h b/src/os/win32/ngx_types.h
index d5f0d927d..cf8db97b3 100644
--- a/src/os/win32/ngx_types.h
+++ b/src/os/win32/ngx_types.h
@@ -3,6 +3,7 @@
#include <ngx_config.h>
+#include <ngx_core.h>
typedef unsigned __int32 u_int32_t;