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