annotate src/core/nginx.c @ 100:7ebc8b7fb816

nginx-0.0.1-2003-06-03-19:42:58 import
author Igor Sysoev <igor@sysoev.ru>
date Tue, 03 Jun 2003 15:42:58 +0000
parents c9b243802a17
children 6dfda4cf5200
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
98
c9b243802a17 nginx-0.0.1-2003-05-30-18:27:59 import
Igor Sysoev <igor@sysoev.ru>
parents: 97
diff changeset
1
c9b243802a17 nginx-0.0.1-2003-05-30-18:27:59 import
Igor Sysoev <igor@sysoev.ru>
parents: 97
diff changeset
2
c9b243802a17 nginx-0.0.1-2003-05-30-18:27:59 import
Igor Sysoev <igor@sysoev.ru>
parents: 97
diff changeset
3 #include <ngx_config.h>
c9b243802a17 nginx-0.0.1-2003-05-30-18:27:59 import
Igor Sysoev <igor@sysoev.ru>
parents: 97
diff changeset
4 #include <ngx_core.h>
c9b243802a17 nginx-0.0.1-2003-05-30-18:27:59 import
Igor Sysoev <igor@sysoev.ru>
parents: 97
diff changeset
5
c9b243802a17 nginx-0.0.1-2003-05-30-18:27:59 import
Igor Sysoev <igor@sysoev.ru>
parents: 97
diff changeset
6 #include <ngx_listen.h>
0
4eff17414a43 nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
7
4eff17414a43 nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
8 #include <nginx.h>
4eff17414a43 nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
9
4eff17414a43 nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
10
4eff17414a43 nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
11
98
c9b243802a17 nginx-0.0.1-2003-05-30-18:27:59 import
Igor Sysoev <igor@sysoev.ru>
parents: 97
diff changeset
12 static int ngx_open_listening_sockets(ngx_log_t *log);
3
34a521b1a148 nginx-0.0.1-2002-08-20-18:48:28 import
Igor Sysoev <igor@sysoev.ru>
parents: 2
diff changeset
13
34a521b1a148 nginx-0.0.1-2002-08-20-18:48:28 import
Igor Sysoev <igor@sysoev.ru>
parents: 2
diff changeset
14
91
637625a2acdb nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents: 90
diff changeset
15 ngx_log_t ngx_log;
637625a2acdb nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents: 90
diff changeset
16 ngx_pool_t *ngx_pool;
637625a2acdb nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents: 90
diff changeset
17 void ****ngx_conf_ctx;
637625a2acdb nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents: 90
diff changeset
18
637625a2acdb nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents: 90
diff changeset
19
637625a2acdb nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents: 90
diff changeset
20 ngx_os_io_t ngx_io;
0
4eff17414a43 nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
21
4eff17414a43 nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
22
98
c9b243802a17 nginx-0.0.1-2003-05-30-18:27:59 import
Igor Sysoev <igor@sysoev.ru>
parents: 97
diff changeset
23 int ngx_max_module;
c9b243802a17 nginx-0.0.1-2003-05-30-18:27:59 import
Igor Sysoev <igor@sysoev.ru>
parents: 97
diff changeset
24 void *ctx_conf;
71
59229033ae93 nginx-0.0.1-2003-04-08-19:40:10 import
Igor Sysoev <igor@sysoev.ru>
parents: 59
diff changeset
25
26
53cb81681040 nginx-0.0.1-2002-12-15-09:25:09 import
Igor Sysoev <igor@sysoev.ru>
parents: 24
diff changeset
26 int ngx_connection_counter;
53cb81681040 nginx-0.0.1-2002-12-15-09:25:09 import
Igor Sysoev <igor@sysoev.ru>
parents: 24
diff changeset
27
44
0e81ac0bb3e2 nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents: 43
diff changeset
28 ngx_array_t ngx_listening_sockets;
2
ffffe1499bce nginx-0.0.1-2002-08-16-19:27:03 import
Igor Sysoev <igor@sysoev.ru>
parents: 1
diff changeset
29
ffffe1499bce nginx-0.0.1-2002-08-16-19:27:03 import
Igor Sysoev <igor@sysoev.ru>
parents: 1
diff changeset
30
0
4eff17414a43 nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
31 int main(int argc, char *const *argv)
4eff17414a43 nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
32 {
45
f1ee46c036a4 nginx-0.0.1-2003-01-10-09:09:20 import
Igor Sysoev <igor@sysoev.ru>
parents: 44
diff changeset
33 int i;
100
7ebc8b7fb816 nginx-0.0.1-2003-06-03-19:42:58 import
Igor Sysoev <igor@sysoev.ru>
parents: 98
diff changeset
34 ngx_str_t conf_file;
7ebc8b7fb816 nginx-0.0.1-2003-06-03-19:42:58 import
Igor Sysoev <igor@sysoev.ru>
parents: 98
diff changeset
35 ngx_log_t *log;
7ebc8b7fb816 nginx-0.0.1-2003-06-03-19:42:58 import
Igor Sysoev <igor@sysoev.ru>
parents: 98
diff changeset
36 ngx_conf_t conf;
36
c14d7232b11f nginx-0.0.1-2002-12-23-09:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents: 32
diff changeset
37
92
19cc647ecd91 nginx-0.0.1-2003-05-20-19:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents: 91
diff changeset
38 ngx_max_sockets = -1;
19cc647ecd91 nginx-0.0.1-2003-05-20-19:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents: 91
diff changeset
39
100
7ebc8b7fb816 nginx-0.0.1-2003-06-03-19:42:58 import
Igor Sysoev <igor@sysoev.ru>
parents: 98
diff changeset
40 #if 0
92
19cc647ecd91 nginx-0.0.1-2003-05-20-19:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents: 91
diff changeset
41 ngx_log.fd = STDERR_FILENO;
19cc647ecd91 nginx-0.0.1-2003-05-20-19:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents: 91
diff changeset
42 ngx_log.log_level = NGX_LOG_INFO;
19cc647ecd91 nginx-0.0.1-2003-05-20-19:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents: 91
diff changeset
43
19cc647ecd91 nginx-0.0.1-2003-05-20-19:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents: 91
diff changeset
44 /* STUB */ ngx_log.log_level = NGX_LOG_DEBUG;
100
7ebc8b7fb816 nginx-0.0.1-2003-06-03-19:42:58 import
Igor Sysoev <igor@sysoev.ru>
parents: 98
diff changeset
45 #endif
7ebc8b7fb816 nginx-0.0.1-2003-06-03-19:42:58 import
Igor Sysoev <igor@sysoev.ru>
parents: 98
diff changeset
46 log = ngx_log_init_errlog();
0
4eff17414a43 nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
47
100
7ebc8b7fb816 nginx-0.0.1-2003-06-03-19:42:58 import
Igor Sysoev <igor@sysoev.ru>
parents: 98
diff changeset
48 if (ngx_os_init(log) == NGX_ERROR) {
91
637625a2acdb nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents: 90
diff changeset
49 return 1;
88
674d333f4296 nginx-0.0.1-2003-05-14-21:13:13 import
Igor Sysoev <igor@sysoev.ru>
parents: 87
diff changeset
50 }
674d333f4296 nginx-0.0.1-2003-05-14-21:13:13 import
Igor Sysoev <igor@sysoev.ru>
parents: 87
diff changeset
51
100
7ebc8b7fb816 nginx-0.0.1-2003-06-03-19:42:58 import
Igor Sysoev <igor@sysoev.ru>
parents: 98
diff changeset
52 ngx_pool = ngx_create_pool(16 * 1024, log);
3
34a521b1a148 nginx-0.0.1-2002-08-20-18:48:28 import
Igor Sysoev <igor@sysoev.ru>
parents: 2
diff changeset
53 /* */
0
4eff17414a43 nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
54
71
59229033ae93 nginx-0.0.1-2003-04-08-19:40:10 import
Igor Sysoev <igor@sysoev.ru>
parents: 59
diff changeset
55 ngx_max_module = 0;
59229033ae93 nginx-0.0.1-2003-04-08-19:40:10 import
Igor Sysoev <igor@sysoev.ru>
parents: 59
diff changeset
56 for (i = 0; ngx_modules[i]; i++) {
59229033ae93 nginx-0.0.1-2003-04-08-19:40:10 import
Igor Sysoev <igor@sysoev.ru>
parents: 59
diff changeset
57 ngx_modules[i]->index = ngx_max_module++;
59229033ae93 nginx-0.0.1-2003-04-08-19:40:10 import
Igor Sysoev <igor@sysoev.ru>
parents: 59
diff changeset
58 }
59229033ae93 nginx-0.0.1-2003-04-08-19:40:10 import
Igor Sysoev <igor@sysoev.ru>
parents: 59
diff changeset
59
91
637625a2acdb nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents: 90
diff changeset
60 /* life cycle */
90
37530da31268 nginx-0.0.1-2003-05-16-19:27:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 88
diff changeset
61
91
637625a2acdb nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents: 90
diff changeset
62 {
637625a2acdb nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents: 90
diff changeset
63 ngx_init_array(ngx_listening_sockets,
637625a2acdb nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents: 90
diff changeset
64 ngx_pool, 10, sizeof(ngx_listen_t),
637625a2acdb nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents: 90
diff changeset
65 1);
90
37530da31268 nginx-0.0.1-2003-05-16-19:27:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 88
diff changeset
66
91
637625a2acdb nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents: 90
diff changeset
67 ngx_memzero(&conf, sizeof(ngx_conf_t));
90
37530da31268 nginx-0.0.1-2003-05-16-19:27:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 88
diff changeset
68
91
637625a2acdb nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents: 90
diff changeset
69 ngx_test_null(conf.args,
637625a2acdb nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents: 90
diff changeset
70 ngx_create_array(ngx_pool, 10, sizeof(ngx_str_t)),
637625a2acdb nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents: 90
diff changeset
71 1);
637625a2acdb nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents: 90
diff changeset
72
637625a2acdb nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents: 90
diff changeset
73 ngx_test_null(ngx_conf_ctx,
637625a2acdb nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents: 90
diff changeset
74 ngx_pcalloc(ngx_pool, ngx_max_module * sizeof(void *)),
637625a2acdb nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents: 90
diff changeset
75 1);
36
c14d7232b11f nginx-0.0.1-2002-12-23-09:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents: 32
diff changeset
76
91
637625a2acdb nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents: 90
diff changeset
77 conf.ctx = ngx_conf_ctx;
637625a2acdb nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents: 90
diff changeset
78 conf.pool = ngx_pool;
100
7ebc8b7fb816 nginx-0.0.1-2003-06-03-19:42:58 import
Igor Sysoev <igor@sysoev.ru>
parents: 98
diff changeset
79 conf.log = log;
96
a23d010f356d nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents: 92
diff changeset
80 conf.module_type = NGX_CORE_MODULE;
91
637625a2acdb nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents: 90
diff changeset
81 conf.cmd_type = NGX_MAIN_CONF;
36
c14d7232b11f nginx-0.0.1-2002-12-23-09:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents: 32
diff changeset
82
97
70d2345a903f nginx-0.0.1-2003-05-29-17:02:09 import
Igor Sysoev <igor@sysoev.ru>
parents: 96
diff changeset
83 conf_file.len = sizeof(NGINX_CONF) - 1;
70d2345a903f nginx-0.0.1-2003-05-29-17:02:09 import
Igor Sysoev <igor@sysoev.ru>
parents: 96
diff changeset
84 conf_file.data = NGINX_CONF;
36
c14d7232b11f nginx-0.0.1-2002-12-23-09:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents: 32
diff changeset
85
91
637625a2acdb nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents: 90
diff changeset
86 if (ngx_conf_parse(&conf, &conf_file) != NGX_CONF_OK) {
637625a2acdb nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents: 90
diff changeset
87 return 1;
637625a2acdb nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents: 90
diff changeset
88 }
637625a2acdb nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents: 90
diff changeset
89
100
7ebc8b7fb816 nginx-0.0.1-2003-06-03-19:42:58 import
Igor Sysoev <igor@sysoev.ru>
parents: 98
diff changeset
90 #if 0
7ebc8b7fb816 nginx-0.0.1-2003-06-03-19:42:58 import
Igor Sysoev <igor@sysoev.ru>
parents: 98
diff changeset
91 log = (ngx_log_t *) ngx_get_conf(ngx_errlog_module);
7ebc8b7fb816 nginx-0.0.1-2003-06-03-19:42:58 import
Igor Sysoev <igor@sysoev.ru>
parents: 98
diff changeset
92 /* STUB */ log->log_level = NGX_LOG_DEBUG;
7ebc8b7fb816 nginx-0.0.1-2003-06-03-19:42:58 import
Igor Sysoev <igor@sysoev.ru>
parents: 98
diff changeset
93 #endif
7ebc8b7fb816 nginx-0.0.1-2003-06-03-19:42:58 import
Igor Sysoev <igor@sysoev.ru>
parents: 98
diff changeset
94
91
637625a2acdb nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents: 90
diff changeset
95 ngx_init_temp_number();
83
a7e45c45a95c nginx-0.0.1-2003-04-28-19:06:39 import
Igor Sysoev <igor@sysoev.ru>
parents: 71
diff changeset
96
91
637625a2acdb nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents: 90
diff changeset
97 ngx_io = ngx_os_io;
637625a2acdb nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents: 90
diff changeset
98
637625a2acdb nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents: 90
diff changeset
99 for (i = 0; ngx_modules[i]; i++) {
637625a2acdb nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents: 90
diff changeset
100 if (ngx_modules[i]->init_module) {
637625a2acdb nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents: 90
diff changeset
101 if (ngx_modules[i]->init_module(ngx_pool) == NGX_ERROR) {
637625a2acdb nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents: 90
diff changeset
102 return 1;
637625a2acdb nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents: 90
diff changeset
103 }
45
f1ee46c036a4 nginx-0.0.1-2003-01-10-09:09:20 import
Igor Sysoev <igor@sysoev.ru>
parents: 44
diff changeset
104 }
f1ee46c036a4 nginx-0.0.1-2003-01-10-09:09:20 import
Igor Sysoev <igor@sysoev.ru>
parents: 44
diff changeset
105 }
91
637625a2acdb nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents: 90
diff changeset
106
100
7ebc8b7fb816 nginx-0.0.1-2003-06-03-19:42:58 import
Igor Sysoev <igor@sysoev.ru>
parents: 98
diff changeset
107 if (ngx_open_listening_sockets(log) == NGX_ERROR) {
98
c9b243802a17 nginx-0.0.1-2003-05-30-18:27:59 import
Igor Sysoev <igor@sysoev.ru>
parents: 97
diff changeset
108 return 1;
c9b243802a17 nginx-0.0.1-2003-05-30-18:27:59 import
Igor Sysoev <igor@sysoev.ru>
parents: 97
diff changeset
109 }
45
f1ee46c036a4 nginx-0.0.1-2003-01-10-09:09:20 import
Igor Sysoev <igor@sysoev.ru>
parents: 44
diff changeset
110
91
637625a2acdb nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents: 90
diff changeset
111 /* TODO: daemon, once only */
0
4eff17414a43 nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
112
91
637625a2acdb nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents: 90
diff changeset
113 /* TODO: fork */
0
4eff17414a43 nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
114
100
7ebc8b7fb816 nginx-0.0.1-2003-06-03-19:42:58 import
Igor Sysoev <igor@sysoev.ru>
parents: 98
diff changeset
115 ngx_pre_thread(&ngx_listening_sockets, ngx_pool, log);
2
ffffe1499bce nginx-0.0.1-2002-08-16-19:27:03 import
Igor Sysoev <igor@sysoev.ru>
parents: 1
diff changeset
116
91
637625a2acdb nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents: 90
diff changeset
117 /* TODO: threads */
0
4eff17414a43 nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
118
91
637625a2acdb nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents: 90
diff changeset
119 /* STUB */
100
7ebc8b7fb816 nginx-0.0.1-2003-06-03-19:42:58 import
Igor Sysoev <igor@sysoev.ru>
parents: 98
diff changeset
120 ngx_worker(log);
96
a23d010f356d nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents: 92
diff changeset
121 }
8
708f8bb772ec nginx-0.0.1-2002-09-02-18:48:24 import
Igor Sysoev <igor@sysoev.ru>
parents: 6
diff changeset
122
708f8bb772ec nginx-0.0.1-2002-09-02-18:48:24 import
Igor Sysoev <igor@sysoev.ru>
parents: 6
diff changeset
123 return 0;
0
4eff17414a43 nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
124 }
3
34a521b1a148 nginx-0.0.1-2002-08-20-18:48:28 import
Igor Sysoev <igor@sysoev.ru>
parents: 2
diff changeset
125
24
77c7629a2627 nginx-0.0.1-2002-12-10-21:05:12 import
Igor Sysoev <igor@sysoev.ru>
parents: 8
diff changeset
126
98
c9b243802a17 nginx-0.0.1-2003-05-30-18:27:59 import
Igor Sysoev <igor@sysoev.ru>
parents: 97
diff changeset
127 static int ngx_open_listening_sockets(ngx_log_t *log)
3
34a521b1a148 nginx-0.0.1-2002-08-20-18:48:28 import
Igor Sysoev <igor@sysoev.ru>
parents: 2
diff changeset
128 {
34a521b1a148 nginx-0.0.1-2002-08-20-18:48:28 import
Igor Sysoev <igor@sysoev.ru>
parents: 2
diff changeset
129 int times, failed, reuseaddr, i;
34a521b1a148 nginx-0.0.1-2002-08-20-18:48:28 import
Igor Sysoev <igor@sysoev.ru>
parents: 2
diff changeset
130 ngx_err_t err;
34a521b1a148 nginx-0.0.1-2002-08-20-18:48:28 import
Igor Sysoev <igor@sysoev.ru>
parents: 2
diff changeset
131 ngx_socket_t s;
34a521b1a148 nginx-0.0.1-2002-08-20-18:48:28 import
Igor Sysoev <igor@sysoev.ru>
parents: 2
diff changeset
132 ngx_listen_t *ls;
34a521b1a148 nginx-0.0.1-2002-08-20-18:48:28 import
Igor Sysoev <igor@sysoev.ru>
parents: 2
diff changeset
133
34a521b1a148 nginx-0.0.1-2002-08-20-18:48:28 import
Igor Sysoev <igor@sysoev.ru>
parents: 2
diff changeset
134 reuseaddr = 1;
34a521b1a148 nginx-0.0.1-2002-08-20-18:48:28 import
Igor Sysoev <igor@sysoev.ru>
parents: 2
diff changeset
135
34a521b1a148 nginx-0.0.1-2002-08-20-18:48:28 import
Igor Sysoev <igor@sysoev.ru>
parents: 2
diff changeset
136 for (times = 10; times; times--) {
34a521b1a148 nginx-0.0.1-2002-08-20-18:48:28 import
Igor Sysoev <igor@sysoev.ru>
parents: 2
diff changeset
137 failed = 0;
34a521b1a148 nginx-0.0.1-2002-08-20-18:48:28 import
Igor Sysoev <igor@sysoev.ru>
parents: 2
diff changeset
138
34a521b1a148 nginx-0.0.1-2002-08-20-18:48:28 import
Igor Sysoev <igor@sysoev.ru>
parents: 2
diff changeset
139 /* for each listening socket */
44
0e81ac0bb3e2 nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents: 43
diff changeset
140 ls = (ngx_listen_t *) ngx_listening_sockets.elts;
0e81ac0bb3e2 nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents: 43
diff changeset
141 for (i = 0; i < ngx_listening_sockets.nelts; i++) {
6
669801705ab1 nginx-0.0.1-2002-08-26-19:18:19 import
Igor Sysoev <igor@sysoev.ru>
parents: 3
diff changeset
142
44
0e81ac0bb3e2 nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents: 43
diff changeset
143 if (ls[i].bound)
3
34a521b1a148 nginx-0.0.1-2002-08-20-18:48:28 import
Igor Sysoev <igor@sysoev.ru>
parents: 2
diff changeset
144 continue;
34a521b1a148 nginx-0.0.1-2002-08-20-18:48:28 import
Igor Sysoev <igor@sysoev.ru>
parents: 2
diff changeset
145
6
669801705ab1 nginx-0.0.1-2002-08-26-19:18:19 import
Igor Sysoev <igor@sysoev.ru>
parents: 3
diff changeset
146 if (ls[i].inherited) {
669801705ab1 nginx-0.0.1-2002-08-26-19:18:19 import
Igor Sysoev <igor@sysoev.ru>
parents: 3
diff changeset
147
669801705ab1 nginx-0.0.1-2002-08-26-19:18:19 import
Igor Sysoev <igor@sysoev.ru>
parents: 3
diff changeset
148 /* TODO: close on exit */
669801705ab1 nginx-0.0.1-2002-08-26-19:18:19 import
Igor Sysoev <igor@sysoev.ru>
parents: 3
diff changeset
149 /* TODO: nonblocking */
669801705ab1 nginx-0.0.1-2002-08-26-19:18:19 import
Igor Sysoev <igor@sysoev.ru>
parents: 3
diff changeset
150 /* TODO: deferred accept */
669801705ab1 nginx-0.0.1-2002-08-26-19:18:19 import
Igor Sysoev <igor@sysoev.ru>
parents: 3
diff changeset
151
44
0e81ac0bb3e2 nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents: 43
diff changeset
152 ls[i].bound = 1;
6
669801705ab1 nginx-0.0.1-2002-08-26-19:18:19 import
Igor Sysoev <igor@sysoev.ru>
parents: 3
diff changeset
153 continue;
669801705ab1 nginx-0.0.1-2002-08-26-19:18:19 import
Igor Sysoev <igor@sysoev.ru>
parents: 3
diff changeset
154 }
669801705ab1 nginx-0.0.1-2002-08-26-19:18:19 import
Igor Sysoev <igor@sysoev.ru>
parents: 3
diff changeset
155
669801705ab1 nginx-0.0.1-2002-08-26-19:18:19 import
Igor Sysoev <igor@sysoev.ru>
parents: 3
diff changeset
156 s = ngx_socket(ls[i].family, ls[i].type, ls[i].protocol,
669801705ab1 nginx-0.0.1-2002-08-26-19:18:19 import
Igor Sysoev <igor@sysoev.ru>
parents: 3
diff changeset
157 ls[i].flags);
669801705ab1 nginx-0.0.1-2002-08-26-19:18:19 import
Igor Sysoev <igor@sysoev.ru>
parents: 3
diff changeset
158 if (s == -1) {
3
34a521b1a148 nginx-0.0.1-2002-08-20-18:48:28 import
Igor Sysoev <igor@sysoev.ru>
parents: 2
diff changeset
159 ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno,
32
d45effe5854c nginx-0.0.1-2002-12-19-10:08:55 import
Igor Sysoev <igor@sysoev.ru>
parents: 26
diff changeset
160 ngx_socket_n " %s falied", ls[i].addr_text.data);
98
c9b243802a17 nginx-0.0.1-2003-05-30-18:27:59 import
Igor Sysoev <igor@sysoev.ru>
parents: 97
diff changeset
161 return NGX_ERROR;
6
669801705ab1 nginx-0.0.1-2002-08-26-19:18:19 import
Igor Sysoev <igor@sysoev.ru>
parents: 3
diff changeset
162 }
3
34a521b1a148 nginx-0.0.1-2002-08-20-18:48:28 import
Igor Sysoev <igor@sysoev.ru>
parents: 2
diff changeset
163
34a521b1a148 nginx-0.0.1-2002-08-20-18:48:28 import
Igor Sysoev <igor@sysoev.ru>
parents: 2
diff changeset
164 if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR,
6
669801705ab1 nginx-0.0.1-2002-08-26-19:18:19 import
Igor Sysoev <igor@sysoev.ru>
parents: 3
diff changeset
165 (const void *) &reuseaddr, sizeof(int)) == -1) {
3
34a521b1a148 nginx-0.0.1-2002-08-20-18:48:28 import
Igor Sysoev <igor@sysoev.ru>
parents: 2
diff changeset
166 ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno,
6
669801705ab1 nginx-0.0.1-2002-08-26-19:18:19 import
Igor Sysoev <igor@sysoev.ru>
parents: 3
diff changeset
167 "setsockopt(SO_REUSEADDR) %s failed",
32
d45effe5854c nginx-0.0.1-2002-12-19-10:08:55 import
Igor Sysoev <igor@sysoev.ru>
parents: 26
diff changeset
168 ls[i].addr_text.data);
98
c9b243802a17 nginx-0.0.1-2003-05-30-18:27:59 import
Igor Sysoev <igor@sysoev.ru>
parents: 97
diff changeset
169 return NGX_ERROR;
6
669801705ab1 nginx-0.0.1-2002-08-26-19:18:19 import
Igor Sysoev <igor@sysoev.ru>
parents: 3
diff changeset
170 }
3
34a521b1a148 nginx-0.0.1-2002-08-20-18:48:28 import
Igor Sysoev <igor@sysoev.ru>
parents: 2
diff changeset
171
34a521b1a148 nginx-0.0.1-2002-08-20-18:48:28 import
Igor Sysoev <igor@sysoev.ru>
parents: 2
diff changeset
172 /* TODO: close on exit */
34a521b1a148 nginx-0.0.1-2002-08-20-18:48:28 import
Igor Sysoev <igor@sysoev.ru>
parents: 2
diff changeset
173
34a521b1a148 nginx-0.0.1-2002-08-20-18:48:28 import
Igor Sysoev <igor@sysoev.ru>
parents: 2
diff changeset
174 if (ls[i].nonblocking) {
6
669801705ab1 nginx-0.0.1-2002-08-26-19:18:19 import
Igor Sysoev <igor@sysoev.ru>
parents: 3
diff changeset
175 if (ngx_nonblocking(s) == -1) {
3
34a521b1a148 nginx-0.0.1-2002-08-20-18:48:28 import
Igor Sysoev <igor@sysoev.ru>
parents: 2
diff changeset
176 ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno,
34a521b1a148 nginx-0.0.1-2002-08-20-18:48:28 import
Igor Sysoev <igor@sysoev.ru>
parents: 2
diff changeset
177 ngx_nonblocking_n " %s failed",
32
d45effe5854c nginx-0.0.1-2002-12-19-10:08:55 import
Igor Sysoev <igor@sysoev.ru>
parents: 26
diff changeset
178 ls[i].addr_text.data);
98
c9b243802a17 nginx-0.0.1-2003-05-30-18:27:59 import
Igor Sysoev <igor@sysoev.ru>
parents: 97
diff changeset
179 return NGX_ERROR;
6
669801705ab1 nginx-0.0.1-2002-08-26-19:18:19 import
Igor Sysoev <igor@sysoev.ru>
parents: 3
diff changeset
180 }
3
34a521b1a148 nginx-0.0.1-2002-08-20-18:48:28 import
Igor Sysoev <igor@sysoev.ru>
parents: 2
diff changeset
181 }
34a521b1a148 nginx-0.0.1-2002-08-20-18:48:28 import
Igor Sysoev <igor@sysoev.ru>
parents: 2
diff changeset
182
6
669801705ab1 nginx-0.0.1-2002-08-26-19:18:19 import
Igor Sysoev <igor@sysoev.ru>
parents: 3
diff changeset
183 if (bind(s, ls[i].sockaddr, ls[i].socklen) == -1) {
3
34a521b1a148 nginx-0.0.1-2002-08-20-18:48:28 import
Igor Sysoev <igor@sysoev.ru>
parents: 2
diff changeset
184 err = ngx_socket_errno;
6
669801705ab1 nginx-0.0.1-2002-08-26-19:18:19 import
Igor Sysoev <igor@sysoev.ru>
parents: 3
diff changeset
185 ngx_log_error(NGX_LOG_EMERG, log, err,
32
d45effe5854c nginx-0.0.1-2002-12-19-10:08:55 import
Igor Sysoev <igor@sysoev.ru>
parents: 26
diff changeset
186 "bind() to %s failed", ls[i].addr_text.data);
3
34a521b1a148 nginx-0.0.1-2002-08-20-18:48:28 import
Igor Sysoev <igor@sysoev.ru>
parents: 2
diff changeset
187
34a521b1a148 nginx-0.0.1-2002-08-20-18:48:28 import
Igor Sysoev <igor@sysoev.ru>
parents: 2
diff changeset
188 if (err != NGX_EADDRINUSE)
98
c9b243802a17 nginx-0.0.1-2003-05-30-18:27:59 import
Igor Sysoev <igor@sysoev.ru>
parents: 97
diff changeset
189 return NGX_ERROR;
3
34a521b1a148 nginx-0.0.1-2002-08-20-18:48:28 import
Igor Sysoev <igor@sysoev.ru>
parents: 2
diff changeset
190
34a521b1a148 nginx-0.0.1-2002-08-20-18:48:28 import
Igor Sysoev <igor@sysoev.ru>
parents: 2
diff changeset
191 if (ngx_close_socket(s) == -1)
6
669801705ab1 nginx-0.0.1-2002-08-26-19:18:19 import
Igor Sysoev <igor@sysoev.ru>
parents: 3
diff changeset
192 ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno,
3
34a521b1a148 nginx-0.0.1-2002-08-20-18:48:28 import
Igor Sysoev <igor@sysoev.ru>
parents: 2
diff changeset
193 ngx_close_socket_n " %s failed",
32
d45effe5854c nginx-0.0.1-2002-12-19-10:08:55 import
Igor Sysoev <igor@sysoev.ru>
parents: 26
diff changeset
194 ls[i].addr_text.data);
3
34a521b1a148 nginx-0.0.1-2002-08-20-18:48:28 import
Igor Sysoev <igor@sysoev.ru>
parents: 2
diff changeset
195
34a521b1a148 nginx-0.0.1-2002-08-20-18:48:28 import
Igor Sysoev <igor@sysoev.ru>
parents: 2
diff changeset
196 failed = 1;
34a521b1a148 nginx-0.0.1-2002-08-20-18:48:28 import
Igor Sysoev <igor@sysoev.ru>
parents: 2
diff changeset
197 continue;
34a521b1a148 nginx-0.0.1-2002-08-20-18:48:28 import
Igor Sysoev <igor@sysoev.ru>
parents: 2
diff changeset
198 }
34a521b1a148 nginx-0.0.1-2002-08-20-18:48:28 import
Igor Sysoev <igor@sysoev.ru>
parents: 2
diff changeset
199
6
669801705ab1 nginx-0.0.1-2002-08-26-19:18:19 import
Igor Sysoev <igor@sysoev.ru>
parents: 3
diff changeset
200 if (listen(s, ls[i].backlog) == -1) {
3
34a521b1a148 nginx-0.0.1-2002-08-20-18:48:28 import
Igor Sysoev <igor@sysoev.ru>
parents: 2
diff changeset
201 ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno,
32
d45effe5854c nginx-0.0.1-2002-12-19-10:08:55 import
Igor Sysoev <igor@sysoev.ru>
parents: 26
diff changeset
202 "listen() to %s failed", ls[i].addr_text.data);
98
c9b243802a17 nginx-0.0.1-2003-05-30-18:27:59 import
Igor Sysoev <igor@sysoev.ru>
parents: 97
diff changeset
203 return NGX_ERROR;
6
669801705ab1 nginx-0.0.1-2002-08-26-19:18:19 import
Igor Sysoev <igor@sysoev.ru>
parents: 3
diff changeset
204 }
3
34a521b1a148 nginx-0.0.1-2002-08-20-18:48:28 import
Igor Sysoev <igor@sysoev.ru>
parents: 2
diff changeset
205
34a521b1a148 nginx-0.0.1-2002-08-20-18:48:28 import
Igor Sysoev <igor@sysoev.ru>
parents: 2
diff changeset
206 /* TODO: deferred accept */
34a521b1a148 nginx-0.0.1-2002-08-20-18:48:28 import
Igor Sysoev <igor@sysoev.ru>
parents: 2
diff changeset
207
34a521b1a148 nginx-0.0.1-2002-08-20-18:48:28 import
Igor Sysoev <igor@sysoev.ru>
parents: 2
diff changeset
208 ls[i].fd = s;
44
0e81ac0bb3e2 nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents: 43
diff changeset
209 ls[i].bound = 1;
3
34a521b1a148 nginx-0.0.1-2002-08-20-18:48:28 import
Igor Sysoev <igor@sysoev.ru>
parents: 2
diff changeset
210 }
34a521b1a148 nginx-0.0.1-2002-08-20-18:48:28 import
Igor Sysoev <igor@sysoev.ru>
parents: 2
diff changeset
211
34a521b1a148 nginx-0.0.1-2002-08-20-18:48:28 import
Igor Sysoev <igor@sysoev.ru>
parents: 2
diff changeset
212 if (!failed)
34a521b1a148 nginx-0.0.1-2002-08-20-18:48:28 import
Igor Sysoev <igor@sysoev.ru>
parents: 2
diff changeset
213 break;
34a521b1a148 nginx-0.0.1-2002-08-20-18:48:28 import
Igor Sysoev <igor@sysoev.ru>
parents: 2
diff changeset
214
6
669801705ab1 nginx-0.0.1-2002-08-26-19:18:19 import
Igor Sysoev <igor@sysoev.ru>
parents: 3
diff changeset
215 ngx_log_error(NGX_LOG_NOTICE, log, 0,
669801705ab1 nginx-0.0.1-2002-08-26-19:18:19 import
Igor Sysoev <igor@sysoev.ru>
parents: 3
diff changeset
216 "try again to bind() after 500ms");
3
34a521b1a148 nginx-0.0.1-2002-08-20-18:48:28 import
Igor Sysoev <igor@sysoev.ru>
parents: 2
diff changeset
217 ngx_msleep(500);
34a521b1a148 nginx-0.0.1-2002-08-20-18:48:28 import
Igor Sysoev <igor@sysoev.ru>
parents: 2
diff changeset
218 }
34a521b1a148 nginx-0.0.1-2002-08-20-18:48:28 import
Igor Sysoev <igor@sysoev.ru>
parents: 2
diff changeset
219
6
669801705ab1 nginx-0.0.1-2002-08-26-19:18:19 import
Igor Sysoev <igor@sysoev.ru>
parents: 3
diff changeset
220 if (failed) {
669801705ab1 nginx-0.0.1-2002-08-26-19:18:19 import
Igor Sysoev <igor@sysoev.ru>
parents: 3
diff changeset
221 ngx_log_error(NGX_LOG_EMERG, log, 0, "can not bind(), exiting");
98
c9b243802a17 nginx-0.0.1-2003-05-30-18:27:59 import
Igor Sysoev <igor@sysoev.ru>
parents: 97
diff changeset
222 return NGX_ERROR;
6
669801705ab1 nginx-0.0.1-2002-08-26-19:18:19 import
Igor Sysoev <igor@sysoev.ru>
parents: 3
diff changeset
223 }
98
c9b243802a17 nginx-0.0.1-2003-05-30-18:27:59 import
Igor Sysoev <igor@sysoev.ru>
parents: 97
diff changeset
224
c9b243802a17 nginx-0.0.1-2003-05-30-18:27:59 import
Igor Sysoev <igor@sysoev.ru>
parents: 97
diff changeset
225 return NGX_OK;
3
34a521b1a148 nginx-0.0.1-2002-08-20-18:48:28 import
Igor Sysoev <igor@sysoev.ru>
parents: 2
diff changeset
226 }