nginx-0.0.1-2003-05-19-20:39:14 import
diff --git a/src/core/nginx.c b/src/core/nginx.c
index ad0cd57..6fbc33b 100644
--- a/src/core/nginx.c
+++ b/src/core/nginx.c
@@ -4,6 +4,7 @@
#include <ngx_config.h>
#include <ngx_core.h>
+#include <ngx_connection.h>
#include <ngx_os_init.h>
#include <ngx_string.h>
#include <ngx_errno.h>
@@ -13,7 +14,6 @@
#include <ngx_array.h>
#include <ngx_socket.h>
#include <ngx_server.h>
-#include <ngx_connection.h>
#include <ngx_listen.h>
#include <ngx_conf_file.h>
@@ -33,8 +33,12 @@
ngx_server_t ngx_server;
/* */
-ngx_log_t ngx_log;
-ngx_pool_t *ngx_pool;
+ngx_log_t ngx_log;
+ngx_pool_t *ngx_pool;
+void ****ngx_conf_ctx;
+
+
+ngx_os_io_t ngx_io;
int ngx_max_module;
@@ -55,94 +59,76 @@
ngx_log.log_level = NGX_LOG_DEBUG;
if (ngx_os_init(&ngx_log) == NGX_ERROR) {
- exit(1);
+ return 1;
}
ngx_pool = ngx_create_pool(16 * 1024, &ngx_log);
/* */
-#if (WIN32)
-
- if (ngx_init_sockets(&ngx_log) == NGX_ERROR) {
- exit(1);
- }
-
-#else
-
- ngx_set_signals(&ngx_log);
-
-#endif
-
- ngx_init_array(ngx_listening_sockets, ngx_pool, 10, sizeof(ngx_listen_t),
- 1);
-
ngx_max_module = 0;
for (i = 0; ngx_modules[i]; i++) {
ngx_modules[i]->index = ngx_max_module++;
}
- ngx_memzero(&conf, sizeof(ngx_conf_t));
+ /* life cycle */
- ngx_test_null(conf.args, ngx_create_array(ngx_pool, 10, sizeof(ngx_str_t)),
- 1);
+ {
+ ngx_init_array(ngx_listening_sockets,
+ ngx_pool, 10, sizeof(ngx_listen_t),
+ 1);
- ngx_test_null(conf.ctx,
- ngx_pcalloc(ngx_pool, ngx_max_module * sizeof(void *)),
- 1);
+ ngx_memzero(&conf, sizeof(ngx_conf_t));
- conf.pool = ngx_pool;
- conf.log = &ngx_log;
- conf.module_type = NGX_CORE_MODULE_TYPE;
- conf.cmd_type = NGX_MAIN_CONF;
+ ngx_test_null(conf.args,
+ ngx_create_array(ngx_pool, 10, sizeof(ngx_str_t)),
+ 1);
- conf_file.len = sizeof("nginx.conf") - 1;
- conf_file.data = "nginx.conf";
+ ngx_test_null(ngx_conf_ctx,
+ ngx_pcalloc(ngx_pool, ngx_max_module * sizeof(void *)),
+ 1);
- if (ngx_conf_parse(&conf, &conf_file) != NGX_CONF_OK) {
- return 1;
- }
+ conf.ctx = ngx_conf_ctx;
+ conf.pool = ngx_pool;
+ conf.log = &ngx_log;
+ conf.module_type = NGX_CORE_MODULE_TYPE;
+ conf.cmd_type = NGX_MAIN_CONF;
- ngx_init_temp_number();
+ conf_file.len = sizeof("nginx.conf") - 1;
+ conf_file.data = "nginx.conf";
- for (i = 0; ngx_modules[i]; i++) {
- if (ngx_modules[i]->init_module) {
- if (ngx_modules[i]->init_module(ngx_pool) == NGX_ERROR) {
- return 1;
+ if (ngx_conf_parse(&conf, &conf_file) != NGX_CONF_OK) {
+ return 1;
+ }
+
+ ngx_init_temp_number();
+
+ ngx_io = ngx_os_io;
+
+ for (i = 0; ngx_modules[i]; i++) {
+ if (ngx_modules[i]->init_module) {
+ if (ngx_modules[i]->init_module(ngx_pool) == NGX_ERROR) {
+ return 1;
+ }
}
}
- }
- ngx_open_listening_sockets(&ngx_log);
+ ngx_open_listening_sockets(&ngx_log);
- /* TODO: daemon */
+ /* TODO: daemon, once only */
- /* TODO: fork */
+ /* TODO: fork */
- ngx_pre_thread(&ngx_listening_sockets, ngx_pool, &ngx_log);
+ ngx_pre_thread(&ngx_listening_sockets, ngx_pool, &ngx_log);
- /* TODO: threads */
+ /* TODO: threads */
- /* STUB */
- ngx_worker(&ngx_log);
+ /* STUB */
+ ngx_worker(&ngx_log);
+ }
return 0;
}
-#if !(WIN32)
-static void ngx_set_signals(ngx_log_t *log)
-{
- struct sigaction sa;
-
- ngx_memzero(&sa, sizeof(struct sigaction));
- sa.sa_handler = SIG_IGN;
- sigemptyset(&sa.sa_mask);
- if (sigaction(SIGPIPE, &sa, NULL) == -1) {
- ngx_log_error(NGX_LOG_EMERG, log, ngx_errno,
- "sigaction(SIGPIPE, SIG_IGN) failed");
- exit(1);
- }
-}
-#endif
static void ngx_open_listening_sockets(ngx_log_t *log)
{
diff --git a/src/core/ngx_alloc.h b/src/core/ngx_alloc.h
index 722d79c..1d2f2f7 100644
--- a/src/core/ngx_alloc.h
+++ b/src/core/ngx_alloc.h
@@ -42,5 +42,7 @@
void *ngx_palloc(ngx_pool_t *pool, size_t size);
void *ngx_pcalloc(ngx_pool_t *pool, size_t size);
+#define ngx_free free
+
#endif /* _NGX_ALLOC_H_INCLUDED_ */
diff --git a/src/core/ngx_array.h b/src/core/ngx_array.h
index 22c7c4b..22cb3fc 100644
--- a/src/core/ngx_array.h
+++ b/src/core/ngx_array.h
@@ -7,7 +7,7 @@
#include <ngx_alloc.h>
typedef struct {
- char *elts;
+ void *elts;
int nelts;
size_t size;
int nalloc;
diff --git a/src/core/ngx_conf_file.c b/src/core/ngx_conf_file.c
index 3d93f02..99af0af 100644
--- a/src/core/ngx_conf_file.c
+++ b/src/core/ngx_conf_file.c
@@ -19,7 +19,7 @@
{
int i, rc, found;
char *rv;
- void *conf, **pconf;
+ void *conf, **confp;
ngx_str_t *name;
ngx_fd_t fd;
ngx_conf_file_t *prev;
@@ -164,10 +164,10 @@
conf = &(((void **) cf->ctx)[ngx_modules[i]->index]);
} else if (cf->ctx) {
- pconf = *(void **) ((char *) cf->ctx + cmd->conf);
+ confp = *(void **) ((char *) cf->ctx + cmd->conf);
- if (pconf) {
- conf = pconf[*(int *)(ngx_modules[i]->ctx)];
+ if (confp) {
+ conf = confp[*(int *)(ngx_modules[i]->ctx)];
}
}
diff --git a/src/core/ngx_conf_file.h b/src/core/ngx_conf_file.h
index a632625..40b9763 100644
--- a/src/core/ngx_conf_file.h
+++ b/src/core/ngx_conf_file.h
@@ -96,17 +96,35 @@
};
-#define ngx_conf_merge(conf, prev, default) \
+#define ngx_get_conf(module) ngx_conf_ctx[module.index]
+
+
+#define ngx_conf_init_value(conf, default) \
+ if (conf == NGX_CONF_UNSET) { \
+ conf = default; \
+ }
+
+#define ngx_conf_init_size_value(conf, default) \
+ if (conf == NGX_CONF_UNSET) { \
+ conf = default; \
+ }
+
+#define ngx_conf_init_msec_value(conf, default) \
+ if (conf == NGX_CONF_UNSET) { \
+ conf = default; \
+ }
+
+#define ngx_conf_merge_value(conf, prev, default) \
if (conf == NGX_CONF_UNSET) { \
conf = (prev == NGX_CONF_UNSET) ? default : prev; \
}
-#define ngx_conf_msec_merge(conf, prev, default) \
+#define ngx_conf_merge_msec_value(conf, prev, default) \
if (conf == (ngx_msec_t) NGX_CONF_UNSET) { \
conf = (prev == (ngx_msec_t) NGX_CONF_UNSET) ? default : prev; \
}
-#define ngx_conf_size_merge(conf, prev, default) \
+#define ngx_conf_merge_size_value(conf, prev, default) \
if (conf == (size_t) NGX_CONF_UNSET) { \
conf = (prev == (size_t) NGX_CONF_UNSET) ? default : prev; \
}
@@ -126,7 +144,8 @@
char *ngx_conf_set_time_slot(ngx_conf_t *cf, ngx_command_t *cmd, char *conf);
-extern ngx_module_t *ngx_modules[];
+extern ngx_module_t *ngx_modules[];
+extern void ****ngx_conf_ctx;
#endif /* _NGX_HTTP_CONF_FILE_H_INCLUDED_ */
diff --git a/src/core/ngx_config.h b/src/core/ngx_config.h
index 8287d56..e039cd6 100644
--- a/src/core/ngx_config.h
+++ b/src/core/ngx_config.h
@@ -92,6 +92,7 @@
#include <sys/time.h>
#include <sys/socket.h>
#include <sys/uio.h>
+#include <sys/resource.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
diff --git a/src/core/ngx_connection.h b/src/core/ngx_connection.h
index 544101b..8ad48c8 100644
--- a/src/core/ngx_connection.h
+++ b/src/core/ngx_connection.h
@@ -81,12 +81,26 @@
#endif
+typedef struct {
+ ssize_t (*recv)(ngx_connection_t *c, char *buf, size_t size);
+ void *dummy_recv_chain;
+ void *dummy_send;
+ ngx_chain_t *(*send_chain)(ngx_connection_t *c, ngx_chain_t *in);
+} ngx_os_io_t;
+
+
+extern ngx_os_io_t ngx_io;
+
+
+
extern ngx_chain_t *(*ngx_write_chain_proc)
(ngx_connection_t *c, ngx_chain_t *in);
ssize_t ngx_recv_chain(ngx_connection_t *c, ngx_chain_t *ce);
+#if 0
ngx_chain_t *ngx_write_chain(ngx_connection_t *c, ngx_chain_t *in, off_t flush);
+#endif
/* TODO: move it to OS specific file */
diff --git a/src/core/ngx_core.h b/src/core/ngx_core.h
index fd5bb92..acb7fa4 100644
--- a/src/core/ngx_core.h
+++ b/src/core/ngx_core.h
@@ -2,6 +2,23 @@
#define _NGX_CORE_H_INCLUDED_
+#include <ngx_types.h>
+#include <ngx_time.h>
+#include <ngx_socket.h>
+#include <ngx_files.h>
+
+#include <ngx_log.h>
+#include <ngx_alloc.h>
+#include <ngx_hunk.h>
+#include <ngx_array.h>
+#include <ngx_string.h>
+#include <ngx_file.h>
+#include <ngx_conf_file.h>
+#include <ngx_connection.h>
+#include <ngx_os_init.h>
+
+
+
#define NGX_OK 0
#define NGX_ERROR -1
#define NGX_AGAIN -2
diff --git a/src/core/ngx_modules.c b/src/core/ngx_modules.c
index 273c555..db6cf73 100644
--- a/src/core/ngx_modules.c
+++ b/src/core/ngx_modules.c
@@ -7,6 +7,11 @@
extern ngx_module_t ngx_events_module;
extern ngx_module_t ngx_event_module;
+extern ngx_module_t ngx_select_module;
+#if (HAVE_KQUEUE)
+extern ngx_module_t ngx_kqueue_module;
+#endif
+
extern ngx_module_t ngx_http_module;
extern ngx_module_t ngx_http_core_module;
@@ -26,6 +31,11 @@
&ngx_events_module,
&ngx_event_module,
+ &ngx_select_module,
+#if (HAVE_KQUEUE)
+ &ngx_kqueue_module,
+#endif
+
/* http */
&ngx_http_module,
diff --git a/src/core/ngx_string.h b/src/core/ngx_string.h
index e678f73..7c97c13 100644
--- a/src/core/ngx_string.h
+++ b/src/core/ngx_string.h
@@ -53,4 +53,8 @@
int ngx_atoi(char *line, size_t n);
+#define ngx_value_helper(n) #n
+#define ngx_value(n) ngx_value_helper(n)
+
+
#endif /* _NGX_STRING_H_INCLUDED_ */