comparison src/core/nginx.c @ 110:152567c11325

nginx-0.0.1-2003-07-02-22:51:41 import
author Igor Sysoev <igor@sysoev.ru>
date Wed, 02 Jul 2003 18:51:41 +0000
parents a9bc21d63fe4
children 1c002f2b77ed
comparison
equal deleted inserted replaced
109:a9bc21d63fe4 110:152567c11325
13 13
14 14
15 ngx_os_io_t ngx_io; 15 ngx_os_io_t ngx_io;
16 16
17 17
18 ngx_cycle_t *cycle;
19
18 int ngx_max_module; 20 int ngx_max_module;
19 #if 0
20 void *ctx_conf;
21 #endif
22 21
23 int ngx_connection_counter; 22 int ngx_connection_counter;
24
25 #if 0
26 ngx_array_t ngx_listening_sockets;
27 #endif
28 23
29 24
30 #if 1 25 #if 1
31 26
32 int main(int argc, char *const *argv) 27 int main(int argc, char *const *argv)
33 { 28 {
34 int i; 29 int i;
35 ngx_log_t *log; 30 ngx_log_t *log;
36 ngx_conf_t conf; 31 ngx_cycle_t *new_cycle;
37 ngx_cycle_t *cycle, *new_cycle;
38 32
39 /* TODO */ ngx_max_sockets = -1; 33 /* TODO */ ngx_max_sockets = -1;
40 34
41 log = ngx_log_init_errlog(); 35 log = ngx_log_init_errlog();
42 36
58 52
59 /* life cycle */ 53 /* life cycle */
60 54
61 for ( ;; ) { 55 for ( ;; ) {
62 56
57 /* STUB */
58 ngx_io = ngx_os_io;
59
63 /* forks */ 60 /* forks */
64 61
65 ngx_init_temp_number(); 62 ngx_init_temp_number();
63
64 /* STUB */
65 ngx_pre_thread(&cycle->listening, cycle->pool, cycle->log);
66 66
67 /* threads */ 67 /* threads */
68 68
69 for ( ;; ) { 69 for ( ;; ) {
70 70
105 ngx_destroy_pool(pool); 105 ngx_destroy_pool(pool);
106 return NULL; 106 return NULL;
107 } 107 }
108 cycle->pool = pool; 108 cycle->pool = pool;
109 109
110 cycle->log = ngx_log_create_errlog(cycle);
111 if (cycle->log == NULL) {
112 ngx_destroy_pool(pool);
113 return NULL;
114 }
115
116 n = old_cycle ? old_cycle->open_files.nelts : 20; 110 n = old_cycle ? old_cycle->open_files.nelts : 20;
117 cycle->open_files.elts = ngx_pcalloc(pool, n * sizeof(ngx_open_file_t)); 111 cycle->open_files.elts = ngx_pcalloc(pool, n * sizeof(ngx_open_file_t));
118 if (cycle->open_files.elts == NULL) { 112 if (cycle->open_files.elts == NULL) {
119 ngx_destroy_pool(pool); 113 ngx_destroy_pool(pool);
120 return NULL; 114 return NULL;
122 cycle->open_files.nelts = 0; 116 cycle->open_files.nelts = 0;
123 cycle->open_files.size = sizeof(ngx_open_file_t); 117 cycle->open_files.size = sizeof(ngx_open_file_t);
124 cycle->open_files.nalloc = n; 118 cycle->open_files.nalloc = n;
125 cycle->open_files.pool = pool; 119 cycle->open_files.pool = pool;
126 120
121 cycle->log = ngx_log_create_errlog(cycle);
122 if (cycle->log == NULL) {
123 ngx_destroy_pool(pool);
124 return NULL;
125 }
126
127 n = old_cycle ? old_cycle->listening.nelts : 10; 127 n = old_cycle ? old_cycle->listening.nelts : 10;
128 cycle->listening.elts = ngx_pcalloc(pool, n * sizeof(ngx_listening_t)); 128 cycle->listening.elts = ngx_pcalloc(pool, n * sizeof(ngx_listening_t));
129 if (cycle->listening.elts == NULL) { 129 if (cycle->listening.elts == NULL) {
130 ngx_destroy_pool(pool); 130 ngx_destroy_pool(pool);
131 return NULL; 131 return NULL;
149 return NULL; 149 return NULL;
150 } 150 }
151 151
152 conf.ctx = cycle->conf_ctx; 152 conf.ctx = cycle->conf_ctx;
153 conf.cycle = cycle; 153 conf.cycle = cycle;
154 /* STUB */ conf.pool = cycle->pool; 154 /* STUB */ conf.pool = cycle->pool; ngx_conf_ctx = cycle->conf_ctx;
155 conf.log = log; 155 conf.log = log;
156 conf.module_type = NGX_CORE_MODULE; 156 conf.module_type = NGX_CORE_MODULE;
157 conf.cmd_type = NGX_MAIN_CONF; 157 conf.cmd_type = NGX_MAIN_CONF;
158 158
159 conf_file.len = sizeof(NGINX_CONF) - 1; 159 conf_file.len = sizeof(NGINX_CONF) - 1;
198 /* TODO: Win32 append */ 198 /* TODO: Win32 append */
199 } 199 }
200 } 200 }
201 201
202 if (!failed) { 202 if (!failed) {
203 ls = old_cycle->listening.elts; 203 if (old_cycle) {
204 for (i = 0; i < old_cycle->listening.nelts; i++) { 204 ls = old_cycle->listening.elts;
205 ls[i].remain = 0;
206 }
207
208 nls = cycle->listening.elts;
209 for (n = 0; n < cycle->listening.nelts; n++) {
210 for (i = 0; i < old_cycle->listening.nelts; i++) { 205 for (i = 0; i < old_cycle->listening.nelts; i++) {
211 if (ngx_memcmp(nls[n].sockaddr, 206 ls[i].remain = 0;
212 ls[i].sockaddr, ls[i].socklen) == 0) 207 }
213 { 208
214 nls[n].fd = ls[i].fd; 209 nls = cycle->listening.elts;
215 ls[i].remain = 1; 210 for (n = 0; n < cycle->listening.nelts; n++) {
216 break; 211 for (i = 0; i < old_cycle->listening.nelts; i++) {
212 if (ngx_memcmp(nls[n].sockaddr,
213 ls[i].sockaddr, ls[i].socklen) == 0)
214 {
215 nls[n].fd = ls[i].fd;
216 ls[i].remain = 1;
217 break;
218 }
217 } 219 }
218 } 220
219 221 if (nls[n].fd == -1) {
220 if (nls[n].fd == -1) { 222 nls[n].new = 1;
221 nls[n].new = 1; 223 }
222 } 224 }
223 } 225 }
224 226
225 if (ngx_open_listening_sockets(cycle, log) == NGX_ERROR) { 227 if (ngx_open_listening_sockets(cycle, log) == NGX_ERROR) {
226 failed = 1; 228 failed = 1;
273 if (ngx_modules[i]->commit_module) { 275 if (ngx_modules[i]->commit_module) {
274 ngx_modules[i]->commit_module(cycle, log); 276 ngx_modules[i]->commit_module(cycle, log);
275 } 277 }
276 } 278 }
277 279
280 pool->log = cycle->log;
281
282 if (old_cycle == NULL) {
283 return cycle;
284 }
285
278 ls = old_cycle->listening.elts; 286 ls = old_cycle->listening.elts;
279 for (i = 0; i < old_cycle->listening.nelts; i++) { 287 for (i = 0; i < old_cycle->listening.nelts; i++) {
280 if (ls[i].remain) { 288 if (ls[i].remain) {
281 continue; 289 continue;
282 } 290 }
298 ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, 306 ngx_log_error(NGX_LOG_EMERG, log, ngx_errno,
299 ngx_close_file_n " \"%s\" failed", 307 ngx_close_file_n " \"%s\" failed",
300 file->name.data); 308 file->name.data);
301 } 309 }
302 } 310 }
303
304 pool->log = cycle->log;
305 311
306 ngx_destroy_pool(old_cycle->pool); 312 ngx_destroy_pool(old_cycle->pool);
307 313
308 return cycle; 314 return cycle;
309 } 315 }