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