Mercurial > hg > nginx-quic
annotate src/core/ngx_connection.c @ 6230:2a621245f4cf
Win32: MSVC 2015 compatibility.
Resolved warnings about declarations that hide previous local declarations.
Warnings about WSASocketA() being deprecated resolved by explicit use of
WSASocketW() instead of WSASocket(). When compiling without IPv6 support,
WinSock deprecated warnings are disabled to allow use of gethostbyname().
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Mon, 17 Aug 2015 18:09:17 +0300 |
parents | 5e6142609e48 |
children | 954b67727af3 |
rev | line source |
---|---|
441
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
417
diff
changeset
|
1 |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
417
diff
changeset
|
2 /* |
444
42d11f017717
nginx-0.1.0-2004-09-29-20:00:49 import; remove years from copyright
Igor Sysoev <igor@sysoev.ru>
parents:
441
diff
changeset
|
3 * Copyright (C) Igor Sysoev |
4412 | 4 * Copyright (C) Nginx, Inc. |
441
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
417
diff
changeset
|
5 */ |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
417
diff
changeset
|
6 |
218
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
7 |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
8 #include <ngx_config.h> |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
9 #include <ngx_core.h> |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
10 #include <ngx_event.h> |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
11 |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
12 |
236
86e473b5641e
nginx-0.0.1-2004-01-22-09:47:28 import
Igor Sysoev <igor@sysoev.ru>
parents:
219
diff
changeset
|
13 ngx_os_io_t ngx_io; |
218
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
14 |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
15 |
3880
e3cb8e27e413
reuse keepalive connections if there are no free worker connections
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
16 static void ngx_drain_connections(void); |
e3cb8e27e413
reuse keepalive connections if there are no free worker connections
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
17 |
e3cb8e27e413
reuse keepalive connections if there are no free worker connections
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
18 |
2806 | 19 ngx_listening_t * |
20 ngx_create_listening(ngx_conf_t *cf, void *sockaddr, socklen_t socklen) | |
21 { | |
3230
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
3151
diff
changeset
|
22 size_t len; |
2806 | 23 ngx_listening_t *ls; |
24 struct sockaddr *sa; | |
25 u_char text[NGX_SOCKADDR_STRLEN]; | |
26 | |
27 ls = ngx_array_push(&cf->cycle->listening); | |
28 if (ls == NULL) { | |
29 return NULL; | |
30 } | |
31 | |
32 ngx_memzero(ls, sizeof(ngx_listening_t)); | |
33 | |
34 sa = ngx_palloc(cf->pool, socklen); | |
35 if (sa == NULL) { | |
36 return NULL; | |
37 } | |
38 | |
39 ngx_memcpy(sa, sockaddr, socklen); | |
40 | |
41 ls->sockaddr = sa; | |
42 ls->socklen = socklen; | |
43 | |
5263
05ba5bce31e0
Core: extended ngx_sock_ntop() with socklen parameter.
Vladimir Homutov <vl@nginx.com>
parents:
5137
diff
changeset
|
44 len = ngx_sock_ntop(sa, socklen, text, NGX_SOCKADDR_STRLEN, 1); |
3230
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
3151
diff
changeset
|
45 ls->addr_text.len = len; |
2806 | 46 |
47 switch (ls->sockaddr->sa_family) { | |
48 #if (NGX_HAVE_INET6) | |
49 case AF_INET6: | |
50 ls->addr_text_max_len = NGX_INET6_ADDRSTRLEN; | |
51 break; | |
52 #endif | |
3230
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
3151
diff
changeset
|
53 #if (NGX_HAVE_UNIX_DOMAIN) |
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
3151
diff
changeset
|
54 case AF_UNIX: |
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
3151
diff
changeset
|
55 ls->addr_text_max_len = NGX_UNIX_ADDRSTRLEN; |
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
3151
diff
changeset
|
56 len++; |
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
3151
diff
changeset
|
57 break; |
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
3151
diff
changeset
|
58 #endif |
2806 | 59 case AF_INET: |
60 ls->addr_text_max_len = NGX_INET_ADDRSTRLEN; | |
61 break; | |
62 default: | |
63 ls->addr_text_max_len = NGX_SOCKADDR_STRLEN; | |
64 break; | |
65 } | |
66 | |
3230
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
3151
diff
changeset
|
67 ls->addr_text.data = ngx_pnalloc(cf->pool, len); |
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
3151
diff
changeset
|
68 if (ls->addr_text.data == NULL) { |
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
3151
diff
changeset
|
69 return NULL; |
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
3151
diff
changeset
|
70 } |
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
3151
diff
changeset
|
71 |
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
3151
diff
changeset
|
72 ngx_memcpy(ls->addr_text.data, text, len); |
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
3151
diff
changeset
|
73 |
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
3151
diff
changeset
|
74 ls->fd = (ngx_socket_t) -1; |
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
3151
diff
changeset
|
75 ls->type = SOCK_STREAM; |
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
3151
diff
changeset
|
76 |
2806 | 77 ls->backlog = NGX_LISTEN_BACKLOG; |
78 ls->rcvbuf = -1; | |
79 ls->sndbuf = -1; | |
80 | |
3676 | 81 #if (NGX_HAVE_SETFIB) |
82 ls->setfib = -1; | |
83 #endif | |
84 | |
5456
692afcea9d0d
Added support for TCP_FASTOPEN supported in Linux >= 3.7.1.
Mathew Rodley <mathew@rodley.com.au>
parents:
5431
diff
changeset
|
85 #if (NGX_HAVE_TCP_FASTOPEN) |
692afcea9d0d
Added support for TCP_FASTOPEN supported in Linux >= 3.7.1.
Mathew Rodley <mathew@rodley.com.au>
parents:
5431
diff
changeset
|
86 ls->fastopen = -1; |
692afcea9d0d
Added support for TCP_FASTOPEN supported in Linux >= 3.7.1.
Mathew Rodley <mathew@rodley.com.au>
parents:
5431
diff
changeset
|
87 #endif |
692afcea9d0d
Added support for TCP_FASTOPEN supported in Linux >= 3.7.1.
Mathew Rodley <mathew@rodley.com.au>
parents:
5431
diff
changeset
|
88 |
2806 | 89 return ls; |
90 } | |
91 | |
92 | |
521 | 93 ngx_int_t |
6153
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
94 ngx_clone_listening(ngx_conf_t *cf, ngx_listening_t *ls) |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
95 { |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
96 #if (NGX_HAVE_REUSEPORT) |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
97 |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
98 ngx_int_t n; |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
99 ngx_core_conf_t *ccf; |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
100 ngx_listening_t ols; |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
101 |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
102 if (!ls->reuseport) { |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
103 return NGX_OK; |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
104 } |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
105 |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
106 ols = *ls; |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
107 |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
108 ccf = (ngx_core_conf_t *) ngx_get_conf(cf->cycle->conf_ctx, |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
109 ngx_core_module); |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
110 |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
111 for (n = 1; n < ccf->worker_processes; n++) { |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
112 |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
113 /* create a socket for each worker process */ |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
114 |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
115 ls = ngx_array_push(&cf->cycle->listening); |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
116 if (ls == NULL) { |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
117 return NGX_ERROR; |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
118 } |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
119 |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
120 *ls = ols; |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
121 ls->worker = n; |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
122 } |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
123 |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
124 #endif |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
125 |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
126 return NGX_OK; |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
127 } |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
128 |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
129 |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
130 ngx_int_t |
521 | 131 ngx_set_inherited_sockets(ngx_cycle_t *cycle) |
218
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
132 { |
523 | 133 size_t len; |
134 ngx_uint_t i; | |
135 ngx_listening_t *ls; | |
563 | 136 socklen_t olen; |
5550
3c5ddf0575d8
Core: handle getsockopt(TCP_FASTOPEN) failures.
Piotr Sikora <piotr@cloudflare.com>
parents:
5541
diff
changeset
|
137 #if (NGX_HAVE_DEFERRED_ACCEPT || NGX_HAVE_TCP_FASTOPEN) |
5431
91bd62a9627e
Core: handling of getsockopt(TCP_DEFER_ACCEPT) failures.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5360
diff
changeset
|
138 ngx_err_t err; |
91bd62a9627e
Core: handling of getsockopt(TCP_DEFER_ACCEPT) failures.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5360
diff
changeset
|
139 #endif |
523 | 140 #if (NGX_HAVE_DEFERRED_ACCEPT && defined SO_ACCEPTFILTER) |
141 struct accept_filter_arg af; | |
142 #endif | |
143 #if (NGX_HAVE_DEFERRED_ACCEPT && defined TCP_DEFER_ACCEPT) | |
144 int timeout; | |
145 #endif | |
6153
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
146 #if (NGX_HAVE_REUSEPORT) |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
147 int reuseport; |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
148 #endif |
218
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
149 |
219
f57597ec5249
nginx-0.0.1-2004-01-06-19:49:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
218
diff
changeset
|
150 ls = cycle->listening.elts; |
f57597ec5249
nginx-0.0.1-2004-01-06-19:49:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
218
diff
changeset
|
151 for (i = 0; i < cycle->listening.nelts; i++) { |
f57597ec5249
nginx-0.0.1-2004-01-06-19:49:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
218
diff
changeset
|
152 |
3537
d2848db4d98e
fix IPv6 and Unix domain sockets inheritance while online upgrade
Igor Sysoev <igor@sysoev.ru>
parents:
3371
diff
changeset
|
153 ls[i].sockaddr = ngx_palloc(cycle->pool, NGX_SOCKADDRLEN); |
219
f57597ec5249
nginx-0.0.1-2004-01-06-19:49:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
218
diff
changeset
|
154 if (ls[i].sockaddr == NULL) { |
f57597ec5249
nginx-0.0.1-2004-01-06-19:49:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
218
diff
changeset
|
155 return NGX_ERROR; |
f57597ec5249
nginx-0.0.1-2004-01-06-19:49:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
218
diff
changeset
|
156 } |
f57597ec5249
nginx-0.0.1-2004-01-06-19:49:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
218
diff
changeset
|
157 |
3537
d2848db4d98e
fix IPv6 and Unix domain sockets inheritance while online upgrade
Igor Sysoev <igor@sysoev.ru>
parents:
3371
diff
changeset
|
158 ls[i].socklen = NGX_SOCKADDRLEN; |
219
f57597ec5249
nginx-0.0.1-2004-01-06-19:49:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
218
diff
changeset
|
159 if (getsockname(ls[i].fd, ls[i].sockaddr, &ls[i].socklen) == -1) { |
f57597ec5249
nginx-0.0.1-2004-01-06-19:49:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
218
diff
changeset
|
160 ngx_log_error(NGX_LOG_CRIT, cycle->log, ngx_socket_errno, |
f57597ec5249
nginx-0.0.1-2004-01-06-19:49:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
218
diff
changeset
|
161 "getsockname() of the inherited " |
f57597ec5249
nginx-0.0.1-2004-01-06-19:49:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
218
diff
changeset
|
162 "socket #%d failed", ls[i].fd); |
f57597ec5249
nginx-0.0.1-2004-01-06-19:49:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
218
diff
changeset
|
163 ls[i].ignore = 1; |
218
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
164 continue; |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
165 } |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
166 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2254
diff
changeset
|
167 switch (ls[i].sockaddr->sa_family) { |
218
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
168 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2254
diff
changeset
|
169 #if (NGX_HAVE_INET6) |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2254
diff
changeset
|
170 case AF_INET6: |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2254
diff
changeset
|
171 ls[i].addr_text_max_len = NGX_INET6_ADDRSTRLEN; |
5583
f47c844acbd4
Core: allocate enough memory to hold IPv6 text address plus port.
Ruslan Ermilov <ru@nginx.com>
parents:
5557
diff
changeset
|
172 len = NGX_INET6_ADDRSTRLEN + sizeof("[]:65535") - 1; |
3292
6ed04ab2d062
allow to inherit unix domain sockets while online upgrade
Igor Sysoev <igor@sysoev.ru>
parents:
3263
diff
changeset
|
173 break; |
6ed04ab2d062
allow to inherit unix domain sockets while online upgrade
Igor Sysoev <igor@sysoev.ru>
parents:
3263
diff
changeset
|
174 #endif |
6ed04ab2d062
allow to inherit unix domain sockets while online upgrade
Igor Sysoev <igor@sysoev.ru>
parents:
3263
diff
changeset
|
175 |
6ed04ab2d062
allow to inherit unix domain sockets while online upgrade
Igor Sysoev <igor@sysoev.ru>
parents:
3263
diff
changeset
|
176 #if (NGX_HAVE_UNIX_DOMAIN) |
6ed04ab2d062
allow to inherit unix domain sockets while online upgrade
Igor Sysoev <igor@sysoev.ru>
parents:
3263
diff
changeset
|
177 case AF_UNIX: |
6ed04ab2d062
allow to inherit unix domain sockets while online upgrade
Igor Sysoev <igor@sysoev.ru>
parents:
3263
diff
changeset
|
178 ls[i].addr_text_max_len = NGX_UNIX_ADDRSTRLEN; |
6ed04ab2d062
allow to inherit unix domain sockets while online upgrade
Igor Sysoev <igor@sysoev.ru>
parents:
3263
diff
changeset
|
179 len = NGX_UNIX_ADDRSTRLEN; |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2254
diff
changeset
|
180 break; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2254
diff
changeset
|
181 #endif |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2254
diff
changeset
|
182 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2254
diff
changeset
|
183 case AF_INET: |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2254
diff
changeset
|
184 ls[i].addr_text_max_len = NGX_INET_ADDRSTRLEN; |
3292
6ed04ab2d062
allow to inherit unix domain sockets while online upgrade
Igor Sysoev <igor@sysoev.ru>
parents:
3263
diff
changeset
|
185 len = NGX_INET_ADDRSTRLEN + sizeof(":65535") - 1; |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2254
diff
changeset
|
186 break; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2254
diff
changeset
|
187 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2254
diff
changeset
|
188 default: |
219
f57597ec5249
nginx-0.0.1-2004-01-06-19:49:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
218
diff
changeset
|
189 ngx_log_error(NGX_LOG_CRIT, cycle->log, ngx_socket_errno, |
f57597ec5249
nginx-0.0.1-2004-01-06-19:49:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
218
diff
changeset
|
190 "the inherited socket #%d has " |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2254
diff
changeset
|
191 "an unsupported protocol family", ls[i].fd); |
219
f57597ec5249
nginx-0.0.1-2004-01-06-19:49:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
218
diff
changeset
|
192 ls[i].ignore = 1; |
f57597ec5249
nginx-0.0.1-2004-01-06-19:49:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
218
diff
changeset
|
193 continue; |
f57597ec5249
nginx-0.0.1-2004-01-06-19:49:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
218
diff
changeset
|
194 } |
461 | 195 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2254
diff
changeset
|
196 ls[i].addr_text.data = ngx_pnalloc(cycle->pool, len); |
219
f57597ec5249
nginx-0.0.1-2004-01-06-19:49:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
218
diff
changeset
|
197 if (ls[i].addr_text.data == NULL) { |
f57597ec5249
nginx-0.0.1-2004-01-06-19:49:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
218
diff
changeset
|
198 return NGX_ERROR; |
218
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
199 } |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
200 |
5263
05ba5bce31e0
Core: extended ngx_sock_ntop() with socklen parameter.
Vladimir Homutov <vl@nginx.com>
parents:
5137
diff
changeset
|
201 len = ngx_sock_ntop(ls[i].sockaddr, ls[i].socklen, |
05ba5bce31e0
Core: extended ngx_sock_ntop() with socklen parameter.
Vladimir Homutov <vl@nginx.com>
parents:
5137
diff
changeset
|
202 ls[i].addr_text.data, len, 1); |
461 | 203 if (len == 0) { |
219
f57597ec5249
nginx-0.0.1-2004-01-06-19:49:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
218
diff
changeset
|
204 return NGX_ERROR; |
f57597ec5249
nginx-0.0.1-2004-01-06-19:49:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
218
diff
changeset
|
205 } |
461 | 206 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2254
diff
changeset
|
207 ls[i].addr_text.len = len; |
523 | 208 |
1377
0d57c150115b
set default listen() backlog to 511 on all platforms except FreeBSD
Igor Sysoev <igor@sysoev.ru>
parents:
1225
diff
changeset
|
209 ls[i].backlog = NGX_LISTEN_BACKLOG; |
537 | 210 |
563 | 211 olen = sizeof(int); |
212 | |
213 if (getsockopt(ls[i].fd, SOL_SOCKET, SO_RCVBUF, (void *) &ls[i].rcvbuf, | |
214 &olen) | |
215 == -1) | |
216 { | |
217 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_socket_errno, | |
218 "getsockopt(SO_RCVBUF) %V failed, ignored", | |
219 &ls[i].addr_text); | |
220 | |
221 ls[i].rcvbuf = -1; | |
222 } | |
223 | |
224 olen = sizeof(int); | |
225 | |
226 if (getsockopt(ls[i].fd, SOL_SOCKET, SO_SNDBUF, (void *) &ls[i].sndbuf, | |
227 &olen) | |
228 == -1) | |
229 { | |
230 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_socket_errno, | |
231 "getsockopt(SO_SNDBUF) %V failed, ignored", | |
232 &ls[i].addr_text); | |
233 | |
234 ls[i].sndbuf = -1; | |
235 } | |
236 | |
3676 | 237 #if 0 |
238 /* SO_SETFIB is currently a set only option */ | |
239 | |
240 #if (NGX_HAVE_SETFIB) | |
241 | |
5488
c51b9491b0bd
Fixed the first argument to getsockopt().
Ruslan Ermilov <ru@nginx.com>
parents:
5464
diff
changeset
|
242 olen = sizeof(int); |
c51b9491b0bd
Fixed the first argument to getsockopt().
Ruslan Ermilov <ru@nginx.com>
parents:
5464
diff
changeset
|
243 |
c51b9491b0bd
Fixed the first argument to getsockopt().
Ruslan Ermilov <ru@nginx.com>
parents:
5464
diff
changeset
|
244 if (getsockopt(ls[i].fd, SOL_SOCKET, SO_SETFIB, |
3676 | 245 (void *) &ls[i].setfib, &olen) |
246 == -1) | |
247 { | |
248 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_socket_errno, | |
249 "getsockopt(SO_SETFIB) %V failed, ignored", | |
250 &ls[i].addr_text); | |
251 | |
252 ls[i].setfib = -1; | |
253 } | |
254 | |
255 #endif | |
256 #endif | |
257 | |
6153
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
258 #if (NGX_HAVE_REUSEPORT) |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
259 |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
260 reuseport = 0; |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
261 olen = sizeof(int); |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
262 |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
263 if (getsockopt(ls[i].fd, SOL_SOCKET, SO_REUSEPORT, |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
264 (void *) &reuseport, &olen) |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
265 == -1) |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
266 { |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
267 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_socket_errno, |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
268 "getsockopt(SO_REUSEPORT) %V failed, ignored", |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
269 &ls[i].addr_text); |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
270 |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
271 } else { |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
272 ls[i].reuseport = reuseport ? 1 : 0; |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
273 } |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
274 |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
275 #endif |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
276 |
5456
692afcea9d0d
Added support for TCP_FASTOPEN supported in Linux >= 3.7.1.
Mathew Rodley <mathew@rodley.com.au>
parents:
5431
diff
changeset
|
277 #if (NGX_HAVE_TCP_FASTOPEN) |
692afcea9d0d
Added support for TCP_FASTOPEN supported in Linux >= 3.7.1.
Mathew Rodley <mathew@rodley.com.au>
parents:
5431
diff
changeset
|
278 |
5488
c51b9491b0bd
Fixed the first argument to getsockopt().
Ruslan Ermilov <ru@nginx.com>
parents:
5464
diff
changeset
|
279 olen = sizeof(int); |
c51b9491b0bd
Fixed the first argument to getsockopt().
Ruslan Ermilov <ru@nginx.com>
parents:
5464
diff
changeset
|
280 |
c51b9491b0bd
Fixed the first argument to getsockopt().
Ruslan Ermilov <ru@nginx.com>
parents:
5464
diff
changeset
|
281 if (getsockopt(ls[i].fd, IPPROTO_TCP, TCP_FASTOPEN, |
5456
692afcea9d0d
Added support for TCP_FASTOPEN supported in Linux >= 3.7.1.
Mathew Rodley <mathew@rodley.com.au>
parents:
5431
diff
changeset
|
282 (void *) &ls[i].fastopen, &olen) |
692afcea9d0d
Added support for TCP_FASTOPEN supported in Linux >= 3.7.1.
Mathew Rodley <mathew@rodley.com.au>
parents:
5431
diff
changeset
|
283 == -1) |
692afcea9d0d
Added support for TCP_FASTOPEN supported in Linux >= 3.7.1.
Mathew Rodley <mathew@rodley.com.au>
parents:
5431
diff
changeset
|
284 { |
5550
3c5ddf0575d8
Core: handle getsockopt(TCP_FASTOPEN) failures.
Piotr Sikora <piotr@cloudflare.com>
parents:
5541
diff
changeset
|
285 err = ngx_socket_errno; |
3c5ddf0575d8
Core: handle getsockopt(TCP_FASTOPEN) failures.
Piotr Sikora <piotr@cloudflare.com>
parents:
5541
diff
changeset
|
286 |
3c5ddf0575d8
Core: handle getsockopt(TCP_FASTOPEN) failures.
Piotr Sikora <piotr@cloudflare.com>
parents:
5541
diff
changeset
|
287 if (err != NGX_EOPNOTSUPP && err != NGX_ENOPROTOOPT) { |
3c5ddf0575d8
Core: handle getsockopt(TCP_FASTOPEN) failures.
Piotr Sikora <piotr@cloudflare.com>
parents:
5541
diff
changeset
|
288 ngx_log_error(NGX_LOG_NOTICE, cycle->log, err, |
3c5ddf0575d8
Core: handle getsockopt(TCP_FASTOPEN) failures.
Piotr Sikora <piotr@cloudflare.com>
parents:
5541
diff
changeset
|
289 "getsockopt(TCP_FASTOPEN) %V failed, ignored", |
3c5ddf0575d8
Core: handle getsockopt(TCP_FASTOPEN) failures.
Piotr Sikora <piotr@cloudflare.com>
parents:
5541
diff
changeset
|
290 &ls[i].addr_text); |
3c5ddf0575d8
Core: handle getsockopt(TCP_FASTOPEN) failures.
Piotr Sikora <piotr@cloudflare.com>
parents:
5541
diff
changeset
|
291 } |
5456
692afcea9d0d
Added support for TCP_FASTOPEN supported in Linux >= 3.7.1.
Mathew Rodley <mathew@rodley.com.au>
parents:
5431
diff
changeset
|
292 |
692afcea9d0d
Added support for TCP_FASTOPEN supported in Linux >= 3.7.1.
Mathew Rodley <mathew@rodley.com.au>
parents:
5431
diff
changeset
|
293 ls[i].fastopen = -1; |
692afcea9d0d
Added support for TCP_FASTOPEN supported in Linux >= 3.7.1.
Mathew Rodley <mathew@rodley.com.au>
parents:
5431
diff
changeset
|
294 } |
692afcea9d0d
Added support for TCP_FASTOPEN supported in Linux >= 3.7.1.
Mathew Rodley <mathew@rodley.com.au>
parents:
5431
diff
changeset
|
295 |
692afcea9d0d
Added support for TCP_FASTOPEN supported in Linux >= 3.7.1.
Mathew Rodley <mathew@rodley.com.au>
parents:
5431
diff
changeset
|
296 #endif |
692afcea9d0d
Added support for TCP_FASTOPEN supported in Linux >= 3.7.1.
Mathew Rodley <mathew@rodley.com.au>
parents:
5431
diff
changeset
|
297 |
523 | 298 #if (NGX_HAVE_DEFERRED_ACCEPT && defined SO_ACCEPTFILTER) |
299 | |
300 ngx_memzero(&af, sizeof(struct accept_filter_arg)); | |
563 | 301 olen = sizeof(struct accept_filter_arg); |
523 | 302 |
563 | 303 if (getsockopt(ls[i].fd, SOL_SOCKET, SO_ACCEPTFILTER, &af, &olen) |
523 | 304 == -1) |
305 { | |
5557
188481078faf
Use ngx_socket_errno where appropriate.
Piotr Sikora <piotr@cloudflare.com>
parents:
5550
diff
changeset
|
306 err = ngx_socket_errno; |
541 | 307 |
308 if (err == NGX_EINVAL) { | |
309 continue; | |
310 } | |
311 | |
312 ngx_log_error(NGX_LOG_NOTICE, cycle->log, err, | |
523 | 313 "getsockopt(SO_ACCEPTFILTER) for %V failed, ignored", |
314 &ls[i].addr_text); | |
315 continue; | |
316 } | |
317 | |
563 | 318 if (olen < sizeof(struct accept_filter_arg) || af.af_name[0] == '\0') { |
523 | 319 continue; |
320 } | |
321 | |
322 ls[i].accept_filter = ngx_palloc(cycle->pool, 16); | |
323 if (ls[i].accept_filter == NULL) { | |
324 return NGX_ERROR; | |
325 } | |
326 | |
327 (void) ngx_cpystrn((u_char *) ls[i].accept_filter, | |
328 (u_char *) af.af_name, 16); | |
329 #endif | |
330 | |
331 #if (NGX_HAVE_DEFERRED_ACCEPT && defined TCP_DEFER_ACCEPT) | |
332 | |
333 timeout = 0; | |
563 | 334 olen = sizeof(int); |
523 | 335 |
563 | 336 if (getsockopt(ls[i].fd, IPPROTO_TCP, TCP_DEFER_ACCEPT, &timeout, &olen) |
523 | 337 == -1) |
338 { | |
5557
188481078faf
Use ngx_socket_errno where appropriate.
Piotr Sikora <piotr@cloudflare.com>
parents:
5550
diff
changeset
|
339 err = ngx_socket_errno; |
5431
91bd62a9627e
Core: handling of getsockopt(TCP_DEFER_ACCEPT) failures.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5360
diff
changeset
|
340 |
91bd62a9627e
Core: handling of getsockopt(TCP_DEFER_ACCEPT) failures.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5360
diff
changeset
|
341 if (err == NGX_EOPNOTSUPP) { |
91bd62a9627e
Core: handling of getsockopt(TCP_DEFER_ACCEPT) failures.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5360
diff
changeset
|
342 continue; |
91bd62a9627e
Core: handling of getsockopt(TCP_DEFER_ACCEPT) failures.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5360
diff
changeset
|
343 } |
91bd62a9627e
Core: handling of getsockopt(TCP_DEFER_ACCEPT) failures.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5360
diff
changeset
|
344 |
91bd62a9627e
Core: handling of getsockopt(TCP_DEFER_ACCEPT) failures.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5360
diff
changeset
|
345 ngx_log_error(NGX_LOG_NOTICE, cycle->log, err, |
523 | 346 "getsockopt(TCP_DEFER_ACCEPT) for %V failed, ignored", |
347 &ls[i].addr_text); | |
348 continue; | |
349 } | |
350 | |
565 | 351 if (olen < sizeof(int) || timeout == 0) { |
523 | 352 continue; |
353 } | |
354 | |
355 ls[i].deferred_accept = 1; | |
356 #endif | |
218
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
357 } |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
358 |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
359 return NGX_OK; |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
360 } |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
361 |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
362 |
521 | 363 ngx_int_t |
364 ngx_open_listening_sockets(ngx_cycle_t *cycle) | |
218
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
365 { |
563 | 366 int reuseaddr; |
367 ngx_uint_t i, tries, failed; | |
253
b6793bc5034b
nginx-0.0.2-2004-02-09-10:46:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
242
diff
changeset
|
368 ngx_err_t err; |
b6793bc5034b
nginx-0.0.2-2004-02-09-10:46:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
242
diff
changeset
|
369 ngx_log_t *log; |
b6793bc5034b
nginx-0.0.2-2004-02-09-10:46:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
242
diff
changeset
|
370 ngx_socket_t s; |
b6793bc5034b
nginx-0.0.2-2004-02-09-10:46:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
242
diff
changeset
|
371 ngx_listening_t *ls; |
218
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
372 |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
373 reuseaddr = 1; |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
374 #if (NGX_SUPPRESS_WARN) |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
375 failed = 0; |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
376 #endif |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
377 |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
378 log = cycle->log; |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
379 |
563 | 380 /* TODO: configurable try number */ |
218
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
381 |
2024 | 382 for (tries = 5; tries; tries--) { |
218
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
383 failed = 0; |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
384 |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
385 /* for each listening socket */ |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
386 |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
387 ls = cycle->listening.elts; |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
388 for (i = 0; i < cycle->listening.nelts; i++) { |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
389 |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
390 if (ls[i].ignore) { |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
391 continue; |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
392 } |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
393 |
6153
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
394 #if (NGX_HAVE_REUSEPORT) |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
395 |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
396 if (ls[i].add_reuseport) { |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
397 |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
398 /* |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
399 * to allow transition from a socket without SO_REUSEPORT |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
400 * to multiple sockets with SO_REUSEPORT, we have to set |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
401 * SO_REUSEPORT on the old socket before opening new ones |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
402 */ |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
403 |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
404 int reuseport = 1; |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
405 |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
406 if (setsockopt(ls[i].fd, SOL_SOCKET, SO_REUSEPORT, |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
407 (const void *) &reuseport, sizeof(int)) |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
408 == -1) |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
409 { |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
410 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_socket_errno, |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
411 "setsockopt(SO_REUSEPORT) %V failed, ignored", |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
412 &ls[i].addr_text); |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
413 } |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
414 |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
415 ls[i].add_reuseport = 0; |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
416 } |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
417 #endif |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
418 |
5360
3d2d3e1cf427
Win32: MinGW GCC compatibility.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5283
diff
changeset
|
419 if (ls[i].fd != (ngx_socket_t) -1) { |
218
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
420 continue; |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
421 } |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
422 |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
423 if (ls[i].inherited) { |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
424 |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
425 /* TODO: close on exit */ |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
426 /* TODO: nonblocking */ |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
427 /* TODO: deferred accept */ |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
428 |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
429 continue; |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
430 } |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
431 |
2198
5975975eedc0
ngx_sock_ntop() takes family from sockaddr, remove duplicate field
Igor Sysoev <igor@sysoev.ru>
parents:
2197
diff
changeset
|
432 s = ngx_socket(ls[i].sockaddr->sa_family, ls[i].type, 0); |
218
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
433 |
5360
3d2d3e1cf427
Win32: MinGW GCC compatibility.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5283
diff
changeset
|
434 if (s == (ngx_socket_t) -1) { |
218
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
435 ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno, |
461 | 436 ngx_socket_n " %V failed", &ls[i].addr_text); |
218
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
437 return NGX_ERROR; |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
438 } |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
439 |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
440 if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, |
563 | 441 (const void *) &reuseaddr, sizeof(int)) |
442 == -1) | |
443 { | |
218
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
444 ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno, |
461 | 445 "setsockopt(SO_REUSEADDR) %V failed", |
446 &ls[i].addr_text); | |
563 | 447 |
1223 | 448 if (ngx_close_socket(s) == -1) { |
563 | 449 ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno, |
450 ngx_close_socket_n " %V failed", | |
451 &ls[i].addr_text); | |
1223 | 452 } |
563 | 453 |
218
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
454 return NGX_ERROR; |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
455 } |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
456 |
6153
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
457 #if (NGX_HAVE_REUSEPORT) |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
458 |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
459 if (ls[i].reuseport) { |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
460 int reuseport; |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
461 |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
462 reuseport = 1; |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
463 |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
464 if (setsockopt(s, SOL_SOCKET, SO_REUSEPORT, |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
465 (const void *) &reuseport, sizeof(int)) |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
466 == -1) |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
467 { |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
468 ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno, |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
469 "setsockopt(SO_REUSEPORT) %V failed, ignored", |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
470 &ls[i].addr_text); |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
471 |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
472 if (ngx_close_socket(s) == -1) { |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
473 ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno, |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
474 ngx_close_socket_n " %V failed", |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
475 &ls[i].addr_text); |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
476 } |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
477 |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
478 return NGX_ERROR; |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
479 } |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
480 } |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
481 #endif |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
482 |
2562 | 483 #if (NGX_HAVE_INET6 && defined IPV6_V6ONLY) |
484 | |
4771
bdcdbdf35b52
Core: ipv6only is now on by default.
Ruslan Ermilov <ru@nginx.com>
parents:
4572
diff
changeset
|
485 if (ls[i].sockaddr->sa_family == AF_INET6) { |
2562 | 486 int ipv6only; |
487 | |
4771
bdcdbdf35b52
Core: ipv6only is now on by default.
Ruslan Ermilov <ru@nginx.com>
parents:
4572
diff
changeset
|
488 ipv6only = ls[i].ipv6only; |
2562 | 489 |
490 if (setsockopt(s, IPPROTO_IPV6, IPV6_V6ONLY, | |
491 (const void *) &ipv6only, sizeof(int)) | |
492 == -1) | |
493 { | |
2801 | 494 ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno, |
2562 | 495 "setsockopt(IPV6_V6ONLY) %V failed, ignored", |
496 &ls[i].addr_text); | |
497 } | |
498 } | |
499 #endif | |
218
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
500 /* TODO: close on exit */ |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
501 |
6125
4dc8e7b62216
Removed the obsolete aio module.
Ruslan Ermilov <ru@nginx.com>
parents:
6038
diff
changeset
|
502 if (!(ngx_event_flags & NGX_USE_IOCP_EVENT)) { |
218
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
503 if (ngx_nonblocking(s) == -1) { |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
504 ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno, |
461 | 505 ngx_nonblocking_n " %V failed", |
506 &ls[i].addr_text); | |
563 | 507 |
1223 | 508 if (ngx_close_socket(s) == -1) { |
563 | 509 ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno, |
510 ngx_close_socket_n " %V failed", | |
511 &ls[i].addr_text); | |
1223 | 512 } |
563 | 513 |
218
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
514 return NGX_ERROR; |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
515 } |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
516 } |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
517 |
2801 | 518 ngx_log_debug2(NGX_LOG_DEBUG_CORE, log, 0, |
593 | 519 "bind() %V #%d ", &ls[i].addr_text, s); |
520 | |
218
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
521 if (bind(s, ls[i].sockaddr, ls[i].socklen) == -1) { |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
522 err = ngx_socket_errno; |
563 | 523 |
5740
4440438eb086
Core: plugged socket leak during configuration test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5583
diff
changeset
|
524 if (err != NGX_EADDRINUSE || !ngx_test_config) { |
4440438eb086
Core: plugged socket leak during configuration test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5583
diff
changeset
|
525 ngx_log_error(NGX_LOG_EMERG, log, err, |
4440438eb086
Core: plugged socket leak during configuration test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5583
diff
changeset
|
526 "bind() to %V failed", &ls[i].addr_text); |
563 | 527 } |
528 | |
1223 | 529 if (ngx_close_socket(s) == -1) { |
218
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
530 ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno, |
461 | 531 ngx_close_socket_n " %V failed", |
532 &ls[i].addr_text); | |
1223 | 533 } |
218
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
534 |
563 | 535 if (err != NGX_EADDRINUSE) { |
536 return NGX_ERROR; | |
537 } | |
538 | |
5740
4440438eb086
Core: plugged socket leak during configuration test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5583
diff
changeset
|
539 if (!ngx_test_config) { |
4440438eb086
Core: plugged socket leak during configuration test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5583
diff
changeset
|
540 failed = 1; |
4440438eb086
Core: plugged socket leak during configuration test.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5583
diff
changeset
|
541 } |
563 | 542 |
218
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
543 continue; |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
544 } |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
545 |
3260
a6df0624203c
unlink unix domain socket file after testing
Igor Sysoev <igor@sysoev.ru>
parents:
3230
diff
changeset
|
546 #if (NGX_HAVE_UNIX_DOMAIN) |
a6df0624203c
unlink unix domain socket file after testing
Igor Sysoev <igor@sysoev.ru>
parents:
3230
diff
changeset
|
547 |
3371
102fdc22de4d
chmod unix listen domain socket to 0666
Igor Sysoev <igor@sysoev.ru>
parents:
3358
diff
changeset
|
548 if (ls[i].sockaddr->sa_family == AF_UNIX) { |
102fdc22de4d
chmod unix listen domain socket to 0666
Igor Sysoev <igor@sysoev.ru>
parents:
3358
diff
changeset
|
549 mode_t mode; |
102fdc22de4d
chmod unix listen domain socket to 0666
Igor Sysoev <igor@sysoev.ru>
parents:
3358
diff
changeset
|
550 u_char *name; |
102fdc22de4d
chmod unix listen domain socket to 0666
Igor Sysoev <igor@sysoev.ru>
parents:
3358
diff
changeset
|
551 |
102fdc22de4d
chmod unix listen domain socket to 0666
Igor Sysoev <igor@sysoev.ru>
parents:
3358
diff
changeset
|
552 name = ls[i].addr_text.data + sizeof("unix:") - 1; |
102fdc22de4d
chmod unix listen domain socket to 0666
Igor Sysoev <igor@sysoev.ru>
parents:
3358
diff
changeset
|
553 mode = (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH); |
3260
a6df0624203c
unlink unix domain socket file after testing
Igor Sysoev <igor@sysoev.ru>
parents:
3230
diff
changeset
|
554 |
3371
102fdc22de4d
chmod unix listen domain socket to 0666
Igor Sysoev <igor@sysoev.ru>
parents:
3358
diff
changeset
|
555 if (chmod((char *) name, mode) == -1) { |
102fdc22de4d
chmod unix listen domain socket to 0666
Igor Sysoev <igor@sysoev.ru>
parents:
3358
diff
changeset
|
556 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, |
102fdc22de4d
chmod unix listen domain socket to 0666
Igor Sysoev <igor@sysoev.ru>
parents:
3358
diff
changeset
|
557 "chmod() \"%s\" failed", name); |
102fdc22de4d
chmod unix listen domain socket to 0666
Igor Sysoev <igor@sysoev.ru>
parents:
3358
diff
changeset
|
558 } |
102fdc22de4d
chmod unix listen domain socket to 0666
Igor Sysoev <igor@sysoev.ru>
parents:
3358
diff
changeset
|
559 |
102fdc22de4d
chmod unix listen domain socket to 0666
Igor Sysoev <igor@sysoev.ru>
parents:
3358
diff
changeset
|
560 if (ngx_test_config) { |
5137
f941cf265cc5
Use NGX_FILE_ERROR for handling file operations errors.
Valentin Bartenev <vbart@nginx.com>
parents:
5115
diff
changeset
|
561 if (ngx_delete_file(name) == NGX_FILE_ERROR) { |
3371
102fdc22de4d
chmod unix listen domain socket to 0666
Igor Sysoev <igor@sysoev.ru>
parents:
3358
diff
changeset
|
562 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, |
102fdc22de4d
chmod unix listen domain socket to 0666
Igor Sysoev <igor@sysoev.ru>
parents:
3358
diff
changeset
|
563 ngx_delete_file_n " %s failed", name); |
102fdc22de4d
chmod unix listen domain socket to 0666
Igor Sysoev <igor@sysoev.ru>
parents:
3358
diff
changeset
|
564 } |
3260
a6df0624203c
unlink unix domain socket file after testing
Igor Sysoev <igor@sysoev.ru>
parents:
3230
diff
changeset
|
565 } |
a6df0624203c
unlink unix domain socket file after testing
Igor Sysoev <igor@sysoev.ru>
parents:
3230
diff
changeset
|
566 } |
a6df0624203c
unlink unix domain socket file after testing
Igor Sysoev <igor@sysoev.ru>
parents:
3230
diff
changeset
|
567 #endif |
a6df0624203c
unlink unix domain socket file after testing
Igor Sysoev <igor@sysoev.ru>
parents:
3230
diff
changeset
|
568 |
1224
53e3dd035140
do listen() just after bind() to exit early
Igor Sysoev <igor@sysoev.ru>
parents:
1223
diff
changeset
|
569 if (listen(s, ls[i].backlog) == -1) { |
6218
3096ae76ba47
Workaround for "configuration file test failed" under OpenVZ.
Gena Makhomed <gmm@csdoc.com>
parents:
6153
diff
changeset
|
570 err = ngx_socket_errno; |
3096ae76ba47
Workaround for "configuration file test failed" under OpenVZ.
Gena Makhomed <gmm@csdoc.com>
parents:
6153
diff
changeset
|
571 |
3096ae76ba47
Workaround for "configuration file test failed" under OpenVZ.
Gena Makhomed <gmm@csdoc.com>
parents:
6153
diff
changeset
|
572 /* |
3096ae76ba47
Workaround for "configuration file test failed" under OpenVZ.
Gena Makhomed <gmm@csdoc.com>
parents:
6153
diff
changeset
|
573 * on OpenVZ after suspend/resume EADDRINUSE |
3096ae76ba47
Workaround for "configuration file test failed" under OpenVZ.
Gena Makhomed <gmm@csdoc.com>
parents:
6153
diff
changeset
|
574 * may be returned by listen() instead of bind(), see |
3096ae76ba47
Workaround for "configuration file test failed" under OpenVZ.
Gena Makhomed <gmm@csdoc.com>
parents:
6153
diff
changeset
|
575 * https://bugzilla.openvz.org/show_bug.cgi?id=2470 |
3096ae76ba47
Workaround for "configuration file test failed" under OpenVZ.
Gena Makhomed <gmm@csdoc.com>
parents:
6153
diff
changeset
|
576 */ |
3096ae76ba47
Workaround for "configuration file test failed" under OpenVZ.
Gena Makhomed <gmm@csdoc.com>
parents:
6153
diff
changeset
|
577 |
3096ae76ba47
Workaround for "configuration file test failed" under OpenVZ.
Gena Makhomed <gmm@csdoc.com>
parents:
6153
diff
changeset
|
578 if (err != NGX_EADDRINUSE || !ngx_test_config) { |
3096ae76ba47
Workaround for "configuration file test failed" under OpenVZ.
Gena Makhomed <gmm@csdoc.com>
parents:
6153
diff
changeset
|
579 ngx_log_error(NGX_LOG_EMERG, log, err, |
3096ae76ba47
Workaround for "configuration file test failed" under OpenVZ.
Gena Makhomed <gmm@csdoc.com>
parents:
6153
diff
changeset
|
580 "listen() to %V, backlog %d failed", |
3096ae76ba47
Workaround for "configuration file test failed" under OpenVZ.
Gena Makhomed <gmm@csdoc.com>
parents:
6153
diff
changeset
|
581 &ls[i].addr_text, ls[i].backlog); |
3096ae76ba47
Workaround for "configuration file test failed" under OpenVZ.
Gena Makhomed <gmm@csdoc.com>
parents:
6153
diff
changeset
|
582 } |
1224
53e3dd035140
do listen() just after bind() to exit early
Igor Sysoev <igor@sysoev.ru>
parents:
1223
diff
changeset
|
583 |
53e3dd035140
do listen() just after bind() to exit early
Igor Sysoev <igor@sysoev.ru>
parents:
1223
diff
changeset
|
584 if (ngx_close_socket(s) == -1) { |
53e3dd035140
do listen() just after bind() to exit early
Igor Sysoev <igor@sysoev.ru>
parents:
1223
diff
changeset
|
585 ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno, |
53e3dd035140
do listen() just after bind() to exit early
Igor Sysoev <igor@sysoev.ru>
parents:
1223
diff
changeset
|
586 ngx_close_socket_n " %V failed", |
53e3dd035140
do listen() just after bind() to exit early
Igor Sysoev <igor@sysoev.ru>
parents:
1223
diff
changeset
|
587 &ls[i].addr_text); |
53e3dd035140
do listen() just after bind() to exit early
Igor Sysoev <igor@sysoev.ru>
parents:
1223
diff
changeset
|
588 } |
53e3dd035140
do listen() just after bind() to exit early
Igor Sysoev <igor@sysoev.ru>
parents:
1223
diff
changeset
|
589 |
6218
3096ae76ba47
Workaround for "configuration file test failed" under OpenVZ.
Gena Makhomed <gmm@csdoc.com>
parents:
6153
diff
changeset
|
590 if (err != NGX_EADDRINUSE) { |
3096ae76ba47
Workaround for "configuration file test failed" under OpenVZ.
Gena Makhomed <gmm@csdoc.com>
parents:
6153
diff
changeset
|
591 return NGX_ERROR; |
3096ae76ba47
Workaround for "configuration file test failed" under OpenVZ.
Gena Makhomed <gmm@csdoc.com>
parents:
6153
diff
changeset
|
592 } |
3096ae76ba47
Workaround for "configuration file test failed" under OpenVZ.
Gena Makhomed <gmm@csdoc.com>
parents:
6153
diff
changeset
|
593 |
3096ae76ba47
Workaround for "configuration file test failed" under OpenVZ.
Gena Makhomed <gmm@csdoc.com>
parents:
6153
diff
changeset
|
594 if (!ngx_test_config) { |
3096ae76ba47
Workaround for "configuration file test failed" under OpenVZ.
Gena Makhomed <gmm@csdoc.com>
parents:
6153
diff
changeset
|
595 failed = 1; |
3096ae76ba47
Workaround for "configuration file test failed" under OpenVZ.
Gena Makhomed <gmm@csdoc.com>
parents:
6153
diff
changeset
|
596 } |
3096ae76ba47
Workaround for "configuration file test failed" under OpenVZ.
Gena Makhomed <gmm@csdoc.com>
parents:
6153
diff
changeset
|
597 |
3096ae76ba47
Workaround for "configuration file test failed" under OpenVZ.
Gena Makhomed <gmm@csdoc.com>
parents:
6153
diff
changeset
|
598 continue; |
1224
53e3dd035140
do listen() just after bind() to exit early
Igor Sysoev <igor@sysoev.ru>
parents:
1223
diff
changeset
|
599 } |
53e3dd035140
do listen() just after bind() to exit early
Igor Sysoev <igor@sysoev.ru>
parents:
1223
diff
changeset
|
600 |
563 | 601 ls[i].listen = 1; |
218
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
602 |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
603 ls[i].fd = s; |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
604 } |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
605 |
563 | 606 if (!failed) { |
218
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
607 break; |
563 | 608 } |
218
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
609 |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
610 /* TODO: delay configurable */ |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
611 |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
612 ngx_log_error(NGX_LOG_NOTICE, log, 0, |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
613 "try again to bind() after 500ms"); |
563 | 614 |
218
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
615 ngx_msleep(500); |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
616 } |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
617 |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
618 if (failed) { |
477 | 619 ngx_log_error(NGX_LOG_EMERG, log, 0, "still could not bind()"); |
218
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
620 return NGX_ERROR; |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
621 } |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
622 |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
623 return NGX_OK; |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
624 } |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
625 |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
626 |
521 | 627 void |
2802 | 628 ngx_configure_listening_sockets(ngx_cycle_t *cycle) |
563 | 629 { |
5282
31690d934175
Style: reuse one int variable in ngx_configure_listening_sockets().
Ruslan Ermilov <ru@nginx.com>
parents:
5264
diff
changeset
|
630 int value; |
563 | 631 ngx_uint_t i; |
632 ngx_listening_t *ls; | |
633 | |
634 #if (NGX_HAVE_DEFERRED_ACCEPT && defined SO_ACCEPTFILTER) | |
635 struct accept_filter_arg af; | |
636 #endif | |
637 | |
638 ls = cycle->listening.elts; | |
639 for (i = 0; i < cycle->listening.nelts; i++) { | |
640 | |
2803
60758ab4e5f4
move listen log copying from ngx_open_listening_sockets()
Igor Sysoev <igor@sysoev.ru>
parents:
2802
diff
changeset
|
641 ls[i].log = *ls[i].logp; |
60758ab4e5f4
move listen log copying from ngx_open_listening_sockets()
Igor Sysoev <igor@sysoev.ru>
parents:
2802
diff
changeset
|
642 |
563 | 643 if (ls[i].rcvbuf != -1) { |
644 if (setsockopt(ls[i].fd, SOL_SOCKET, SO_RCVBUF, | |
645 (const void *) &ls[i].rcvbuf, sizeof(int)) | |
646 == -1) | |
647 { | |
648 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_socket_errno, | |
569 | 649 "setsockopt(SO_RCVBUF, %d) %V failed, ignored", |
650 ls[i].rcvbuf, &ls[i].addr_text); | |
563 | 651 } |
652 } | |
653 | |
654 if (ls[i].sndbuf != -1) { | |
655 if (setsockopt(ls[i].fd, SOL_SOCKET, SO_SNDBUF, | |
656 (const void *) &ls[i].sndbuf, sizeof(int)) | |
657 == -1) | |
658 { | |
659 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_socket_errno, | |
569 | 660 "setsockopt(SO_SNDBUF, %d) %V failed, ignored", |
661 ls[i].sndbuf, &ls[i].addr_text); | |
563 | 662 } |
663 } | |
664 | |
4323
c4513d4dd024
Added the "so_keepalive=" parameter to the "listen" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4016
diff
changeset
|
665 if (ls[i].keepalive) { |
5282
31690d934175
Style: reuse one int variable in ngx_configure_listening_sockets().
Ruslan Ermilov <ru@nginx.com>
parents:
5264
diff
changeset
|
666 value = (ls[i].keepalive == 1) ? 1 : 0; |
4323
c4513d4dd024
Added the "so_keepalive=" parameter to the "listen" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4016
diff
changeset
|
667 |
c4513d4dd024
Added the "so_keepalive=" parameter to the "listen" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4016
diff
changeset
|
668 if (setsockopt(ls[i].fd, SOL_SOCKET, SO_KEEPALIVE, |
5282
31690d934175
Style: reuse one int variable in ngx_configure_listening_sockets().
Ruslan Ermilov <ru@nginx.com>
parents:
5264
diff
changeset
|
669 (const void *) &value, sizeof(int)) |
4323
c4513d4dd024
Added the "so_keepalive=" parameter to the "listen" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4016
diff
changeset
|
670 == -1) |
c4513d4dd024
Added the "so_keepalive=" parameter to the "listen" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4016
diff
changeset
|
671 { |
c4513d4dd024
Added the "so_keepalive=" parameter to the "listen" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4016
diff
changeset
|
672 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_socket_errno, |
c4513d4dd024
Added the "so_keepalive=" parameter to the "listen" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4016
diff
changeset
|
673 "setsockopt(SO_KEEPALIVE, %d) %V failed, ignored", |
5282
31690d934175
Style: reuse one int variable in ngx_configure_listening_sockets().
Ruslan Ermilov <ru@nginx.com>
parents:
5264
diff
changeset
|
674 value, &ls[i].addr_text); |
4323
c4513d4dd024
Added the "so_keepalive=" parameter to the "listen" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4016
diff
changeset
|
675 } |
c4513d4dd024
Added the "so_keepalive=" parameter to the "listen" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4016
diff
changeset
|
676 } |
c4513d4dd024
Added the "so_keepalive=" parameter to the "listen" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4016
diff
changeset
|
677 |
4522 | 678 #if (NGX_HAVE_KEEPALIVE_TUNABLE) |
4323
c4513d4dd024
Added the "so_keepalive=" parameter to the "listen" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4016
diff
changeset
|
679 |
c4513d4dd024
Added the "so_keepalive=" parameter to the "listen" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4016
diff
changeset
|
680 if (ls[i].keepidle) { |
5283
6d73e0dc4f64
On DragonFlyBSD, TCP_KEEPIDLE and TCP_KEEPINTVL are in msecs.
Ruslan Ermilov <ru@nginx.com>
parents:
5282
diff
changeset
|
681 value = ls[i].keepidle; |
6d73e0dc4f64
On DragonFlyBSD, TCP_KEEPIDLE and TCP_KEEPINTVL are in msecs.
Ruslan Ermilov <ru@nginx.com>
parents:
5282
diff
changeset
|
682 |
6d73e0dc4f64
On DragonFlyBSD, TCP_KEEPIDLE and TCP_KEEPINTVL are in msecs.
Ruslan Ermilov <ru@nginx.com>
parents:
5282
diff
changeset
|
683 #if (NGX_KEEPALIVE_FACTOR) |
6d73e0dc4f64
On DragonFlyBSD, TCP_KEEPIDLE and TCP_KEEPINTVL are in msecs.
Ruslan Ermilov <ru@nginx.com>
parents:
5282
diff
changeset
|
684 value *= NGX_KEEPALIVE_FACTOR; |
6d73e0dc4f64
On DragonFlyBSD, TCP_KEEPIDLE and TCP_KEEPINTVL are in msecs.
Ruslan Ermilov <ru@nginx.com>
parents:
5282
diff
changeset
|
685 #endif |
6d73e0dc4f64
On DragonFlyBSD, TCP_KEEPIDLE and TCP_KEEPINTVL are in msecs.
Ruslan Ermilov <ru@nginx.com>
parents:
5282
diff
changeset
|
686 |
4323
c4513d4dd024
Added the "so_keepalive=" parameter to the "listen" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4016
diff
changeset
|
687 if (setsockopt(ls[i].fd, IPPROTO_TCP, TCP_KEEPIDLE, |
5283
6d73e0dc4f64
On DragonFlyBSD, TCP_KEEPIDLE and TCP_KEEPINTVL are in msecs.
Ruslan Ermilov <ru@nginx.com>
parents:
5282
diff
changeset
|
688 (const void *) &value, sizeof(int)) |
4323
c4513d4dd024
Added the "so_keepalive=" parameter to the "listen" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4016
diff
changeset
|
689 == -1) |
c4513d4dd024
Added the "so_keepalive=" parameter to the "listen" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4016
diff
changeset
|
690 { |
c4513d4dd024
Added the "so_keepalive=" parameter to the "listen" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4016
diff
changeset
|
691 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_socket_errno, |
c4513d4dd024
Added the "so_keepalive=" parameter to the "listen" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4016
diff
changeset
|
692 "setsockopt(TCP_KEEPIDLE, %d) %V failed, ignored", |
5283
6d73e0dc4f64
On DragonFlyBSD, TCP_KEEPIDLE and TCP_KEEPINTVL are in msecs.
Ruslan Ermilov <ru@nginx.com>
parents:
5282
diff
changeset
|
693 value, &ls[i].addr_text); |
4323
c4513d4dd024
Added the "so_keepalive=" parameter to the "listen" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4016
diff
changeset
|
694 } |
c4513d4dd024
Added the "so_keepalive=" parameter to the "listen" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4016
diff
changeset
|
695 } |
c4513d4dd024
Added the "so_keepalive=" parameter to the "listen" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4016
diff
changeset
|
696 |
c4513d4dd024
Added the "so_keepalive=" parameter to the "listen" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4016
diff
changeset
|
697 if (ls[i].keepintvl) { |
5283
6d73e0dc4f64
On DragonFlyBSD, TCP_KEEPIDLE and TCP_KEEPINTVL are in msecs.
Ruslan Ermilov <ru@nginx.com>
parents:
5282
diff
changeset
|
698 value = ls[i].keepintvl; |
6d73e0dc4f64
On DragonFlyBSD, TCP_KEEPIDLE and TCP_KEEPINTVL are in msecs.
Ruslan Ermilov <ru@nginx.com>
parents:
5282
diff
changeset
|
699 |
6d73e0dc4f64
On DragonFlyBSD, TCP_KEEPIDLE and TCP_KEEPINTVL are in msecs.
Ruslan Ermilov <ru@nginx.com>
parents:
5282
diff
changeset
|
700 #if (NGX_KEEPALIVE_FACTOR) |
6d73e0dc4f64
On DragonFlyBSD, TCP_KEEPIDLE and TCP_KEEPINTVL are in msecs.
Ruslan Ermilov <ru@nginx.com>
parents:
5282
diff
changeset
|
701 value *= NGX_KEEPALIVE_FACTOR; |
6d73e0dc4f64
On DragonFlyBSD, TCP_KEEPIDLE and TCP_KEEPINTVL are in msecs.
Ruslan Ermilov <ru@nginx.com>
parents:
5282
diff
changeset
|
702 #endif |
6d73e0dc4f64
On DragonFlyBSD, TCP_KEEPIDLE and TCP_KEEPINTVL are in msecs.
Ruslan Ermilov <ru@nginx.com>
parents:
5282
diff
changeset
|
703 |
4323
c4513d4dd024
Added the "so_keepalive=" parameter to the "listen" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4016
diff
changeset
|
704 if (setsockopt(ls[i].fd, IPPROTO_TCP, TCP_KEEPINTVL, |
5283
6d73e0dc4f64
On DragonFlyBSD, TCP_KEEPIDLE and TCP_KEEPINTVL are in msecs.
Ruslan Ermilov <ru@nginx.com>
parents:
5282
diff
changeset
|
705 (const void *) &value, sizeof(int)) |
4323
c4513d4dd024
Added the "so_keepalive=" parameter to the "listen" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4016
diff
changeset
|
706 == -1) |
c4513d4dd024
Added the "so_keepalive=" parameter to the "listen" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4016
diff
changeset
|
707 { |
c4513d4dd024
Added the "so_keepalive=" parameter to the "listen" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4016
diff
changeset
|
708 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_socket_errno, |
c4513d4dd024
Added the "so_keepalive=" parameter to the "listen" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4016
diff
changeset
|
709 "setsockopt(TCP_KEEPINTVL, %d) %V failed, ignored", |
5283
6d73e0dc4f64
On DragonFlyBSD, TCP_KEEPIDLE and TCP_KEEPINTVL are in msecs.
Ruslan Ermilov <ru@nginx.com>
parents:
5282
diff
changeset
|
710 value, &ls[i].addr_text); |
4323
c4513d4dd024
Added the "so_keepalive=" parameter to the "listen" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4016
diff
changeset
|
711 } |
c4513d4dd024
Added the "so_keepalive=" parameter to the "listen" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4016
diff
changeset
|
712 } |
c4513d4dd024
Added the "so_keepalive=" parameter to the "listen" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4016
diff
changeset
|
713 |
c4513d4dd024
Added the "so_keepalive=" parameter to the "listen" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4016
diff
changeset
|
714 if (ls[i].keepcnt) { |
c4513d4dd024
Added the "so_keepalive=" parameter to the "listen" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4016
diff
changeset
|
715 if (setsockopt(ls[i].fd, IPPROTO_TCP, TCP_KEEPCNT, |
c4513d4dd024
Added the "so_keepalive=" parameter to the "listen" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4016
diff
changeset
|
716 (const void *) &ls[i].keepcnt, sizeof(int)) |
c4513d4dd024
Added the "so_keepalive=" parameter to the "listen" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4016
diff
changeset
|
717 == -1) |
c4513d4dd024
Added the "so_keepalive=" parameter to the "listen" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4016
diff
changeset
|
718 { |
c4513d4dd024
Added the "so_keepalive=" parameter to the "listen" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4016
diff
changeset
|
719 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_socket_errno, |
c4513d4dd024
Added the "so_keepalive=" parameter to the "listen" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4016
diff
changeset
|
720 "setsockopt(TCP_KEEPCNT, %d) %V failed, ignored", |
c4513d4dd024
Added the "so_keepalive=" parameter to the "listen" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4016
diff
changeset
|
721 ls[i].keepcnt, &ls[i].addr_text); |
c4513d4dd024
Added the "so_keepalive=" parameter to the "listen" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4016
diff
changeset
|
722 } |
c4513d4dd024
Added the "so_keepalive=" parameter to the "listen" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4016
diff
changeset
|
723 } |
c4513d4dd024
Added the "so_keepalive=" parameter to the "listen" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4016
diff
changeset
|
724 |
c4513d4dd024
Added the "so_keepalive=" parameter to the "listen" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4016
diff
changeset
|
725 #endif |
c4513d4dd024
Added the "so_keepalive=" parameter to the "listen" directive.
Valentin Bartenev <vbart@nginx.com>
parents:
4016
diff
changeset
|
726 |
3676 | 727 #if (NGX_HAVE_SETFIB) |
728 if (ls[i].setfib != -1) { | |
729 if (setsockopt(ls[i].fd, SOL_SOCKET, SO_SETFIB, | |
730 (const void *) &ls[i].setfib, sizeof(int)) | |
731 == -1) | |
732 { | |
733 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_socket_errno, | |
734 "setsockopt(SO_SETFIB, %d) %V failed, ignored", | |
735 ls[i].setfib, &ls[i].addr_text); | |
736 } | |
737 } | |
738 #endif | |
739 | |
5456
692afcea9d0d
Added support for TCP_FASTOPEN supported in Linux >= 3.7.1.
Mathew Rodley <mathew@rodley.com.au>
parents:
5431
diff
changeset
|
740 #if (NGX_HAVE_TCP_FASTOPEN) |
692afcea9d0d
Added support for TCP_FASTOPEN supported in Linux >= 3.7.1.
Mathew Rodley <mathew@rodley.com.au>
parents:
5431
diff
changeset
|
741 if (ls[i].fastopen != -1) { |
692afcea9d0d
Added support for TCP_FASTOPEN supported in Linux >= 3.7.1.
Mathew Rodley <mathew@rodley.com.au>
parents:
5431
diff
changeset
|
742 if (setsockopt(ls[i].fd, IPPROTO_TCP, TCP_FASTOPEN, |
692afcea9d0d
Added support for TCP_FASTOPEN supported in Linux >= 3.7.1.
Mathew Rodley <mathew@rodley.com.au>
parents:
5431
diff
changeset
|
743 (const void *) &ls[i].fastopen, sizeof(int)) |
692afcea9d0d
Added support for TCP_FASTOPEN supported in Linux >= 3.7.1.
Mathew Rodley <mathew@rodley.com.au>
parents:
5431
diff
changeset
|
744 == -1) |
692afcea9d0d
Added support for TCP_FASTOPEN supported in Linux >= 3.7.1.
Mathew Rodley <mathew@rodley.com.au>
parents:
5431
diff
changeset
|
745 { |
692afcea9d0d
Added support for TCP_FASTOPEN supported in Linux >= 3.7.1.
Mathew Rodley <mathew@rodley.com.au>
parents:
5431
diff
changeset
|
746 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_socket_errno, |
692afcea9d0d
Added support for TCP_FASTOPEN supported in Linux >= 3.7.1.
Mathew Rodley <mathew@rodley.com.au>
parents:
5431
diff
changeset
|
747 "setsockopt(TCP_FASTOPEN, %d) %V failed, ignored", |
692afcea9d0d
Added support for TCP_FASTOPEN supported in Linux >= 3.7.1.
Mathew Rodley <mathew@rodley.com.au>
parents:
5431
diff
changeset
|
748 ls[i].fastopen, &ls[i].addr_text); |
692afcea9d0d
Added support for TCP_FASTOPEN supported in Linux >= 3.7.1.
Mathew Rodley <mathew@rodley.com.au>
parents:
5431
diff
changeset
|
749 } |
692afcea9d0d
Added support for TCP_FASTOPEN supported in Linux >= 3.7.1.
Mathew Rodley <mathew@rodley.com.au>
parents:
5431
diff
changeset
|
750 } |
692afcea9d0d
Added support for TCP_FASTOPEN supported in Linux >= 3.7.1.
Mathew Rodley <mathew@rodley.com.au>
parents:
5431
diff
changeset
|
751 #endif |
692afcea9d0d
Added support for TCP_FASTOPEN supported in Linux >= 3.7.1.
Mathew Rodley <mathew@rodley.com.au>
parents:
5431
diff
changeset
|
752 |
635 | 753 #if 0 |
754 if (1) { | |
755 int tcp_nodelay = 1; | |
756 | |
757 if (setsockopt(ls[i].fd, IPPROTO_TCP, TCP_NODELAY, | |
758 (const void *) &tcp_nodelay, sizeof(int)) | |
759 == -1) | |
760 { | |
761 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_socket_errno, | |
762 "setsockopt(TCP_NODELAY) %V failed, ignored", | |
763 &ls[i].addr_text); | |
764 } | |
765 } | |
766 #endif | |
767 | |
563 | 768 if (ls[i].listen) { |
1225 | 769 |
770 /* change backlog via listen() */ | |
771 | |
563 | 772 if (listen(ls[i].fd, ls[i].backlog) == -1) { |
773 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_socket_errno, | |
1222 | 774 "listen() to %V, backlog %d failed, ignored", |
775 &ls[i].addr_text, ls[i].backlog); | |
563 | 776 } |
777 } | |
778 | |
779 /* | |
780 * setting deferred mode should be last operation on socket, | |
781 * because code may prematurely continue cycle on failure | |
782 */ | |
783 | |
784 #if (NGX_HAVE_DEFERRED_ACCEPT) | |
785 | |
786 #ifdef SO_ACCEPTFILTER | |
787 | |
627 | 788 if (ls[i].delete_deferred) { |
789 if (setsockopt(ls[i].fd, SOL_SOCKET, SO_ACCEPTFILTER, NULL, 0) | |
790 == -1) | |
563 | 791 { |
5557
188481078faf
Use ngx_socket_errno where appropriate.
Piotr Sikora <piotr@cloudflare.com>
parents:
5550
diff
changeset
|
792 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_socket_errno, |
563 | 793 "setsockopt(SO_ACCEPTFILTER, NULL) " |
794 "for %V failed, ignored", | |
627 | 795 &ls[i].addr_text); |
563 | 796 |
627 | 797 if (ls[i].accept_filter) { |
563 | 798 ngx_log_error(NGX_LOG_ALERT, cycle->log, 0, |
799 "could not change the accept filter " | |
800 "to \"%s\" for %V, ignored", | |
627 | 801 ls[i].accept_filter, &ls[i].addr_text); |
563 | 802 } |
803 | |
804 continue; | |
805 } | |
806 | |
627 | 807 ls[i].deferred_accept = 0; |
563 | 808 } |
809 | |
627 | 810 if (ls[i].add_deferred) { |
563 | 811 ngx_memzero(&af, sizeof(struct accept_filter_arg)); |
812 (void) ngx_cpystrn((u_char *) af.af_name, | |
627 | 813 (u_char *) ls[i].accept_filter, 16); |
563 | 814 |
627 | 815 if (setsockopt(ls[i].fd, SOL_SOCKET, SO_ACCEPTFILTER, |
563 | 816 &af, sizeof(struct accept_filter_arg)) |
817 == -1) | |
818 { | |
5557
188481078faf
Use ngx_socket_errno where appropriate.
Piotr Sikora <piotr@cloudflare.com>
parents:
5550
diff
changeset
|
819 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_socket_errno, |
563 | 820 "setsockopt(SO_ACCEPTFILTER, \"%s\") " |
4016
b044d6553d52
Move SO_ACCEPTFILTER and TCP_DEFER_ACCEPT checks into configure.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3880
diff
changeset
|
821 "for %V failed, ignored", |
627 | 822 ls[i].accept_filter, &ls[i].addr_text); |
563 | 823 continue; |
824 } | |
825 | |
627 | 826 ls[i].deferred_accept = 1; |
563 | 827 } |
828 | |
829 #endif | |
830 | |
831 #ifdef TCP_DEFER_ACCEPT | |
832 | |
627 | 833 if (ls[i].add_deferred || ls[i].delete_deferred) { |
563 | 834 |
627 | 835 if (ls[i].add_deferred) { |
5541
fdb67cfc957d
Fixed TCP_DEFER_ACCEPT handling (ticket #353).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5488
diff
changeset
|
836 /* |
fdb67cfc957d
Fixed TCP_DEFER_ACCEPT handling (ticket #353).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5488
diff
changeset
|
837 * There is no way to find out how long a connection was |
fdb67cfc957d
Fixed TCP_DEFER_ACCEPT handling (ticket #353).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5488
diff
changeset
|
838 * in queue (and a connection may bypass deferred queue at all |
fdb67cfc957d
Fixed TCP_DEFER_ACCEPT handling (ticket #353).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5488
diff
changeset
|
839 * if syncookies were used), hence we use 1 second timeout |
fdb67cfc957d
Fixed TCP_DEFER_ACCEPT handling (ticket #353).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5488
diff
changeset
|
840 * here. |
fdb67cfc957d
Fixed TCP_DEFER_ACCEPT handling (ticket #353).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5488
diff
changeset
|
841 */ |
fdb67cfc957d
Fixed TCP_DEFER_ACCEPT handling (ticket #353).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5488
diff
changeset
|
842 value = 1; |
563 | 843 |
844 } else { | |
5282
31690d934175
Style: reuse one int variable in ngx_configure_listening_sockets().
Ruslan Ermilov <ru@nginx.com>
parents:
5264
diff
changeset
|
845 value = 0; |
563 | 846 } |
847 | |
627 | 848 if (setsockopt(ls[i].fd, IPPROTO_TCP, TCP_DEFER_ACCEPT, |
5282
31690d934175
Style: reuse one int variable in ngx_configure_listening_sockets().
Ruslan Ermilov <ru@nginx.com>
parents:
5264
diff
changeset
|
849 &value, sizeof(int)) |
563 | 850 == -1) |
851 { | |
5557
188481078faf
Use ngx_socket_errno where appropriate.
Piotr Sikora <piotr@cloudflare.com>
parents:
5550
diff
changeset
|
852 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_socket_errno, |
563 | 853 "setsockopt(TCP_DEFER_ACCEPT, %d) for %V failed, " |
854 "ignored", | |
5282
31690d934175
Style: reuse one int variable in ngx_configure_listening_sockets().
Ruslan Ermilov <ru@nginx.com>
parents:
5264
diff
changeset
|
855 value, &ls[i].addr_text); |
563 | 856 |
857 continue; | |
858 } | |
859 } | |
860 | |
627 | 861 if (ls[i].add_deferred) { |
862 ls[i].deferred_accept = 1; | |
563 | 863 } |
864 | |
865 #endif | |
866 | |
867 #endif /* NGX_HAVE_DEFERRED_ACCEPT */ | |
868 } | |
869 | |
870 return; | |
871 } | |
872 | |
873 | |
874 void | |
521 | 875 ngx_close_listening_sockets(ngx_cycle_t *cycle) |
218
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
876 { |
543 | 877 ngx_uint_t i; |
878 ngx_listening_t *ls; | |
879 ngx_connection_t *c; | |
218
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
880 |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
881 if (ngx_event_flags & NGX_USE_IOCP_EVENT) { |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
882 return; |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
883 } |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
884 |
303
00c5660d2707
nginx-0.0.3-2004-04-01-20:20:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
885 ngx_accept_mutex_held = 0; |
611 | 886 ngx_use_accept_mutex = 0; |
303
00c5660d2707
nginx-0.0.3-2004-04-01-20:20:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
887 |
218
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
888 ls = cycle->listening.elts; |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
889 for (i = 0; i < cycle->listening.nelts; i++) { |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
890 |
543 | 891 c = ls[i].connection; |
218
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
892 |
2725 | 893 if (c) { |
894 if (c->read->active) { | |
6126
adba26ff70b5
Removed the obsolete rtsig module.
Ruslan Ermilov <ru@nginx.com>
parents:
6125
diff
changeset
|
895 if (ngx_event_flags & NGX_USE_EPOLL_EVENT) { |
317
1308b98496a2
nginx-0.0.3-2004-04-15-19:34:36 import
Igor Sysoev <igor@sysoev.ru>
parents:
303
diff
changeset
|
896 |
2725 | 897 /* |
898 * it seems that Linux-2.6.x OpenVZ sends events | |
899 * for closed shared listening sockets unless | |
4572
67653855682e
Fixed spelling in multiline C comments.
Ruslan Ermilov <ru@nginx.com>
parents:
4522
diff
changeset
|
900 * the events was explicitly deleted |
2725 | 901 */ |
1833
86464f8eddd6
workaround for Linux 2.6 OpenVZ
Igor Sysoev <igor@sysoev.ru>
parents:
1435
diff
changeset
|
902 |
2725 | 903 ngx_del_event(c->read, NGX_READ_EVENT, 0); |
1833
86464f8eddd6
workaround for Linux 2.6 OpenVZ
Igor Sysoev <igor@sysoev.ru>
parents:
1435
diff
changeset
|
904 |
2725 | 905 } else { |
906 ngx_del_event(c->read, NGX_READ_EVENT, NGX_CLOSE_EVENT); | |
907 } | |
317
1308b98496a2
nginx-0.0.3-2004-04-15-19:34:36 import
Igor Sysoev <igor@sysoev.ru>
parents:
303
diff
changeset
|
908 } |
2725 | 909 |
910 ngx_free_connection(c); | |
911 | |
912 c->fd = (ngx_socket_t) -1; | |
317
1308b98496a2
nginx-0.0.3-2004-04-15-19:34:36 import
Igor Sysoev <igor@sysoev.ru>
parents:
303
diff
changeset
|
913 } |
218
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
914 |
563 | 915 ngx_log_debug2(NGX_LOG_DEBUG_CORE, cycle->log, 0, |
916 "close listening %V #%d ", &ls[i].addr_text, ls[i].fd); | |
917 | |
543 | 918 if (ngx_close_socket(ls[i].fd) == -1) { |
218
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
919 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_socket_errno, |
461 | 920 ngx_close_socket_n " %V failed", &ls[i].addr_text); |
218
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
921 } |
2928 | 922 |
3230
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
3151
diff
changeset
|
923 #if (NGX_HAVE_UNIX_DOMAIN) |
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
3151
diff
changeset
|
924 |
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
3151
diff
changeset
|
925 if (ls[i].sockaddr->sa_family == AF_UNIX |
3358
f94e8ff65aa2
add NGX_PROCESS_HELPER process status
Igor Sysoev <igor@sysoev.ru>
parents:
3292
diff
changeset
|
926 && ngx_process <= NGX_PROCESS_MASTER |
3261
35077c22326c
do not unlink unix domain socket file while online upgrade
Igor Sysoev <igor@sysoev.ru>
parents:
3260
diff
changeset
|
927 && ngx_new_binary == 0) |
3230
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
3151
diff
changeset
|
928 { |
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
3151
diff
changeset
|
929 u_char *name = ls[i].addr_text.data + sizeof("unix:") - 1; |
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
3151
diff
changeset
|
930 |
5137
f941cf265cc5
Use NGX_FILE_ERROR for handling file operations errors.
Valentin Bartenev <vbart@nginx.com>
parents:
5115
diff
changeset
|
931 if (ngx_delete_file(name) == NGX_FILE_ERROR) { |
3230
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
3151
diff
changeset
|
932 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_socket_errno, |
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
3151
diff
changeset
|
933 ngx_delete_file_n " %s failed", name); |
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
3151
diff
changeset
|
934 } |
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
3151
diff
changeset
|
935 } |
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
3151
diff
changeset
|
936 |
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
3151
diff
changeset
|
937 #endif |
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
3151
diff
changeset
|
938 |
2928 | 939 ls[i].fd = (ngx_socket_t) -1; |
543 | 940 } |
4917
484aec758d2c
Fixed failure to start cache manager and cache loader processes
Igor Sysoev <igor@sysoev.ru>
parents:
4771
diff
changeset
|
941 |
484aec758d2c
Fixed failure to start cache manager and cache loader processes
Igor Sysoev <igor@sysoev.ru>
parents:
4771
diff
changeset
|
942 cycle->listening.nelts = 0; |
543 | 943 } |
218
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
944 |
543 | 945 |
946 ngx_connection_t * | |
947 ngx_get_connection(ngx_socket_t s, ngx_log_t *log) | |
948 { | |
561 | 949 ngx_uint_t instance; |
950 ngx_event_t *rev, *wev; | |
951 ngx_connection_t *c; | |
543 | 952 |
953 /* disable warning: Win32 SOCKET is u_int while UNIX socket is int */ | |
954 | |
955 if (ngx_cycle->files && (ngx_uint_t) s >= ngx_cycle->files_n) { | |
956 ngx_log_error(NGX_LOG_ALERT, log, 0, | |
957 "the new socket has number %d, " | |
958 "but only %ui files are available", | |
959 s, ngx_cycle->files_n); | |
960 return NULL; | |
961 } | |
962 | |
963 c = ngx_cycle->free_connections; | |
964 | |
965 if (c == NULL) { | |
3880
e3cb8e27e413
reuse keepalive connections if there are no free worker connections
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
966 ngx_drain_connections(); |
e3cb8e27e413
reuse keepalive connections if there are no free worker connections
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
967 c = ngx_cycle->free_connections; |
e3cb8e27e413
reuse keepalive connections if there are no free worker connections
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
968 } |
e3cb8e27e413
reuse keepalive connections if there are no free worker connections
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
969 |
e3cb8e27e413
reuse keepalive connections if there are no free worker connections
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
970 if (c == NULL) { |
543 | 971 ngx_log_error(NGX_LOG_ALERT, log, 0, |
2254 | 972 "%ui worker_connections are not enough", |
543 | 973 ngx_cycle->connection_n); |
974 | |
975 return NULL; | |
976 } | |
977 | |
978 ngx_cycle->free_connections = c->data; | |
979 ngx_cycle->free_connection_n--; | |
980 | |
981 if (ngx_cycle->files) { | |
982 ngx_cycle->files[s] = c; | |
983 } | |
984 | |
561 | 985 rev = c->read; |
986 wev = c->write; | |
987 | |
988 ngx_memzero(c, sizeof(ngx_connection_t)); | |
989 | |
990 c->read = rev; | |
991 c->write = wev; | |
992 c->fd = s; | |
993 c->log = log; | |
994 | |
995 instance = rev->instance; | |
996 | |
997 ngx_memzero(rev, sizeof(ngx_event_t)); | |
998 ngx_memzero(wev, sizeof(ngx_event_t)); | |
999 | |
1000 rev->instance = !instance; | |
1001 wev->instance = !instance; | |
1002 | |
1003 rev->index = NGX_INVALID_INDEX; | |
1004 wev->index = NGX_INVALID_INDEX; | |
1005 | |
1006 rev->data = c; | |
1007 wev->data = c; | |
1008 | |
1009 wev->write = 1; | |
1010 | |
543 | 1011 return c; |
1012 } | |
1013 | |
1014 | |
1015 void | |
1016 ngx_free_connection(ngx_connection_t *c) | |
1017 { | |
1018 c->data = ngx_cycle->free_connections; | |
1019 ngx_cycle->free_connections = c; | |
1020 ngx_cycle->free_connection_n++; | |
1021 | |
1022 if (ngx_cycle->files) { | |
1023 ngx_cycle->files[c->fd] = NULL; | |
218
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1024 } |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1025 } |
253
b6793bc5034b
nginx-0.0.2-2004-02-09-10:46:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
242
diff
changeset
|
1026 |
b6793bc5034b
nginx-0.0.2-2004-02-09-10:46:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
242
diff
changeset
|
1027 |
521 | 1028 void |
1029 ngx_close_connection(ngx_connection_t *c) | |
417
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
346
diff
changeset
|
1030 { |
1917
1b2e83c4886d
decrease log level of connection errors while closing socket
Igor Sysoev <igor@sysoev.ru>
parents:
1869
diff
changeset
|
1031 ngx_err_t err; |
1b2e83c4886d
decrease log level of connection errors while closing socket
Igor Sysoev <igor@sysoev.ru>
parents:
1869
diff
changeset
|
1032 ngx_uint_t log_error, level; |
417
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
346
diff
changeset
|
1033 ngx_socket_t fd; |
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
346
diff
changeset
|
1034 |
5360
3d2d3e1cf427
Win32: MinGW GCC compatibility.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5283
diff
changeset
|
1035 if (c->fd == (ngx_socket_t) -1) { |
417
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
346
diff
changeset
|
1036 ngx_log_error(NGX_LOG_ALERT, c->log, 0, "connection already closed"); |
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
346
diff
changeset
|
1037 return; |
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
346
diff
changeset
|
1038 } |
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
346
diff
changeset
|
1039 |
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
346
diff
changeset
|
1040 if (c->read->timer_set) { |
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
346
diff
changeset
|
1041 ngx_del_timer(c->read); |
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
346
diff
changeset
|
1042 } |
577 | 1043 |
417
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
346
diff
changeset
|
1044 if (c->write->timer_set) { |
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
346
diff
changeset
|
1045 ngx_del_timer(c->write); |
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
346
diff
changeset
|
1046 } |
577 | 1047 |
417
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
346
diff
changeset
|
1048 if (ngx_del_conn) { |
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
346
diff
changeset
|
1049 ngx_del_conn(c, NGX_CLOSE_EVENT); |
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
346
diff
changeset
|
1050 |
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
346
diff
changeset
|
1051 } else { |
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
346
diff
changeset
|
1052 if (c->read->active || c->read->disabled) { |
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
346
diff
changeset
|
1053 ngx_del_event(c->read, NGX_READ_EVENT, NGX_CLOSE_EVENT); |
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
346
diff
changeset
|
1054 } |
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
346
diff
changeset
|
1055 |
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
346
diff
changeset
|
1056 if (c->write->active || c->write->disabled) { |
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
346
diff
changeset
|
1057 ngx_del_event(c->write, NGX_WRITE_EVENT, NGX_CLOSE_EVENT); |
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
346
diff
changeset
|
1058 } |
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
346
diff
changeset
|
1059 } |
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
346
diff
changeset
|
1060 |
5821
3f5f0ab59b35
Events: processing of posted events changed from LIFO to FIFO.
Valentin Bartenev <vbart@nginx.com>
parents:
5820
diff
changeset
|
1061 if (c->read->posted) { |
563 | 1062 ngx_delete_posted_event(c->read); |
1063 } | |
417
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
346
diff
changeset
|
1064 |
5821
3f5f0ab59b35
Events: processing of posted events changed from LIFO to FIFO.
Valentin Bartenev <vbart@nginx.com>
parents:
5820
diff
changeset
|
1065 if (c->write->posted) { |
563 | 1066 ngx_delete_posted_event(c->write); |
1067 } | |
417
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
346
diff
changeset
|
1068 |
563 | 1069 c->read->closed = 1; |
1070 c->write->closed = 1; | |
417
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
346
diff
changeset
|
1071 |
3880
e3cb8e27e413
reuse keepalive connections if there are no free worker connections
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
1072 ngx_reusable_connection(c, 0); |
e3cb8e27e413
reuse keepalive connections if there are no free worker connections
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
1073 |
1917
1b2e83c4886d
decrease log level of connection errors while closing socket
Igor Sysoev <igor@sysoev.ru>
parents:
1869
diff
changeset
|
1074 log_error = c->log_error; |
1b2e83c4886d
decrease log level of connection errors while closing socket
Igor Sysoev <igor@sysoev.ru>
parents:
1869
diff
changeset
|
1075 |
543 | 1076 ngx_free_connection(c); |
1077 | |
417
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
346
diff
changeset
|
1078 fd = c->fd; |
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
346
diff
changeset
|
1079 c->fd = (ngx_socket_t) -1; |
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
346
diff
changeset
|
1080 |
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
346
diff
changeset
|
1081 if (ngx_close_socket(fd) == -1) { |
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
346
diff
changeset
|
1082 |
1917
1b2e83c4886d
decrease log level of connection errors while closing socket
Igor Sysoev <igor@sysoev.ru>
parents:
1869
diff
changeset
|
1083 err = ngx_socket_errno; |
1b2e83c4886d
decrease log level of connection errors while closing socket
Igor Sysoev <igor@sysoev.ru>
parents:
1869
diff
changeset
|
1084 |
1b2e83c4886d
decrease log level of connection errors while closing socket
Igor Sysoev <igor@sysoev.ru>
parents:
1869
diff
changeset
|
1085 if (err == NGX_ECONNRESET || err == NGX_ENOTCONN) { |
1b2e83c4886d
decrease log level of connection errors while closing socket
Igor Sysoev <igor@sysoev.ru>
parents:
1869
diff
changeset
|
1086 |
1b2e83c4886d
decrease log level of connection errors while closing socket
Igor Sysoev <igor@sysoev.ru>
parents:
1869
diff
changeset
|
1087 switch (log_error) { |
1b2e83c4886d
decrease log level of connection errors while closing socket
Igor Sysoev <igor@sysoev.ru>
parents:
1869
diff
changeset
|
1088 |
1b2e83c4886d
decrease log level of connection errors while closing socket
Igor Sysoev <igor@sysoev.ru>
parents:
1869
diff
changeset
|
1089 case NGX_ERROR_INFO: |
1b2e83c4886d
decrease log level of connection errors while closing socket
Igor Sysoev <igor@sysoev.ru>
parents:
1869
diff
changeset
|
1090 level = NGX_LOG_INFO; |
1b2e83c4886d
decrease log level of connection errors while closing socket
Igor Sysoev <igor@sysoev.ru>
parents:
1869
diff
changeset
|
1091 break; |
1b2e83c4886d
decrease log level of connection errors while closing socket
Igor Sysoev <igor@sysoev.ru>
parents:
1869
diff
changeset
|
1092 |
1b2e83c4886d
decrease log level of connection errors while closing socket
Igor Sysoev <igor@sysoev.ru>
parents:
1869
diff
changeset
|
1093 case NGX_ERROR_ERR: |
1b2e83c4886d
decrease log level of connection errors while closing socket
Igor Sysoev <igor@sysoev.ru>
parents:
1869
diff
changeset
|
1094 level = NGX_LOG_ERR; |
1b2e83c4886d
decrease log level of connection errors while closing socket
Igor Sysoev <igor@sysoev.ru>
parents:
1869
diff
changeset
|
1095 break; |
1b2e83c4886d
decrease log level of connection errors while closing socket
Igor Sysoev <igor@sysoev.ru>
parents:
1869
diff
changeset
|
1096 |
1b2e83c4886d
decrease log level of connection errors while closing socket
Igor Sysoev <igor@sysoev.ru>
parents:
1869
diff
changeset
|
1097 default: |
1b2e83c4886d
decrease log level of connection errors while closing socket
Igor Sysoev <igor@sysoev.ru>
parents:
1869
diff
changeset
|
1098 level = NGX_LOG_CRIT; |
1b2e83c4886d
decrease log level of connection errors while closing socket
Igor Sysoev <igor@sysoev.ru>
parents:
1869
diff
changeset
|
1099 } |
1b2e83c4886d
decrease log level of connection errors while closing socket
Igor Sysoev <igor@sysoev.ru>
parents:
1869
diff
changeset
|
1100 |
1b2e83c4886d
decrease log level of connection errors while closing socket
Igor Sysoev <igor@sysoev.ru>
parents:
1869
diff
changeset
|
1101 } else { |
1b2e83c4886d
decrease log level of connection errors while closing socket
Igor Sysoev <igor@sysoev.ru>
parents:
1869
diff
changeset
|
1102 level = NGX_LOG_CRIT; |
1b2e83c4886d
decrease log level of connection errors while closing socket
Igor Sysoev <igor@sysoev.ru>
parents:
1869
diff
changeset
|
1103 } |
1b2e83c4886d
decrease log level of connection errors while closing socket
Igor Sysoev <igor@sysoev.ru>
parents:
1869
diff
changeset
|
1104 |
417
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
346
diff
changeset
|
1105 /* we use ngx_cycle->log because c->log was in c->pool */ |
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
346
diff
changeset
|
1106 |
1917
1b2e83c4886d
decrease log level of connection errors while closing socket
Igor Sysoev <igor@sysoev.ru>
parents:
1869
diff
changeset
|
1107 ngx_log_error(level, ngx_cycle->log, err, |
1435 | 1108 ngx_close_socket_n " %d failed", fd); |
417
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
346
diff
changeset
|
1109 } |
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
346
diff
changeset
|
1110 } |
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
346
diff
changeset
|
1111 |
0526206251f6
nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
346
diff
changeset
|
1112 |
3880
e3cb8e27e413
reuse keepalive connections if there are no free worker connections
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
1113 void |
e3cb8e27e413
reuse keepalive connections if there are no free worker connections
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
1114 ngx_reusable_connection(ngx_connection_t *c, ngx_uint_t reusable) |
e3cb8e27e413
reuse keepalive connections if there are no free worker connections
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
1115 { |
e3cb8e27e413
reuse keepalive connections if there are no free worker connections
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
1116 ngx_log_debug1(NGX_LOG_DEBUG_CORE, c->log, 0, |
e3cb8e27e413
reuse keepalive connections if there are no free worker connections
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
1117 "reusable connection: %ui", reusable); |
e3cb8e27e413
reuse keepalive connections if there are no free worker connections
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
1118 |
e3cb8e27e413
reuse keepalive connections if there are no free worker connections
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
1119 if (c->reusable) { |
e3cb8e27e413
reuse keepalive connections if there are no free worker connections
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
1120 ngx_queue_remove(&c->queue); |
5115
a29c574d61fa
Status: introduced the "ngx_stat_waiting" counter.
Valentin Bartenev <vbart@nginx.com>
parents:
5104
diff
changeset
|
1121 |
a29c574d61fa
Status: introduced the "ngx_stat_waiting" counter.
Valentin Bartenev <vbart@nginx.com>
parents:
5104
diff
changeset
|
1122 #if (NGX_STAT_STUB) |
a29c574d61fa
Status: introduced the "ngx_stat_waiting" counter.
Valentin Bartenev <vbart@nginx.com>
parents:
5104
diff
changeset
|
1123 (void) ngx_atomic_fetch_add(ngx_stat_waiting, -1); |
a29c574d61fa
Status: introduced the "ngx_stat_waiting" counter.
Valentin Bartenev <vbart@nginx.com>
parents:
5104
diff
changeset
|
1124 #endif |
3880
e3cb8e27e413
reuse keepalive connections if there are no free worker connections
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
1125 } |
e3cb8e27e413
reuse keepalive connections if there are no free worker connections
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
1126 |
e3cb8e27e413
reuse keepalive connections if there are no free worker connections
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
1127 c->reusable = reusable; |
e3cb8e27e413
reuse keepalive connections if there are no free worker connections
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
1128 |
e3cb8e27e413
reuse keepalive connections if there are no free worker connections
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
1129 if (reusable) { |
e3cb8e27e413
reuse keepalive connections if there are no free worker connections
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
1130 /* need cast as ngx_cycle is volatile */ |
e3cb8e27e413
reuse keepalive connections if there are no free worker connections
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
1131 |
e3cb8e27e413
reuse keepalive connections if there are no free worker connections
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
1132 ngx_queue_insert_head( |
e3cb8e27e413
reuse keepalive connections if there are no free worker connections
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
1133 (ngx_queue_t *) &ngx_cycle->reusable_connections_queue, &c->queue); |
5115
a29c574d61fa
Status: introduced the "ngx_stat_waiting" counter.
Valentin Bartenev <vbart@nginx.com>
parents:
5104
diff
changeset
|
1134 |
a29c574d61fa
Status: introduced the "ngx_stat_waiting" counter.
Valentin Bartenev <vbart@nginx.com>
parents:
5104
diff
changeset
|
1135 #if (NGX_STAT_STUB) |
a29c574d61fa
Status: introduced the "ngx_stat_waiting" counter.
Valentin Bartenev <vbart@nginx.com>
parents:
5104
diff
changeset
|
1136 (void) ngx_atomic_fetch_add(ngx_stat_waiting, 1); |
a29c574d61fa
Status: introduced the "ngx_stat_waiting" counter.
Valentin Bartenev <vbart@nginx.com>
parents:
5104
diff
changeset
|
1137 #endif |
3880
e3cb8e27e413
reuse keepalive connections if there are no free worker connections
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
1138 } |
e3cb8e27e413
reuse keepalive connections if there are no free worker connections
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
1139 } |
e3cb8e27e413
reuse keepalive connections if there are no free worker connections
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
1140 |
e3cb8e27e413
reuse keepalive connections if there are no free worker connections
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
1141 |
e3cb8e27e413
reuse keepalive connections if there are no free worker connections
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
1142 static void |
e3cb8e27e413
reuse keepalive connections if there are no free worker connections
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
1143 ngx_drain_connections(void) |
e3cb8e27e413
reuse keepalive connections if there are no free worker connections
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
1144 { |
e3cb8e27e413
reuse keepalive connections if there are no free worker connections
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
1145 ngx_int_t i; |
e3cb8e27e413
reuse keepalive connections if there are no free worker connections
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
1146 ngx_queue_t *q; |
e3cb8e27e413
reuse keepalive connections if there are no free worker connections
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
1147 ngx_connection_t *c; |
e3cb8e27e413
reuse keepalive connections if there are no free worker connections
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
1148 |
e3cb8e27e413
reuse keepalive connections if there are no free worker connections
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
1149 for (i = 0; i < 32; i++) { |
e3cb8e27e413
reuse keepalive connections if there are no free worker connections
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
1150 if (ngx_queue_empty(&ngx_cycle->reusable_connections_queue)) { |
e3cb8e27e413
reuse keepalive connections if there are no free worker connections
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
1151 break; |
e3cb8e27e413
reuse keepalive connections if there are no free worker connections
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
1152 } |
e3cb8e27e413
reuse keepalive connections if there are no free worker connections
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
1153 |
e3cb8e27e413
reuse keepalive connections if there are no free worker connections
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
1154 q = ngx_queue_last(&ngx_cycle->reusable_connections_queue); |
e3cb8e27e413
reuse keepalive connections if there are no free worker connections
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
1155 c = ngx_queue_data(q, ngx_connection_t, queue); |
e3cb8e27e413
reuse keepalive connections if there are no free worker connections
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
1156 |
e3cb8e27e413
reuse keepalive connections if there are no free worker connections
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
1157 ngx_log_debug0(NGX_LOG_DEBUG_CORE, c->log, 0, |
e3cb8e27e413
reuse keepalive connections if there are no free worker connections
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
1158 "reusing connection"); |
e3cb8e27e413
reuse keepalive connections if there are no free worker connections
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
1159 |
e3cb8e27e413
reuse keepalive connections if there are no free worker connections
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
1160 c->close = 1; |
e3cb8e27e413
reuse keepalive connections if there are no free worker connections
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
1161 c->read->handler(c->read); |
e3cb8e27e413
reuse keepalive connections if there are no free worker connections
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
1162 } |
e3cb8e27e413
reuse keepalive connections if there are no free worker connections
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
1163 } |
e3cb8e27e413
reuse keepalive connections if there are no free worker connections
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
1164 |
e3cb8e27e413
reuse keepalive connections if there are no free worker connections
Igor Sysoev <igor@sysoev.ru>
parents:
3676
diff
changeset
|
1165 |
6220
5e6142609e48
Core: idle connections now closed only once on exiting.
Valentin Bartenev <vbart@nginx.com>
parents:
6218
diff
changeset
|
1166 void |
5e6142609e48
Core: idle connections now closed only once on exiting.
Valentin Bartenev <vbart@nginx.com>
parents:
6218
diff
changeset
|
1167 ngx_close_idle_connections(ngx_cycle_t *cycle) |
5e6142609e48
Core: idle connections now closed only once on exiting.
Valentin Bartenev <vbart@nginx.com>
parents:
6218
diff
changeset
|
1168 { |
5e6142609e48
Core: idle connections now closed only once on exiting.
Valentin Bartenev <vbart@nginx.com>
parents:
6218
diff
changeset
|
1169 ngx_uint_t i; |
5e6142609e48
Core: idle connections now closed only once on exiting.
Valentin Bartenev <vbart@nginx.com>
parents:
6218
diff
changeset
|
1170 ngx_connection_t *c; |
5e6142609e48
Core: idle connections now closed only once on exiting.
Valentin Bartenev <vbart@nginx.com>
parents:
6218
diff
changeset
|
1171 |
5e6142609e48
Core: idle connections now closed only once on exiting.
Valentin Bartenev <vbart@nginx.com>
parents:
6218
diff
changeset
|
1172 c = cycle->connections; |
5e6142609e48
Core: idle connections now closed only once on exiting.
Valentin Bartenev <vbart@nginx.com>
parents:
6218
diff
changeset
|
1173 |
5e6142609e48
Core: idle connections now closed only once on exiting.
Valentin Bartenev <vbart@nginx.com>
parents:
6218
diff
changeset
|
1174 for (i = 0; i < cycle->connection_n; i++) { |
5e6142609e48
Core: idle connections now closed only once on exiting.
Valentin Bartenev <vbart@nginx.com>
parents:
6218
diff
changeset
|
1175 |
5e6142609e48
Core: idle connections now closed only once on exiting.
Valentin Bartenev <vbart@nginx.com>
parents:
6218
diff
changeset
|
1176 /* THREAD: lock */ |
5e6142609e48
Core: idle connections now closed only once on exiting.
Valentin Bartenev <vbart@nginx.com>
parents:
6218
diff
changeset
|
1177 |
5e6142609e48
Core: idle connections now closed only once on exiting.
Valentin Bartenev <vbart@nginx.com>
parents:
6218
diff
changeset
|
1178 if (c[i].fd != -1 && c[i].idle) { |
5e6142609e48
Core: idle connections now closed only once on exiting.
Valentin Bartenev <vbart@nginx.com>
parents:
6218
diff
changeset
|
1179 c[i].close = 1; |
5e6142609e48
Core: idle connections now closed only once on exiting.
Valentin Bartenev <vbart@nginx.com>
parents:
6218
diff
changeset
|
1180 c[i].read->handler(c[i].read); |
5e6142609e48
Core: idle connections now closed only once on exiting.
Valentin Bartenev <vbart@nginx.com>
parents:
6218
diff
changeset
|
1181 } |
5e6142609e48
Core: idle connections now closed only once on exiting.
Valentin Bartenev <vbart@nginx.com>
parents:
6218
diff
changeset
|
1182 } |
5e6142609e48
Core: idle connections now closed only once on exiting.
Valentin Bartenev <vbart@nginx.com>
parents:
6218
diff
changeset
|
1183 } |
5e6142609e48
Core: idle connections now closed only once on exiting.
Valentin Bartenev <vbart@nginx.com>
parents:
6218
diff
changeset
|
1184 |
5e6142609e48
Core: idle connections now closed only once on exiting.
Valentin Bartenev <vbart@nginx.com>
parents:
6218
diff
changeset
|
1185 |
521 | 1186 ngx_int_t |
2854
d788477f5a67
ngx_connection_local_sockaddr()
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
1187 ngx_connection_local_sockaddr(ngx_connection_t *c, ngx_str_t *s, |
d788477f5a67
ngx_connection_local_sockaddr()
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
1188 ngx_uint_t port) |
d788477f5a67
ngx_connection_local_sockaddr()
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
1189 { |
d788477f5a67
ngx_connection_local_sockaddr()
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
1190 socklen_t len; |
d788477f5a67
ngx_connection_local_sockaddr()
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
1191 ngx_uint_t addr; |
d788477f5a67
ngx_connection_local_sockaddr()
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
1192 u_char sa[NGX_SOCKADDRLEN]; |
d788477f5a67
ngx_connection_local_sockaddr()
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
1193 struct sockaddr_in *sin; |
d788477f5a67
ngx_connection_local_sockaddr()
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
1194 #if (NGX_HAVE_INET6) |
d788477f5a67
ngx_connection_local_sockaddr()
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
1195 ngx_uint_t i; |
d788477f5a67
ngx_connection_local_sockaddr()
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
1196 struct sockaddr_in6 *sin6; |
d788477f5a67
ngx_connection_local_sockaddr()
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
1197 #endif |
d788477f5a67
ngx_connection_local_sockaddr()
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
1198 |
5983
69c4912066a4
Core: make ngx_connection_local_sockaddr() always assign address.
Roman Arutyunyan <arut@nginx.com>
parents:
5821
diff
changeset
|
1199 addr = 0; |
5463
1ab1cf63f885
Core: keep the length of the local sockaddr.
Ruslan Ermilov <ru@nginx.com>
parents:
5456
diff
changeset
|
1200 |
5983
69c4912066a4
Core: make ngx_connection_local_sockaddr() always assign address.
Roman Arutyunyan <arut@nginx.com>
parents:
5821
diff
changeset
|
1201 if (c->local_socklen) { |
69c4912066a4
Core: make ngx_connection_local_sockaddr() always assign address.
Roman Arutyunyan <arut@nginx.com>
parents:
5821
diff
changeset
|
1202 switch (c->local_sockaddr->sa_family) { |
2854
d788477f5a67
ngx_connection_local_sockaddr()
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
1203 |
d788477f5a67
ngx_connection_local_sockaddr()
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
1204 #if (NGX_HAVE_INET6) |
5983
69c4912066a4
Core: make ngx_connection_local_sockaddr() always assign address.
Roman Arutyunyan <arut@nginx.com>
parents:
5821
diff
changeset
|
1205 case AF_INET6: |
69c4912066a4
Core: make ngx_connection_local_sockaddr() always assign address.
Roman Arutyunyan <arut@nginx.com>
parents:
5821
diff
changeset
|
1206 sin6 = (struct sockaddr_in6 *) c->local_sockaddr; |
2854
d788477f5a67
ngx_connection_local_sockaddr()
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
1207 |
5983
69c4912066a4
Core: make ngx_connection_local_sockaddr() always assign address.
Roman Arutyunyan <arut@nginx.com>
parents:
5821
diff
changeset
|
1208 for (i = 0; addr == 0 && i < 16; i++) { |
69c4912066a4
Core: make ngx_connection_local_sockaddr() always assign address.
Roman Arutyunyan <arut@nginx.com>
parents:
5821
diff
changeset
|
1209 addr |= sin6->sin6_addr.s6_addr[i]; |
69c4912066a4
Core: make ngx_connection_local_sockaddr() always assign address.
Roman Arutyunyan <arut@nginx.com>
parents:
5821
diff
changeset
|
1210 } |
2854
d788477f5a67
ngx_connection_local_sockaddr()
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
1211 |
5983
69c4912066a4
Core: make ngx_connection_local_sockaddr() always assign address.
Roman Arutyunyan <arut@nginx.com>
parents:
5821
diff
changeset
|
1212 break; |
2854
d788477f5a67
ngx_connection_local_sockaddr()
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
1213 #endif |
d788477f5a67
ngx_connection_local_sockaddr()
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
1214 |
5464
30e806b8636a
Fixed handling of UNIX-domain sockets.
Ruslan Ermilov <ru@nginx.com>
parents:
5463
diff
changeset
|
1215 #if (NGX_HAVE_UNIX_DOMAIN) |
5983
69c4912066a4
Core: make ngx_connection_local_sockaddr() always assign address.
Roman Arutyunyan <arut@nginx.com>
parents:
5821
diff
changeset
|
1216 case AF_UNIX: |
69c4912066a4
Core: make ngx_connection_local_sockaddr() always assign address.
Roman Arutyunyan <arut@nginx.com>
parents:
5821
diff
changeset
|
1217 addr = 1; |
69c4912066a4
Core: make ngx_connection_local_sockaddr() always assign address.
Roman Arutyunyan <arut@nginx.com>
parents:
5821
diff
changeset
|
1218 break; |
5464
30e806b8636a
Fixed handling of UNIX-domain sockets.
Ruslan Ermilov <ru@nginx.com>
parents:
5463
diff
changeset
|
1219 #endif |
30e806b8636a
Fixed handling of UNIX-domain sockets.
Ruslan Ermilov <ru@nginx.com>
parents:
5463
diff
changeset
|
1220 |
5983
69c4912066a4
Core: make ngx_connection_local_sockaddr() always assign address.
Roman Arutyunyan <arut@nginx.com>
parents:
5821
diff
changeset
|
1221 default: /* AF_INET */ |
69c4912066a4
Core: make ngx_connection_local_sockaddr() always assign address.
Roman Arutyunyan <arut@nginx.com>
parents:
5821
diff
changeset
|
1222 sin = (struct sockaddr_in *) c->local_sockaddr; |
69c4912066a4
Core: make ngx_connection_local_sockaddr() always assign address.
Roman Arutyunyan <arut@nginx.com>
parents:
5821
diff
changeset
|
1223 addr = sin->sin_addr.s_addr; |
69c4912066a4
Core: make ngx_connection_local_sockaddr() always assign address.
Roman Arutyunyan <arut@nginx.com>
parents:
5821
diff
changeset
|
1224 break; |
69c4912066a4
Core: make ngx_connection_local_sockaddr() always assign address.
Roman Arutyunyan <arut@nginx.com>
parents:
5821
diff
changeset
|
1225 } |
2854
d788477f5a67
ngx_connection_local_sockaddr()
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
1226 } |
d788477f5a67
ngx_connection_local_sockaddr()
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
1227 |
d788477f5a67
ngx_connection_local_sockaddr()
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
1228 if (addr == 0) { |
d788477f5a67
ngx_connection_local_sockaddr()
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
1229 |
d788477f5a67
ngx_connection_local_sockaddr()
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
1230 len = NGX_SOCKADDRLEN; |
d788477f5a67
ngx_connection_local_sockaddr()
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
1231 |
d788477f5a67
ngx_connection_local_sockaddr()
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
1232 if (getsockname(c->fd, (struct sockaddr *) &sa, &len) == -1) { |
d788477f5a67
ngx_connection_local_sockaddr()
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
1233 ngx_connection_error(c, ngx_socket_errno, "getsockname() failed"); |
d788477f5a67
ngx_connection_local_sockaddr()
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
1234 return NGX_ERROR; |
d788477f5a67
ngx_connection_local_sockaddr()
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
1235 } |
d788477f5a67
ngx_connection_local_sockaddr()
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
1236 |
d788477f5a67
ngx_connection_local_sockaddr()
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
1237 c->local_sockaddr = ngx_palloc(c->pool, len); |
d788477f5a67
ngx_connection_local_sockaddr()
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
1238 if (c->local_sockaddr == NULL) { |
d788477f5a67
ngx_connection_local_sockaddr()
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
1239 return NGX_ERROR; |
d788477f5a67
ngx_connection_local_sockaddr()
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
1240 } |
d788477f5a67
ngx_connection_local_sockaddr()
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
1241 |
d788477f5a67
ngx_connection_local_sockaddr()
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
1242 ngx_memcpy(c->local_sockaddr, &sa, len); |
5463
1ab1cf63f885
Core: keep the length of the local sockaddr.
Ruslan Ermilov <ru@nginx.com>
parents:
5456
diff
changeset
|
1243 |
1ab1cf63f885
Core: keep the length of the local sockaddr.
Ruslan Ermilov <ru@nginx.com>
parents:
5456
diff
changeset
|
1244 c->local_socklen = len; |
2854
d788477f5a67
ngx_connection_local_sockaddr()
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
1245 } |
d788477f5a67
ngx_connection_local_sockaddr()
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
1246 |
d788477f5a67
ngx_connection_local_sockaddr()
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
1247 if (s == NULL) { |
d788477f5a67
ngx_connection_local_sockaddr()
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
1248 return NGX_OK; |
d788477f5a67
ngx_connection_local_sockaddr()
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
1249 } |
d788477f5a67
ngx_connection_local_sockaddr()
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
1250 |
5463
1ab1cf63f885
Core: keep the length of the local sockaddr.
Ruslan Ermilov <ru@nginx.com>
parents:
5456
diff
changeset
|
1251 s->len = ngx_sock_ntop(c->local_sockaddr, c->local_socklen, |
1ab1cf63f885
Core: keep the length of the local sockaddr.
Ruslan Ermilov <ru@nginx.com>
parents:
5456
diff
changeset
|
1252 s->data, s->len, port); |
2854
d788477f5a67
ngx_connection_local_sockaddr()
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
1253 |
d788477f5a67
ngx_connection_local_sockaddr()
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
1254 return NGX_OK; |
d788477f5a67
ngx_connection_local_sockaddr()
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
1255 } |
d788477f5a67
ngx_connection_local_sockaddr()
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
1256 |
d788477f5a67
ngx_connection_local_sockaddr()
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
1257 |
d788477f5a67
ngx_connection_local_sockaddr()
Igor Sysoev <igor@sysoev.ru>
parents:
2806
diff
changeset
|
1258 ngx_int_t |
521 | 1259 ngx_connection_error(ngx_connection_t *c, ngx_err_t err, char *text) |
253
b6793bc5034b
nginx-0.0.2-2004-02-09-10:46:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
242
diff
changeset
|
1260 { |
257
70e1c7d2b83d
nginx-0.0.2-2004-02-11-20:08:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
256
diff
changeset
|
1261 ngx_uint_t level; |
253
b6793bc5034b
nginx-0.0.2-2004-02-09-10:46:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
242
diff
changeset
|
1262 |
2775 | 1263 /* Winsock may return NGX_ECONNABORTED instead of NGX_ECONNRESET */ |
2774
baad3036086e
Winsock uses ECONNABORTED instead of ECONNRESET
Igor Sysoev <igor@sysoev.ru>
parents:
2725
diff
changeset
|
1264 |
2775 | 1265 if ((err == NGX_ECONNRESET |
1266 #if (NGX_WIN32) | |
1267 || err == NGX_ECONNABORTED | |
2774
baad3036086e
Winsock uses ECONNABORTED instead of ECONNRESET
Igor Sysoev <igor@sysoev.ru>
parents:
2725
diff
changeset
|
1268 #endif |
2775 | 1269 ) && c->log_error == NGX_ERROR_IGNORE_ECONNRESET) |
2774
baad3036086e
Winsock uses ECONNABORTED instead of ECONNRESET
Igor Sysoev <igor@sysoev.ru>
parents:
2725
diff
changeset
|
1270 { |
253
b6793bc5034b
nginx-0.0.2-2004-02-09-10:46:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
242
diff
changeset
|
1271 return 0; |
b6793bc5034b
nginx-0.0.2-2004-02-09-10:46:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
242
diff
changeset
|
1272 } |
b6793bc5034b
nginx-0.0.2-2004-02-09-10:46:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
242
diff
changeset
|
1273 |
2560
a7443674e429
ignore EINVAL from setsockopt() on Solaris
Igor Sysoev <igor@sysoev.ru>
parents:
2512
diff
changeset
|
1274 #if (NGX_SOLARIS) |
a7443674e429
ignore EINVAL from setsockopt() on Solaris
Igor Sysoev <igor@sysoev.ru>
parents:
2512
diff
changeset
|
1275 if (err == NGX_EINVAL && c->log_error == NGX_ERROR_IGNORE_EINVAL) { |
a7443674e429
ignore EINVAL from setsockopt() on Solaris
Igor Sysoev <igor@sysoev.ru>
parents:
2512
diff
changeset
|
1276 return 0; |
a7443674e429
ignore EINVAL from setsockopt() on Solaris
Igor Sysoev <igor@sysoev.ru>
parents:
2512
diff
changeset
|
1277 } |
a7443674e429
ignore EINVAL from setsockopt() on Solaris
Igor Sysoev <igor@sysoev.ru>
parents:
2512
diff
changeset
|
1278 #endif |
a7443674e429
ignore EINVAL from setsockopt() on Solaris
Igor Sysoev <igor@sysoev.ru>
parents:
2512
diff
changeset
|
1279 |
537 | 1280 if (err == 0 |
1281 || err == NGX_ECONNRESET | |
2774
baad3036086e
Winsock uses ECONNABORTED instead of ECONNRESET
Igor Sysoev <igor@sysoev.ru>
parents:
2725
diff
changeset
|
1282 #if (NGX_WIN32) |
baad3036086e
Winsock uses ECONNABORTED instead of ECONNRESET
Igor Sysoev <igor@sysoev.ru>
parents:
2725
diff
changeset
|
1283 || err == NGX_ECONNABORTED |
baad3036086e
Winsock uses ECONNABORTED instead of ECONNRESET
Igor Sysoev <igor@sysoev.ru>
parents:
2725
diff
changeset
|
1284 #else |
278
0ba4821f4460
nginx-0.0.2-2004-03-04-10:04:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
257
diff
changeset
|
1285 || err == NGX_EPIPE |
0ba4821f4460
nginx-0.0.2-2004-03-04-10:04:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
257
diff
changeset
|
1286 #endif |
288
f81d075ad172
nginx-0.0.2-2004-03-14-23:46:25 import
Igor Sysoev <igor@sysoev.ru>
parents:
282
diff
changeset
|
1287 || err == NGX_ENOTCONN |
587 | 1288 || err == NGX_ETIMEDOUT |
288
f81d075ad172
nginx-0.0.2-2004-03-14-23:46:25 import
Igor Sysoev <igor@sysoev.ru>
parents:
282
diff
changeset
|
1289 || err == NGX_ECONNREFUSED |
1869
192443881e51
add NGX_ENETDOWN, NGX_ENETUNREACH, and NGX_EHOSTDOWN
Igor Sysoev <igor@sysoev.ru>
parents:
1833
diff
changeset
|
1290 || err == NGX_ENETDOWN |
192443881e51
add NGX_ENETDOWN, NGX_ENETUNREACH, and NGX_EHOSTDOWN
Igor Sysoev <igor@sysoev.ru>
parents:
1833
diff
changeset
|
1291 || err == NGX_ENETUNREACH |
192443881e51
add NGX_ENETDOWN, NGX_ENETUNREACH, and NGX_EHOSTDOWN
Igor Sysoev <igor@sysoev.ru>
parents:
1833
diff
changeset
|
1292 || err == NGX_EHOSTDOWN |
288
f81d075ad172
nginx-0.0.2-2004-03-14-23:46:25 import
Igor Sysoev <igor@sysoev.ru>
parents:
282
diff
changeset
|
1293 || err == NGX_EHOSTUNREACH) |
278
0ba4821f4460
nginx-0.0.2-2004-03-04-10:04:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
257
diff
changeset
|
1294 { |
256
8e39cab6abd5
nginx-0.0.2-2004-02-10-19:23:38 import
Igor Sysoev <igor@sysoev.ru>
parents:
253
diff
changeset
|
1295 switch (c->log_error) { |
253
b6793bc5034b
nginx-0.0.2-2004-02-09-10:46:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
242
diff
changeset
|
1296 |
2560
a7443674e429
ignore EINVAL from setsockopt() on Solaris
Igor Sysoev <igor@sysoev.ru>
parents:
2512
diff
changeset
|
1297 case NGX_ERROR_IGNORE_EINVAL: |
257
70e1c7d2b83d
nginx-0.0.2-2004-02-11-20:08:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
256
diff
changeset
|
1298 case NGX_ERROR_IGNORE_ECONNRESET: |
253
b6793bc5034b
nginx-0.0.2-2004-02-09-10:46:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
242
diff
changeset
|
1299 case NGX_ERROR_INFO: |
b6793bc5034b
nginx-0.0.2-2004-02-09-10:46:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
242
diff
changeset
|
1300 level = NGX_LOG_INFO; |
b6793bc5034b
nginx-0.0.2-2004-02-09-10:46:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
242
diff
changeset
|
1301 break; |
b6793bc5034b
nginx-0.0.2-2004-02-09-10:46:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
242
diff
changeset
|
1302 |
3151
ad3ddfd06e7d
low default connection errors level from alert to error
Igor Sysoev <igor@sysoev.ru>
parents:
2928
diff
changeset
|
1303 default: |
253
b6793bc5034b
nginx-0.0.2-2004-02-09-10:46:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
242
diff
changeset
|
1304 level = NGX_LOG_ERR; |
b6793bc5034b
nginx-0.0.2-2004-02-09-10:46:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
242
diff
changeset
|
1305 } |
b6793bc5034b
nginx-0.0.2-2004-02-09-10:46:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
242
diff
changeset
|
1306 |
b6793bc5034b
nginx-0.0.2-2004-02-09-10:46:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
242
diff
changeset
|
1307 } else { |
1917
1b2e83c4886d
decrease log level of connection errors while closing socket
Igor Sysoev <igor@sysoev.ru>
parents:
1869
diff
changeset
|
1308 level = NGX_LOG_ALERT; |
253
b6793bc5034b
nginx-0.0.2-2004-02-09-10:46:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
242
diff
changeset
|
1309 } |
b6793bc5034b
nginx-0.0.2-2004-02-09-10:46:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
242
diff
changeset
|
1310 |
b6793bc5034b
nginx-0.0.2-2004-02-09-10:46:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
242
diff
changeset
|
1311 ngx_log_error(level, c->log, err, text); |
b6793bc5034b
nginx-0.0.2-2004-02-09-10:46:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
242
diff
changeset
|
1312 |
b6793bc5034b
nginx-0.0.2-2004-02-09-10:46:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
242
diff
changeset
|
1313 return NGX_ERROR; |
b6793bc5034b
nginx-0.0.2-2004-02-09-10:46:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
242
diff
changeset
|
1314 } |