Mercurial > hg > nginx
comparison src/core/nginx.c @ 103:6dfda4cf5200
nginx-0.0.1-2003-06-11-19:28:34 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Wed, 11 Jun 2003 15:28:34 +0000 |
parents | 7ebc8b7fb816 |
children | 00bee6e7b485 |
comparison
equal
deleted
inserted
replaced
102:7e86d028d8f0 | 103:6dfda4cf5200 |
---|---|
1 | 1 |
2 | 2 |
3 #include <ngx_config.h> | 3 #include <ngx_config.h> |
4 #include <ngx_core.h> | 4 #include <ngx_core.h> |
5 | 5 #include <ngx_event.h> |
6 #include <ngx_listen.h> | |
7 | |
8 #include <nginx.h> | 6 #include <nginx.h> |
9 | 7 |
10 | 8 |
11 | 9 |
12 static int ngx_open_listening_sockets(ngx_log_t *log); | 10 static int ngx_open_listening_sockets(ngx_log_t *log); |
59 | 57 |
60 /* life cycle */ | 58 /* life cycle */ |
61 | 59 |
62 { | 60 { |
63 ngx_init_array(ngx_listening_sockets, | 61 ngx_init_array(ngx_listening_sockets, |
64 ngx_pool, 10, sizeof(ngx_listen_t), | 62 ngx_pool, 10, sizeof(ngx_listening_t), |
65 1); | 63 1); |
66 | 64 |
67 ngx_memzero(&conf, sizeof(ngx_conf_t)); | 65 ngx_memzero(&conf, sizeof(ngx_conf_t)); |
68 | 66 |
69 ngx_test_null(conf.args, | 67 ngx_test_null(conf.args, |
124 } | 122 } |
125 | 123 |
126 | 124 |
127 static int ngx_open_listening_sockets(ngx_log_t *log) | 125 static int ngx_open_listening_sockets(ngx_log_t *log) |
128 { | 126 { |
129 int times, failed, reuseaddr, i; | 127 int times, failed, reuseaddr, i; |
130 ngx_err_t err; | 128 ngx_err_t err; |
131 ngx_socket_t s; | 129 ngx_socket_t s; |
132 ngx_listen_t *ls; | 130 ngx_listening_t *ls; |
133 | 131 |
134 reuseaddr = 1; | 132 reuseaddr = 1; |
135 | 133 |
136 for (times = 10; times; times--) { | 134 for (times = 10; times; times--) { |
137 failed = 0; | 135 failed = 0; |
138 | 136 |
139 /* for each listening socket */ | 137 /* for each listening socket */ |
140 ls = (ngx_listen_t *) ngx_listening_sockets.elts; | 138 |
139 ls = ngx_listening_sockets.elts; | |
141 for (i = 0; i < ngx_listening_sockets.nelts; i++) { | 140 for (i = 0; i < ngx_listening_sockets.nelts; i++) { |
142 | 141 |
143 if (ls[i].bound) | 142 if (ls[i].bound) |
144 continue; | 143 continue; |
145 | 144 |
158 if (s == -1) { | 157 if (s == -1) { |
159 ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno, | 158 ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno, |
160 ngx_socket_n " %s falied", ls[i].addr_text.data); | 159 ngx_socket_n " %s falied", ls[i].addr_text.data); |
161 return NGX_ERROR; | 160 return NGX_ERROR; |
162 } | 161 } |
162 | |
163 #if (WIN32) | |
164 /* | |
165 * Winsock assignes a socket number divisible by 4 | |
166 * so to find a connection we divide a socket number by 4. | |
167 */ | |
168 | |
169 if (s % 4) { | |
170 ngx_log_error(NGX_LOG_EMERG, ls->log, 0, | |
171 ngx_socket_n " created socket %d", s); | |
172 return NGX_ERROR; | |
173 } | |
174 #endif | |
163 | 175 |
164 if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, | 176 if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, |
165 (const void *) &reuseaddr, sizeof(int)) == -1) { | 177 (const void *) &reuseaddr, sizeof(int)) == -1) { |
166 ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno, | 178 ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno, |
167 "setsockopt(SO_REUSEADDR) %s failed", | 179 "setsockopt(SO_REUSEADDR) %s failed", |