]> git.kaiwu.me - nginx.git/commitdiff
nginx-0.0.1-2003-06-03-19:42:58 import
authorIgor Sysoev <igor@sysoev.ru>
Tue, 3 Jun 2003 15:42:58 +0000 (15:42 +0000)
committerIgor Sysoev <igor@sysoev.ru>
Tue, 3 Jun 2003 15:42:58 +0000 (15:42 +0000)
43 files changed:
src/core/nginx.c
src/core/ngx_alloc.c
src/core/ngx_alloc.h
src/core/ngx_array.c
src/core/ngx_array.h
src/core/ngx_conf_file.c
src/core/ngx_conf_file.h
src/core/ngx_connection.h
src/core/ngx_core.h
src/core/ngx_file.c
src/core/ngx_file.h
src/core/ngx_hunk.c
src/core/ngx_hunk.h
src/core/ngx_inet.c
src/core/ngx_log.c
src/core/ngx_log.h
src/core/ngx_modules.c
src/core/ngx_sendfile.c [deleted file]
src/core/ngx_sendfile.h [deleted file]
src/core/ngx_server.h [deleted file]
src/core/ngx_string.c
src/core/ngx_string.h
src/core/ngx_table.h
src/event/ngx_event_accept.c
src/event/ngx_event_acceptex.c
src/http/modules/ngx_http_log_handler.c
src/http/modules/ngx_http_range_filter.c
src/http/ngx_http.c
src/http/ngx_http.h
src/http/ngx_http_core_module.c
src/http/ngx_http_event.c
src/http/ngx_http_header_filter.c
src/os/unix/ngx_errno.h
src/os/unix/ngx_time.h
src/os/win32/ngx_errno.h
src/os/win32/ngx_files.c
src/os/win32/ngx_files.h
src/os/win32/ngx_init.c
src/os/win32/ngx_os_init.h
src/os/win32/ngx_socket.c
src/os/win32/ngx_socket.h
src/os/win32/ngx_time.h
src/os/win32/ngx_types.h

index 820d6e3f4c36c5dbc13f8ab9825b49a704155f7d..295e2a946772d21e1bfc501bb458267e0f09a9d9 100644 (file)
@@ -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;
index f2608f77dd114722b228e13a91589f20a8f10b17..af59a223c864a86e76b0abae44ae7331919bee87 100644 (file)
@@ -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)
index 1d2f2f7eaf51a67c6b93a43a400ce541e4e06af6..b63f4bdc18df848bf3f3a03e605e1772c1c46297 100644 (file)
@@ -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.
 
 
 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;
index dd91141c226ef6b77425436343dfbdeaea837055..8d5cec98937dcc8fff89e232ee55eaada7fdceeb 100644 (file)
@@ -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)
index 22cb3fc35d0855c62b9679d13ef2aafbb8ad2cbb..d6443d6a73f6e8ae8bc437a650d6cf990fa4ff27 100644 (file)
@@ -3,8 +3,8 @@
 
 
 #include <ngx_config.h>
+#include <ngx_core.h>
 
-#include <ngx_alloc.h>
 
 typedef struct {
     void       *elts;
index 241c7a89744ef7fb977ce5eaed8441a038dc5336..306bf1ccd1b8ead8dbe837ea18f1e510e4717200 100644 (file)
@@ -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];
index 20747b62430514fd2850b5df71b6645f3133d213..b517ff0f960d42dfd54d0df44528663a8b272918 100644 (file)
@@ -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>
 
 
 /*
 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 {
index c3e9e0902f08f051bfa0e9ade99cdaabcaf45bc3..c75fd1f06145a2e31511fc3d2e14fb56eb810827 100644 (file)
@@ -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;
index a612200d1c9c4076fb2bc53df6ea2f131fee756d..8963d08ff63e3f43bd48fc3714a4c6be8276ede4 100644 (file)
@@ -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>
index b85b4729ee6b1000feb362a46e6eed3d60e9ffc8..455b785fdafee3572b1214eeaa798469d360c929 100644 (file)
@@ -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;
index 442f843b6060a7696f7343f7c937cffc4dba52eb..6f521c251f1f8cf6bafea57790b4f63e2c813bc3 100644 (file)
@@ -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;
index 691387f962863fd12c9f8f1ae6ff7e41ecdac186..32a52c928ee27adc70e10b16636b4983b682e833 100644 (file)
@@ -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,
index c0e0dbf7b6bef57c25a3968a9eb2f424be7c4a2f..b948895a905f60f2d5399aedd61804b9320f0a97 100644 (file)
@@ -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_ */
index b566e1a254b3255526c4faa2ff2fcdb30a0d7c3e..55b8354bd2c9b48fa1292bc9a939404a796cd7e2 100644 (file)
@@ -1,7 +1,6 @@
 
 #include <ngx_config.h>
-#include <ngx_string.h>
-#include <ngx_inet.h>
+#include <ngx_core.h>
 
 
 /* AF_INET only */
index aff3998eb34f427697bc3ec2cc2636692ded3f1a..55807ef7c60b727eb1295e23cd29dd5003bbcdac 100644 (file)
 #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;
+}
index b549d80d9ff693a4a8646caa2217fdb3d2207878..d1d382c456ae3dc379a40f3a25f3fc42678d341d 100644 (file)
@@ -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_ */
index 27d150cd2b2be9bf328d6e0efd1448d1142a7f0f..b25c413e1f52ba7c558d2313b7e1c87c9658423b 100644 (file)
@@ -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 (file)
index e930fe5..0000000
+++ /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 (file)
index 3c211f5..0000000
+++ /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 (file)
index 6372b9a..0000000
+++ /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_ */
index 56a9861c4fbae95261da2e9921efd682bc5e895b..312e81992f71fb1eeefdb5bb8120c4c09c7454e3 100644 (file)
@@ -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)
index daf5f00b7c0f62f010256e1085feb7d30cb226e9..036194bdee74c1b2803ae79a5cd3b6244e99940e 100644 (file)
@@ -3,6 +3,7 @@
 
 
 #include <ngx_config.h>
+#include <ngx_core.h>
 
 
 typedef struct {
index 99366482fdcdc6d38ed197775c3a25c01fa97b39..f49ec3af5bb3ba0057f9035cd3660b53788ff471 100644 (file)
@@ -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)
 
index 77ba8edfadc48793796d210617e8eac1805716ca..6f6e5a4ff49b8c45a85470cf86da683ed683a45b 100644 (file)
@@ -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;
index fceb725d5c3140e57f8123d59e2ba9a72ff337f7..288fd2b43502af77c28c2245f97fb169034ea38a 100644 (file)
@@ -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>
 
 
 
-/* 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;
 
 }
 
index f61461ce71ce279f5c913924f0c8478a4f798561..38aa2331da4a39f32370ffbbee40bc936350cfb4 100644 (file)
@@ -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;
 }
index d2696fd2d982d194a42c3874792821d7898ed267..d32123b12cb82e6184d6e96741a936d5c8873777 100644 (file)
@@ -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;
index 5612d63670e89ca21ca9afbf4bb69ea09ae455e0..44b650e0c1dcc06b9d7b062119e91bf197465061 100644 (file)
@@ -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);
index 4a6e3ced297e62f9dae2bdce1e1d73d99ec735cb..c2608a34b2d40fefcc7ea70342c67c25ce845482 100644 (file)
@@ -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>
index b390c9438f05dec079d12444ba64d9b869c661b3..08a9980ea2b938e153674404c1e47c08667c1756 100644 (file)
@@ -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;
     }
 
index d65fdde486eacdf408fa45fe55077848fd28a30a..b4a9ae97d27dfe6597c7c3478e5957a5f56dabf6 100644 (file)
@@ -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;
index 583b56dc0020a979397c932a3dc5cd635cb63f62..8989f7c0a2e6a8a59d488d11a4398a57a14c4443 100644 (file)
@@ -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;
index 91ac3ba6925539e60199e52ce745ca70629b8ed8..feb9e4a08a6f77597b42679916fca7bb56a82459 100644 (file)
@@ -5,6 +5,7 @@
 #include <errno.h>
 #include <string.h>
 
+
 typedef int               ngx_err_t;
 
 #define NGX_ENOENT        ENOENT
index 5cd791d0e9e986e4902e26e7bed82999ed9e0655..4b5fa5949ee127a4901e67f7deef83075a898597 100644 (file)
@@ -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_ */
index 2378811fe713356ce2da390c606a316b72e2cae0..e94dbe0662478a4e619f443745628835f47d1b53 100644 (file)
@@ -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);
 
index 60e132b2ab42e8f61a24a824e4e1d0d50110584f..3734bdc8319b9f252b18ec2196d19e5878ba8589 100644 (file)
@@ -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;
+}
index 08525b992c60f3bb6938c6fac185a01102953604..a23c0e2a04d476321bf9f4c5f2d767ec731cfcd1 100644 (file)
@@ -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)
 /*
 #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()"
 
index 4f356a1c2d47b2eadfc39e0564e52405e6ea5039..5292330467f65d171a27da65836edc196c67bc94 100644 (file)
@@ -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;
 }
index 5c445ace6cf37bf3a5599bdb0fcce35b10495e28..4a00a3a05ab8590fa9e323608c792cc564a38f9f 100644 (file)
@@ -3,7 +3,7 @@
 
 
 #include <ngx_config.h>
-#include <ngx_log.h>
+#include <ngx_core.h>
 
 
 int ngx_os_init(ngx_log_t *log);
index f289a33e7d6e382a206ad19901aff6114ded156a..e3f6f5c9687aee752bee2c2f404370ba2d71b472 100644 (file)
@@ -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;
index f94d45c315633e3b879f88f1dc92a426f704a009..f86a39aff9af9de29e2621e00f5404d853e7f238 100644 (file)
@@ -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)
index 25eef9556aefca52d083ca0d1ee49ba571d55998..4cd84e564b4d5fce5abba67d6982feb983f2dcc9 100644 (file)
@@ -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_ */
index d5f0d927d806e87133f0e9901c2a9ebd42ea9ca0..cf8db97b3d7d45b26a67b7b9c8971729e847a3bb 100644 (file)
@@ -3,6 +3,7 @@
 
 
 #include <ngx_config.h>
+#include <ngx_core.h>
 
 
 typedef unsigned __int32            u_int32_t;