Mercurial > hg > nginx
comparison src/core/nginx.c @ 106:9f9de4deda7e
nginx-0.0.1-2003-06-26-19:35:36 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Thu, 26 Jun 2003 15:35:36 +0000 |
parents | 00bee6e7b485 |
children | b5be4b0448d3 |
comparison
equal
deleted
inserted
replaced
105:00bee6e7b485 | 106:9f9de4deda7e |
---|---|
1 | |
2 | 1 |
3 #include <ngx_config.h> | 2 #include <ngx_config.h> |
4 #include <ngx_core.h> | 3 #include <ngx_core.h> |
5 #include <ngx_event.h> | 4 #include <ngx_event.h> |
6 #include <nginx.h> | 5 #include <nginx.h> |
8 | 7 |
9 | 8 |
10 static int ngx_open_listening_sockets(ngx_log_t *log); | 9 static int ngx_open_listening_sockets(ngx_log_t *log); |
11 | 10 |
12 | 11 |
13 ngx_log_t ngx_log; | 12 void ****ngx_conf_ctx; |
14 ngx_pool_t *ngx_pool; | |
15 void ****ngx_conf_ctx; | |
16 | 13 |
17 | 14 |
18 ngx_os_io_t ngx_io; | 15 ngx_os_io_t ngx_io; |
19 | 16 |
20 | 17 |
26 ngx_array_t ngx_listening_sockets; | 23 ngx_array_t ngx_listening_sockets; |
27 | 24 |
28 | 25 |
29 int main(int argc, char *const *argv) | 26 int main(int argc, char *const *argv) |
30 { | 27 { |
31 int i; | 28 int i; |
32 ngx_str_t conf_file; | 29 ngx_str_t conf_file; |
33 ngx_log_t *log; | 30 ngx_log_t *log; |
31 ngx_pool_t *pool, *old_pool; | |
34 ngx_conf_t conf; | 32 ngx_conf_t conf; |
35 | 33 |
36 ngx_max_sockets = -1; | 34 ngx_max_sockets = -1; |
37 | |
38 #if 0 | |
39 ngx_log.fd = STDERR_FILENO; | |
40 ngx_log.log_level = NGX_LOG_INFO; | |
41 | |
42 /* STUB */ ngx_log.log_level = NGX_LOG_DEBUG; | |
43 #endif | |
44 | 35 |
45 log = ngx_log_init_errlog(); | 36 log = ngx_log_init_errlog(); |
46 | 37 |
47 if (ngx_os_init(log) == NGX_ERROR) { | 38 if (ngx_os_init(log) == NGX_ERROR) { |
48 return 1; | 39 return 1; |
49 } | 40 } |
50 | |
51 ngx_pool = ngx_create_pool(16 * 1024, log); | |
52 /* */ | |
53 | 41 |
54 ngx_max_module = 0; | 42 ngx_max_module = 0; |
55 for (i = 0; ngx_modules[i]; i++) { | 43 for (i = 0; ngx_modules[i]; i++) { |
56 ngx_modules[i]->index = ngx_max_module++; | 44 ngx_modules[i]->index = ngx_max_module++; |
57 } | 45 } |
58 | 46 |
47 #if 0 | |
48 | |
49 ngx_test_null(cycle->pool, ngx_create_pool(16 * 1024, log), 1); | |
50 | |
51 if (ngx_init_conf(cycle) == NGX_ERROR) { | |
52 ngx_destroy_pool(cycle->pool); | |
53 return 1; | |
54 } | |
55 | |
56 /* daemon */ | |
57 | |
59 /* life cycle */ | 58 /* life cycle */ |
60 | 59 |
61 { | 60 { |
61 | |
62 /* forks */ | |
63 | |
64 /* threads */ | |
65 | |
66 for ( ;; ) { | |
67 worker; | |
68 | |
69 new_cycle = ngx_calloc(sizeof(ngx_cycle_t), cycle->log); | |
70 | |
71 if (new_cycle == NULL) { | |
72 continue; | |
73 } | |
74 | |
75 new_cycle->pool = ngx_create_pool(16 * 1024, cycle->log); | |
76 | |
77 if (new_cycle->pool == NULL) { | |
78 ngx_free(new_cycle); | |
79 continue; | |
80 } | |
81 | |
82 if (ngx_init_conf(new_cycle) == NGX_ERROR) { | |
83 ngx_destroy_pool(new_cycle->pool); | |
84 ngx_free(new_cycle); | |
85 continue; | |
86 } | |
87 | |
88 /* update bound listening */ | |
89 | |
90 ngx_destroy_pool(cycle->pool); | |
91 ngx_free(cycle); | |
92 | |
93 cycle = new_cycle; | |
94 break; | |
95 } | |
96 } | |
97 | |
98 return 0; | |
99 | |
100 #endif | |
101 | |
102 /* life cycle */ | |
103 | |
104 { | |
105 old_pool = pool; | |
106 | |
107 pool = ngx_create_pool(16 * 1024, log); | |
108 | |
62 ngx_init_array(ngx_listening_sockets, | 109 ngx_init_array(ngx_listening_sockets, |
63 ngx_pool, 10, sizeof(ngx_listening_t), | 110 pool, 10, sizeof(ngx_listening_t), |
64 1); | 111 1); |
65 | 112 |
66 ngx_memzero(&conf, sizeof(ngx_conf_t)); | 113 ngx_memzero(&conf, sizeof(ngx_conf_t)); |
67 | 114 |
68 ngx_test_null(conf.args, | 115 ngx_test_null(conf.args, |
69 ngx_create_array(ngx_pool, 10, sizeof(ngx_str_t)), | 116 ngx_create_array(pool, 10, sizeof(ngx_str_t)), |
70 1); | 117 1); |
71 | 118 |
72 ngx_test_null(ngx_conf_ctx, | 119 ngx_test_null(ngx_conf_ctx, |
73 ngx_pcalloc(ngx_pool, ngx_max_module * sizeof(void *)), | 120 ngx_pcalloc(pool, ngx_max_module * sizeof(void *)), |
74 1); | 121 1); |
75 | 122 |
76 conf.ctx = ngx_conf_ctx; | 123 conf.ctx = ngx_conf_ctx; |
77 conf.pool = ngx_pool; | 124 conf.pool = pool; |
78 conf.log = log; | 125 conf.log = log; |
79 conf.module_type = NGX_CORE_MODULE; | 126 conf.module_type = NGX_CORE_MODULE; |
80 conf.cmd_type = NGX_MAIN_CONF; | 127 conf.cmd_type = NGX_MAIN_CONF; |
81 | 128 |
82 conf_file.len = sizeof(NGINX_CONF) - 1; | 129 conf_file.len = sizeof(NGINX_CONF) - 1; |
95 | 142 |
96 ngx_io = ngx_os_io; | 143 ngx_io = ngx_os_io; |
97 | 144 |
98 for (i = 0; ngx_modules[i]; i++) { | 145 for (i = 0; ngx_modules[i]; i++) { |
99 if (ngx_modules[i]->init_module) { | 146 if (ngx_modules[i]->init_module) { |
100 if (ngx_modules[i]->init_module(ngx_pool) == NGX_ERROR) { | 147 if (ngx_modules[i]->init_module(pool) == NGX_ERROR) { |
101 return 1; | 148 return 1; |
102 } | 149 } |
103 } | 150 } |
104 } | 151 } |
105 | 152 |
109 | 156 |
110 /* TODO: daemon, once only */ | 157 /* TODO: daemon, once only */ |
111 | 158 |
112 /* TODO: fork */ | 159 /* TODO: fork */ |
113 | 160 |
114 ngx_pre_thread(&ngx_listening_sockets, ngx_pool, log); | 161 ngx_pre_thread(&ngx_listening_sockets, pool, log); |
115 | 162 |
116 /* TODO: threads */ | 163 /* TODO: threads */ |
117 | 164 |
118 /* STUB */ | 165 /* STUB */ |
119 ngx_worker(log); | 166 ngx_worker(log); |
120 } | 167 } |
121 | 168 |
122 return 0; | 169 return 0; |
123 } | 170 } |
124 | 171 |
172 #if 0 | |
173 | |
174 static int ngx_init_conf(ngx_cycle_t *cycle) | |
175 { | |
176 ngx_conf_t conf; | |
177 | |
178 ngx_init_array(cycle->listening, cycle->pool, 10, sizeof(ngx_listening_t), | |
179 NGX_ERROR); | |
180 | |
181 ngx_memzero(&conf, sizeof(ngx_conf_t)); | |
182 | |
183 ngx_test_null(conf.args, | |
184 ngx_create_array(cycle->pool, 10, sizeof(ngx_str_t)), | |
185 NGX_ERROR); | |
186 | |
187 ngx_test_null(ngx_conf_ctx, | |
188 ngx_pcalloc(cycle->pool, ngx_max_module * sizeof(void *)), | |
189 NGX_ERROR); | |
190 | |
191 conf.ctx = ngx_conf_ctx; | |
192 conf.pool = cycle->pool; | |
193 conf.log = cycle->log; | |
194 conf.module_type = NGX_CORE_MODULE; | |
195 conf.cmd_type = NGX_MAIN_CONF; | |
196 | |
197 conf_file.len = sizeof(NGINX_CONF) - 1; | |
198 conf_file.data = NGINX_CONF; | |
199 | |
200 if (ngx_conf_parse(&conf, &conf_file) != NGX_CONF_OK) { | |
201 return NGX_ERROR; | |
202 } | |
203 | |
204 return NGX_OK; | |
205 } | |
206 | |
207 | |
208 #endif | |
125 | 209 |
126 static int ngx_open_listening_sockets(ngx_log_t *log) | 210 static int ngx_open_listening_sockets(ngx_log_t *log) |
127 { | 211 { |
128 int times, failed, reuseaddr, i; | 212 int times, failed, reuseaddr, i; |
129 ngx_err_t err; | 213 ngx_err_t err; |