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