annotate src/core/ngx_connection.c @ 2802:44b2081c015a

use correct name
author Igor Sysoev <igor@sysoev.ru>
date Tue, 05 May 2009 13:12:59 +0000
parents bceaaf5b055e
children 60758ab4e5f4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
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
4 */
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
218
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
6
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
7 #include <ngx_config.h>
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
8 #include <ngx_core.h>
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
9 #include <ngx_event.h>
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
10
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
11
236
86e473b5641e nginx-0.0.1-2004-01-22-09:47:28 import
Igor Sysoev <igor@sysoev.ru>
parents: 219
diff changeset
12 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
13
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
14
521
6f00349b98e5 nginx-0.1.35-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
15 ngx_int_t
6f00349b98e5 nginx-0.1.35-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
16 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
17 {
523
2019117e6b38 nginx-0.1.36-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 521
diff changeset
18 size_t len;
2019117e6b38 nginx-0.1.36-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 521
diff changeset
19 ngx_uint_t i;
2019117e6b38 nginx-0.1.36-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 521
diff changeset
20 ngx_listening_t *ls;
563
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
21 socklen_t olen;
523
2019117e6b38 nginx-0.1.36-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 521
diff changeset
22 #if (NGX_HAVE_DEFERRED_ACCEPT && defined SO_ACCEPTFILTER)
541
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 537
diff changeset
23 ngx_err_t err;
523
2019117e6b38 nginx-0.1.36-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 521
diff changeset
24 struct accept_filter_arg af;
2019117e6b38 nginx-0.1.36-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 521
diff changeset
25 #endif
2019117e6b38 nginx-0.1.36-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 521
diff changeset
26 #if (NGX_HAVE_DEFERRED_ACCEPT && defined TCP_DEFER_ACCEPT)
2019117e6b38 nginx-0.1.36-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 521
diff changeset
27 int timeout;
2019117e6b38 nginx-0.1.36-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 521
diff changeset
28 #endif
218
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
29
219
f57597ec5249 nginx-0.0.1-2004-01-06-19:49:34 import
Igor Sysoev <igor@sysoev.ru>
parents: 218
diff changeset
30 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
31 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
32
f57597ec5249 nginx-0.0.1-2004-01-06-19:49:34 import
Igor Sysoev <igor@sysoev.ru>
parents: 218
diff changeset
33 /* AF_INET only */
f57597ec5249 nginx-0.0.1-2004-01-06-19:49:34 import
Igor Sysoev <igor@sysoev.ru>
parents: 218
diff changeset
34
f57597ec5249 nginx-0.0.1-2004-01-06-19:49:34 import
Igor Sysoev <igor@sysoev.ru>
parents: 218
diff changeset
35 ls[i].sockaddr = ngx_palloc(cycle->pool, sizeof(struct sockaddr_in));
f57597ec5249 nginx-0.0.1-2004-01-06-19:49:34 import
Igor Sysoev <igor@sysoev.ru>
parents: 218
diff changeset
36 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
37 return NGX_ERROR;
f57597ec5249 nginx-0.0.1-2004-01-06-19:49:34 import
Igor Sysoev <igor@sysoev.ru>
parents: 218
diff changeset
38 }
f57597ec5249 nginx-0.0.1-2004-01-06-19:49:34 import
Igor Sysoev <igor@sysoev.ru>
parents: 218
diff changeset
39
f57597ec5249 nginx-0.0.1-2004-01-06-19:49:34 import
Igor Sysoev <igor@sysoev.ru>
parents: 218
diff changeset
40 ls[i].socklen = sizeof(struct sockaddr_in);
f57597ec5249 nginx-0.0.1-2004-01-06-19:49:34 import
Igor Sysoev <igor@sysoev.ru>
parents: 218
diff changeset
41 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
42 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
43 "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
44 "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
45 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
46 continue;
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
47 }
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
48
2512
2e91aecb9e57 a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents: 2254
diff changeset
49 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
50
2512
2e91aecb9e57 a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents: 2254
diff changeset
51 #if (NGX_HAVE_INET6)
2e91aecb9e57 a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents: 2254
diff changeset
52 case AF_INET6:
2e91aecb9e57 a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents: 2254
diff changeset
53 ls[i].addr_text_max_len = NGX_INET6_ADDRSTRLEN;
2e91aecb9e57 a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents: 2254
diff changeset
54 break;
2e91aecb9e57 a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents: 2254
diff changeset
55 #endif
2e91aecb9e57 a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents: 2254
diff changeset
56
2e91aecb9e57 a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents: 2254
diff changeset
57 case AF_INET:
2e91aecb9e57 a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents: 2254
diff changeset
58 ls[i].addr_text_max_len = NGX_INET_ADDRSTRLEN;
2e91aecb9e57 a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents: 2254
diff changeset
59 break;
2e91aecb9e57 a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents: 2254
diff changeset
60
2e91aecb9e57 a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents: 2254
diff changeset
61 default:
219
f57597ec5249 nginx-0.0.1-2004-01-06-19:49:34 import
Igor Sysoev <igor@sysoev.ru>
parents: 218
diff changeset
62 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
63 "the inherited socket #%d has "
2512
2e91aecb9e57 a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents: 2254
diff changeset
64 "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
65 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
66 continue;
f57597ec5249 nginx-0.0.1-2004-01-06-19:49:34 import
Igor Sysoev <igor@sysoev.ru>
parents: 218
diff changeset
67 }
461
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 452
diff changeset
68
2512
2e91aecb9e57 a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents: 2254
diff changeset
69 len = ls[i].addr_text_max_len + sizeof(":65535") - 1;
218
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
70
2512
2e91aecb9e57 a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents: 2254
diff changeset
71 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
72 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
73 return NGX_ERROR;
218
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
74 }
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
75
2512
2e91aecb9e57 a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents: 2254
diff changeset
76 len = ngx_sock_ntop(ls[i].sockaddr, ls[i].addr_text.data, len, 1);
461
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 452
diff changeset
77 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
78 return NGX_ERROR;
f57597ec5249 nginx-0.0.1-2004-01-06-19:49:34 import
Igor Sysoev <igor@sysoev.ru>
parents: 218
diff changeset
79 }
461
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 452
diff changeset
80
2512
2e91aecb9e57 a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents: 2254
diff changeset
81 ls[i].addr_text.len = len;
523
2019117e6b38 nginx-0.1.36-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 521
diff changeset
82
1377
0d57c150115b set default listen() backlog to 511 on all platforms except FreeBSD
Igor Sysoev <igor@sysoev.ru>
parents: 1225
diff changeset
83 ls[i].backlog = NGX_LISTEN_BACKLOG;
537
c9ad0d9c7d59 nginx-0.1.43-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 523
diff changeset
84
563
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
85 olen = sizeof(int);
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
86
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
87 if (getsockopt(ls[i].fd, SOL_SOCKET, SO_RCVBUF, (void *) &ls[i].rcvbuf,
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
88 &olen)
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
89 == -1)
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
90 {
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
91 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_socket_errno,
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
92 "getsockopt(SO_RCVBUF) %V failed, ignored",
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
93 &ls[i].addr_text);
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
94
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
95 ls[i].rcvbuf = -1;
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
96 }
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
97
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
98 olen = sizeof(int);
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
99
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
100 if (getsockopt(ls[i].fd, SOL_SOCKET, SO_SNDBUF, (void *) &ls[i].sndbuf,
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
101 &olen)
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
102 == -1)
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
103 {
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
104 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_socket_errno,
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
105 "getsockopt(SO_SNDBUF) %V failed, ignored",
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
106 &ls[i].addr_text);
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
107
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
108 ls[i].sndbuf = -1;
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
109 }
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
110
523
2019117e6b38 nginx-0.1.36-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 521
diff changeset
111 #if (NGX_HAVE_DEFERRED_ACCEPT && defined SO_ACCEPTFILTER)
2019117e6b38 nginx-0.1.36-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 521
diff changeset
112
2019117e6b38 nginx-0.1.36-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 521
diff changeset
113 ngx_memzero(&af, sizeof(struct accept_filter_arg));
563
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
114 olen = sizeof(struct accept_filter_arg);
523
2019117e6b38 nginx-0.1.36-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 521
diff changeset
115
563
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
116 if (getsockopt(ls[i].fd, SOL_SOCKET, SO_ACCEPTFILTER, &af, &olen)
523
2019117e6b38 nginx-0.1.36-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 521
diff changeset
117 == -1)
2019117e6b38 nginx-0.1.36-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 521
diff changeset
118 {
541
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 537
diff changeset
119 err = ngx_errno;
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 537
diff changeset
120
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 537
diff changeset
121 if (err == NGX_EINVAL) {
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 537
diff changeset
122 continue;
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 537
diff changeset
123 }
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 537
diff changeset
124
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 537
diff changeset
125 ngx_log_error(NGX_LOG_NOTICE, cycle->log, err,
523
2019117e6b38 nginx-0.1.36-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 521
diff changeset
126 "getsockopt(SO_ACCEPTFILTER) for %V failed, ignored",
2019117e6b38 nginx-0.1.36-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 521
diff changeset
127 &ls[i].addr_text);
2019117e6b38 nginx-0.1.36-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 521
diff changeset
128 continue;
2019117e6b38 nginx-0.1.36-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 521
diff changeset
129 }
2019117e6b38 nginx-0.1.36-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 521
diff changeset
130
563
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
131 if (olen < sizeof(struct accept_filter_arg) || af.af_name[0] == '\0') {
523
2019117e6b38 nginx-0.1.36-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 521
diff changeset
132 continue;
2019117e6b38 nginx-0.1.36-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 521
diff changeset
133 }
2019117e6b38 nginx-0.1.36-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 521
diff changeset
134
2019117e6b38 nginx-0.1.36-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 521
diff changeset
135 ls[i].accept_filter = ngx_palloc(cycle->pool, 16);
2019117e6b38 nginx-0.1.36-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 521
diff changeset
136 if (ls[i].accept_filter == NULL) {
2019117e6b38 nginx-0.1.36-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 521
diff changeset
137 return NGX_ERROR;
2019117e6b38 nginx-0.1.36-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 521
diff changeset
138 }
2019117e6b38 nginx-0.1.36-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 521
diff changeset
139
2019117e6b38 nginx-0.1.36-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 521
diff changeset
140 (void) ngx_cpystrn((u_char *) ls[i].accept_filter,
2019117e6b38 nginx-0.1.36-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 521
diff changeset
141 (u_char *) af.af_name, 16);
2019117e6b38 nginx-0.1.36-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 521
diff changeset
142 #endif
2019117e6b38 nginx-0.1.36-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 521
diff changeset
143
2019117e6b38 nginx-0.1.36-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 521
diff changeset
144 #if (NGX_HAVE_DEFERRED_ACCEPT && defined TCP_DEFER_ACCEPT)
2019117e6b38 nginx-0.1.36-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 521
diff changeset
145
2019117e6b38 nginx-0.1.36-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 521
diff changeset
146 timeout = 0;
563
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
147 olen = sizeof(int);
523
2019117e6b38 nginx-0.1.36-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 521
diff changeset
148
563
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
149 if (getsockopt(ls[i].fd, IPPROTO_TCP, TCP_DEFER_ACCEPT, &timeout, &olen)
523
2019117e6b38 nginx-0.1.36-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 521
diff changeset
150 == -1)
2019117e6b38 nginx-0.1.36-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 521
diff changeset
151 {
2019117e6b38 nginx-0.1.36-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 521
diff changeset
152 ngx_log_error(NGX_LOG_NOTICE, cycle->log, ngx_errno,
2019117e6b38 nginx-0.1.36-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 521
diff changeset
153 "getsockopt(TCP_DEFER_ACCEPT) for %V failed, ignored",
2019117e6b38 nginx-0.1.36-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 521
diff changeset
154 &ls[i].addr_text);
2019117e6b38 nginx-0.1.36-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 521
diff changeset
155 continue;
2019117e6b38 nginx-0.1.36-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 521
diff changeset
156 }
2019117e6b38 nginx-0.1.36-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 521
diff changeset
157
565
7c1369d37c7e nginx-0.3.4-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 563
diff changeset
158 if (olen < sizeof(int) || timeout == 0) {
523
2019117e6b38 nginx-0.1.36-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 521
diff changeset
159 continue;
2019117e6b38 nginx-0.1.36-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 521
diff changeset
160 }
2019117e6b38 nginx-0.1.36-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 521
diff changeset
161
2019117e6b38 nginx-0.1.36-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 521
diff changeset
162 ls[i].deferred_accept = 1;
2019117e6b38 nginx-0.1.36-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 521
diff changeset
163 #endif
218
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
164 }
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
165
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
166 return NGX_OK;
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
167 }
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
168
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
169
521
6f00349b98e5 nginx-0.1.35-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
170 ngx_int_t
6f00349b98e5 nginx-0.1.35-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
171 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
172 {
563
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
173 int reuseaddr;
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
174 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
175 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
176 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
177 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
178 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
179
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
180 reuseaddr = 1;
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
181 #if (NGX_SUPPRESS_WARN)
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
182 failed = 0;
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
183 #endif
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
184
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
185 log = cycle->log;
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
186
563
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
187 /* 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
188
2024
7018254cc006 style fix
Igor Sysoev <igor@sysoev.ru>
parents: 1917
diff changeset
189 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
190 failed = 0;
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
191
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
192 /* for each listening socket */
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
193
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
194 ls = cycle->listening.elts;
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
195 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
196
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
197 if (ls[i].ignore) {
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
198 continue;
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
199 }
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
200
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
201 if (ls[i].fd != -1) {
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
202 continue;
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
203 }
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
204
2785
d478379e51ac *) refactor error_log processing: listen socket log might inherit built-in
Igor Sysoev <igor@sysoev.ru>
parents: 2775
diff changeset
205 ls[i].log = *ls[i].logp;
d478379e51ac *) refactor error_log processing: listen socket log might inherit built-in
Igor Sysoev <igor@sysoev.ru>
parents: 2775
diff changeset
206
218
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
207 if (ls[i].inherited) {
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
208
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
209 /* TODO: close on exit */
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
210 /* TODO: nonblocking */
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
211 /* TODO: deferred accept */
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
212
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
213 continue;
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
214 }
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
215
2198
5975975eedc0 ngx_sock_ntop() takes family from sockaddr, remove duplicate field
Igor Sysoev <igor@sysoev.ru>
parents: 2197
diff changeset
216 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
217
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
218 if (s == -1) {
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
219 ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno,
461
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 452
diff changeset
220 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
221 return NGX_ERROR;
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
222 }
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
223
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
224 if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR,
563
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
225 (const void *) &reuseaddr, sizeof(int))
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
226 == -1)
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
227 {
218
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
228 ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno,
461
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 452
diff changeset
229 "setsockopt(SO_REUSEADDR) %V failed",
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 452
diff changeset
230 &ls[i].addr_text);
563
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
231
1223
8523f4da2d69 style fix
Igor Sysoev <igor@sysoev.ru>
parents: 1222
diff changeset
232 if (ngx_close_socket(s) == -1) {
563
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
233 ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno,
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
234 ngx_close_socket_n " %V failed",
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
235 &ls[i].addr_text);
1223
8523f4da2d69 style fix
Igor Sysoev <igor@sysoev.ru>
parents: 1222
diff changeset
236 }
563
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
237
218
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
238 return NGX_ERROR;
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
239 }
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
240
2562
c352c419be85 ipv6only
Igor Sysoev <igor@sysoev.ru>
parents: 2560
diff changeset
241 #if (NGX_HAVE_INET6 && defined IPV6_V6ONLY)
c352c419be85 ipv6only
Igor Sysoev <igor@sysoev.ru>
parents: 2560
diff changeset
242
c352c419be85 ipv6only
Igor Sysoev <igor@sysoev.ru>
parents: 2560
diff changeset
243 if (ls[i].sockaddr->sa_family == AF_INET6 && ls[i].ipv6only) {
c352c419be85 ipv6only
Igor Sysoev <igor@sysoev.ru>
parents: 2560
diff changeset
244 int ipv6only;
c352c419be85 ipv6only
Igor Sysoev <igor@sysoev.ru>
parents: 2560
diff changeset
245
c352c419be85 ipv6only
Igor Sysoev <igor@sysoev.ru>
parents: 2560
diff changeset
246 ipv6only = (ls[i].ipv6only == 1);
c352c419be85 ipv6only
Igor Sysoev <igor@sysoev.ru>
parents: 2560
diff changeset
247
c352c419be85 ipv6only
Igor Sysoev <igor@sysoev.ru>
parents: 2560
diff changeset
248 if (setsockopt(s, IPPROTO_IPV6, IPV6_V6ONLY,
c352c419be85 ipv6only
Igor Sysoev <igor@sysoev.ru>
parents: 2560
diff changeset
249 (const void *) &ipv6only, sizeof(int))
c352c419be85 ipv6only
Igor Sysoev <igor@sysoev.ru>
parents: 2560
diff changeset
250 == -1)
c352c419be85 ipv6only
Igor Sysoev <igor@sysoev.ru>
parents: 2560
diff changeset
251 {
2801
bceaaf5b055e use local variable
Igor Sysoev <igor@sysoev.ru>
parents: 2799
diff changeset
252 ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno,
2562
c352c419be85 ipv6only
Igor Sysoev <igor@sysoev.ru>
parents: 2560
diff changeset
253 "setsockopt(IPV6_V6ONLY) %V failed, ignored",
c352c419be85 ipv6only
Igor Sysoev <igor@sysoev.ru>
parents: 2560
diff changeset
254 &ls[i].addr_text);
c352c419be85 ipv6only
Igor Sysoev <igor@sysoev.ru>
parents: 2560
diff changeset
255 }
c352c419be85 ipv6only
Igor Sysoev <igor@sysoev.ru>
parents: 2560
diff changeset
256 }
c352c419be85 ipv6only
Igor Sysoev <igor@sysoev.ru>
parents: 2560
diff changeset
257 #endif
218
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
258 /* TODO: close on exit */
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
259
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
260 if (!(ngx_event_flags & NGX_USE_AIO_EVENT)) {
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
261 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
262 ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno,
461
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 452
diff changeset
263 ngx_nonblocking_n " %V failed",
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 452
diff changeset
264 &ls[i].addr_text);
563
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
265
1223
8523f4da2d69 style fix
Igor Sysoev <igor@sysoev.ru>
parents: 1222
diff changeset
266 if (ngx_close_socket(s) == -1) {
563
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
267 ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno,
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
268 ngx_close_socket_n " %V failed",
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
269 &ls[i].addr_text);
1223
8523f4da2d69 style fix
Igor Sysoev <igor@sysoev.ru>
parents: 1222
diff changeset
270 }
563
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
271
218
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
272 return NGX_ERROR;
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
273 }
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
274 }
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
275
2801
bceaaf5b055e use local variable
Igor Sysoev <igor@sysoev.ru>
parents: 2799
diff changeset
276 ngx_log_debug2(NGX_LOG_DEBUG_CORE, log, 0,
593
425af804d968 nginx-0.3.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 587
diff changeset
277 "bind() %V #%d ", &ls[i].addr_text, s);
425af804d968 nginx-0.3.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 587
diff changeset
278
218
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
279 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
280 err = ngx_socket_errno;
563
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
281
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
282 if (err == NGX_EADDRINUSE && ngx_test_config) {
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
283 continue;
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
284 }
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
285
218
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
286 ngx_log_error(NGX_LOG_EMERG, log, err,
461
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 452
diff changeset
287 "bind() to %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
288
1223
8523f4da2d69 style fix
Igor Sysoev <igor@sysoev.ru>
parents: 1222
diff changeset
289 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
290 ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno,
461
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 452
diff changeset
291 ngx_close_socket_n " %V failed",
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 452
diff changeset
292 &ls[i].addr_text);
1223
8523f4da2d69 style fix
Igor Sysoev <igor@sysoev.ru>
parents: 1222
diff changeset
293 }
218
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
294
563
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
295 if (err != NGX_EADDRINUSE) {
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
296 return NGX_ERROR;
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
297 }
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
298
218
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
299 failed = 1;
563
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
300
218
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
301 continue;
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
302 }
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
303
1224
53e3dd035140 do listen() just after bind() to exit early
Igor Sysoev <igor@sysoev.ru>
parents: 1223
diff changeset
304 if (listen(s, ls[i].backlog) == -1) {
53e3dd035140 do listen() just after bind() to exit early
Igor Sysoev <igor@sysoev.ru>
parents: 1223
diff changeset
305 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
306 "listen() to %V, backlog %d failed",
53e3dd035140 do listen() just after bind() to exit early
Igor Sysoev <igor@sysoev.ru>
parents: 1223
diff changeset
307 &ls[i].addr_text, ls[i].backlog);
53e3dd035140 do listen() just after bind() to exit early
Igor Sysoev <igor@sysoev.ru>
parents: 1223
diff changeset
308
53e3dd035140 do listen() just after bind() to exit early
Igor Sysoev <igor@sysoev.ru>
parents: 1223
diff changeset
309 if (ngx_close_socket(s) == -1) {
53e3dd035140 do listen() just after bind() to exit early
Igor Sysoev <igor@sysoev.ru>
parents: 1223
diff changeset
310 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
311 ngx_close_socket_n " %V failed",
53e3dd035140 do listen() just after bind() to exit early
Igor Sysoev <igor@sysoev.ru>
parents: 1223
diff changeset
312 &ls[i].addr_text);
53e3dd035140 do listen() just after bind() to exit early
Igor Sysoev <igor@sysoev.ru>
parents: 1223
diff changeset
313 }
53e3dd035140 do listen() just after bind() to exit early
Igor Sysoev <igor@sysoev.ru>
parents: 1223
diff changeset
314
53e3dd035140 do listen() just after bind() to exit early
Igor Sysoev <igor@sysoev.ru>
parents: 1223
diff changeset
315 return NGX_ERROR;
53e3dd035140 do listen() just after bind() to exit early
Igor Sysoev <igor@sysoev.ru>
parents: 1223
diff changeset
316 }
53e3dd035140 do listen() just after bind() to exit early
Igor Sysoev <igor@sysoev.ru>
parents: 1223
diff changeset
317
563
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
318 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
319
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
320 ls[i].fd = s;
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
321 }
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
322
563
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
323 if (!failed) {
218
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
324 break;
563
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
325 }
218
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
326
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
327 /* TODO: delay configurable */
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
328
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
329 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
330 "try again to bind() after 500ms");
563
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
331
218
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
332 ngx_msleep(500);
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
333 }
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
334
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
335 if (failed) {
477
ad1e9ebf93bb nginx-0.1.13-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 467
diff changeset
336 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
337 return NGX_ERROR;
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
338 }
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
339
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
340 return NGX_OK;
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
341 }
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
342
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
343
521
6f00349b98e5 nginx-0.1.35-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
344 void
2802
44b2081c015a use correct name
Igor Sysoev <igor@sysoev.ru>
parents: 2801
diff changeset
345 ngx_configure_listening_sockets(ngx_cycle_t *cycle)
563
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
346 {
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
347 ngx_uint_t i;
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
348 ngx_listening_t *ls;
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
349
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
350 #if (NGX_HAVE_DEFERRED_ACCEPT && defined SO_ACCEPTFILTER)
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
351 struct accept_filter_arg af;
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
352 #endif
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
353 #if (NGX_HAVE_DEFERRED_ACCEPT && defined TCP_DEFER_ACCEPT)
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
354 int timeout;
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
355 #endif
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
356
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
357 ls = cycle->listening.elts;
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
358 for (i = 0; i < cycle->listening.nelts; i++) {
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
359
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
360 if (ls[i].rcvbuf != -1) {
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
361 if (setsockopt(ls[i].fd, SOL_SOCKET, SO_RCVBUF,
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
362 (const void *) &ls[i].rcvbuf, sizeof(int))
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
363 == -1)
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
364 {
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
365 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_socket_errno,
569
174f1e853e1e nginx-0.3.6-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 565
diff changeset
366 "setsockopt(SO_RCVBUF, %d) %V failed, ignored",
174f1e853e1e nginx-0.3.6-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 565
diff changeset
367 ls[i].rcvbuf, &ls[i].addr_text);
563
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
368 }
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
369 }
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
370
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
371 if (ls[i].sndbuf != -1) {
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
372 if (setsockopt(ls[i].fd, SOL_SOCKET, SO_SNDBUF,
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
373 (const void *) &ls[i].sndbuf, sizeof(int))
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
374 == -1)
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
375 {
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
376 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_socket_errno,
569
174f1e853e1e nginx-0.3.6-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 565
diff changeset
377 "setsockopt(SO_SNDBUF, %d) %V failed, ignored",
174f1e853e1e nginx-0.3.6-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 565
diff changeset
378 ls[i].sndbuf, &ls[i].addr_text);
563
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
379 }
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
380 }
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
381
635
18268abd340c nginx-0.3.39-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 627
diff changeset
382 #if 0
18268abd340c nginx-0.3.39-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 627
diff changeset
383 if (1) {
18268abd340c nginx-0.3.39-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 627
diff changeset
384 int tcp_nodelay = 1;
18268abd340c nginx-0.3.39-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 627
diff changeset
385
18268abd340c nginx-0.3.39-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 627
diff changeset
386 if (setsockopt(ls[i].fd, IPPROTO_TCP, TCP_NODELAY,
18268abd340c nginx-0.3.39-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 627
diff changeset
387 (const void *) &tcp_nodelay, sizeof(int))
18268abd340c nginx-0.3.39-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 627
diff changeset
388 == -1)
18268abd340c nginx-0.3.39-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 627
diff changeset
389 {
18268abd340c nginx-0.3.39-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 627
diff changeset
390 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_socket_errno,
18268abd340c nginx-0.3.39-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 627
diff changeset
391 "setsockopt(TCP_NODELAY) %V failed, ignored",
18268abd340c nginx-0.3.39-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 627
diff changeset
392 &ls[i].addr_text);
18268abd340c nginx-0.3.39-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 627
diff changeset
393 }
18268abd340c nginx-0.3.39-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 627
diff changeset
394 }
18268abd340c nginx-0.3.39-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 627
diff changeset
395 #endif
18268abd340c nginx-0.3.39-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 627
diff changeset
396
563
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
397 if (ls[i].listen) {
1225
8dfa34cb186e add comment
Igor Sysoev <igor@sysoev.ru>
parents: 1224
diff changeset
398
8dfa34cb186e add comment
Igor Sysoev <igor@sysoev.ru>
parents: 1224
diff changeset
399 /* change backlog via listen() */
8dfa34cb186e add comment
Igor Sysoev <igor@sysoev.ru>
parents: 1224
diff changeset
400
563
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
401 if (listen(ls[i].fd, ls[i].backlog) == -1) {
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
402 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_socket_errno,
1222
d8d09f731c17 change wording
Igor Sysoev <igor@sysoev.ru>
parents: 1220
diff changeset
403 "listen() to %V, backlog %d failed, ignored",
d8d09f731c17 change wording
Igor Sysoev <igor@sysoev.ru>
parents: 1220
diff changeset
404 &ls[i].addr_text, ls[i].backlog);
563
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
405 }
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
406 }
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
407
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
408 /*
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
409 * setting deferred mode should be last operation on socket,
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
410 * because code may prematurely continue cycle on failure
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
411 */
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
412
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
413 #if (NGX_HAVE_DEFERRED_ACCEPT)
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
414
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
415 #ifdef SO_ACCEPTFILTER
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
416
627
387450de0b4d nginx-0.3.35-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 611
diff changeset
417 if (ls[i].delete_deferred) {
387450de0b4d nginx-0.3.35-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 611
diff changeset
418 if (setsockopt(ls[i].fd, SOL_SOCKET, SO_ACCEPTFILTER, NULL, 0)
387450de0b4d nginx-0.3.35-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 611
diff changeset
419 == -1)
563
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
420 {
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
421 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
422 "setsockopt(SO_ACCEPTFILTER, NULL) "
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
423 "for %V failed, ignored",
627
387450de0b4d nginx-0.3.35-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 611
diff changeset
424 &ls[i].addr_text);
563
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
425
627
387450de0b4d nginx-0.3.35-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 611
diff changeset
426 if (ls[i].accept_filter) {
563
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
427 ngx_log_error(NGX_LOG_ALERT, cycle->log, 0,
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
428 "could not change the accept filter "
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
429 "to \"%s\" for %V, ignored",
627
387450de0b4d nginx-0.3.35-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 611
diff changeset
430 ls[i].accept_filter, &ls[i].addr_text);
563
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
431 }
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
432
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
433 continue;
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
434 }
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
435
627
387450de0b4d nginx-0.3.35-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 611
diff changeset
436 ls[i].deferred_accept = 0;
563
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
437 }
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
438
627
387450de0b4d nginx-0.3.35-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 611
diff changeset
439 if (ls[i].add_deferred) {
563
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
440 ngx_memzero(&af, sizeof(struct accept_filter_arg));
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
441 (void) ngx_cpystrn((u_char *) af.af_name,
627
387450de0b4d nginx-0.3.35-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 611
diff changeset
442 (u_char *) ls[i].accept_filter, 16);
563
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
443
627
387450de0b4d nginx-0.3.35-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 611
diff changeset
444 if (setsockopt(ls[i].fd, SOL_SOCKET, SO_ACCEPTFILTER,
563
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
445 &af, sizeof(struct accept_filter_arg))
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
446 == -1)
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
447 {
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
448 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
449 "setsockopt(SO_ACCEPTFILTER, \"%s\") "
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
450 " for %V failed, ignored",
627
387450de0b4d nginx-0.3.35-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 611
diff changeset
451 ls[i].accept_filter, &ls[i].addr_text);
563
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
452 continue;
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
453 }
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
454
627
387450de0b4d nginx-0.3.35-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 611
diff changeset
455 ls[i].deferred_accept = 1;
563
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
456 }
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
457
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
458 #endif
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
459
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
460 #ifdef TCP_DEFER_ACCEPT
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
461
627
387450de0b4d nginx-0.3.35-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 611
diff changeset
462 if (ls[i].add_deferred || ls[i].delete_deferred) {
563
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
463
627
387450de0b4d nginx-0.3.35-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 611
diff changeset
464 if (ls[i].add_deferred) {
387450de0b4d nginx-0.3.35-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 611
diff changeset
465 timeout = (int) (ls[i].post_accept_timeout / 1000);
563
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
466
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
467 } else {
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
468 timeout = 0;
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
469 }
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
470
627
387450de0b4d nginx-0.3.35-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 611
diff changeset
471 if (setsockopt(ls[i].fd, IPPROTO_TCP, TCP_DEFER_ACCEPT,
563
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
472 &timeout, sizeof(int))
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
473 == -1)
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
474 {
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
475 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
476 "setsockopt(TCP_DEFER_ACCEPT, %d) for %V failed, "
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
477 "ignored",
627
387450de0b4d nginx-0.3.35-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 611
diff changeset
478 timeout, &ls[i].addr_text);
563
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
479
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
480 continue;
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
481 }
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
482 }
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
483
627
387450de0b4d nginx-0.3.35-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 611
diff changeset
484 if (ls[i].add_deferred) {
387450de0b4d nginx-0.3.35-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 611
diff changeset
485 ls[i].deferred_accept = 1;
563
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
486 }
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
487
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
488 #endif
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
489
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
490 #endif /* NGX_HAVE_DEFERRED_ACCEPT */
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
491 }
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
492
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
493 return;
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
494 }
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
495
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
496
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
497 void
521
6f00349b98e5 nginx-0.1.35-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
498 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
499 {
543
511a89da35ad nginx-0.2.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 541
diff changeset
500 ngx_uint_t i;
511a89da35ad nginx-0.2.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 541
diff changeset
501 ngx_listening_t *ls;
511a89da35ad nginx-0.2.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 541
diff changeset
502 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
503
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
504 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
505 return;
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
506 }
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
507
303
00c5660d2707 nginx-0.0.3-2004-04-01-20:20:53 import
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
508 ngx_accept_mutex_held = 0;
611
3f8a2132b93d nginx-0.3.27-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 605
diff changeset
509 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
510
218
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
511 ls = cycle->listening.elts;
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
512 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
513
543
511a89da35ad nginx-0.2.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 541
diff changeset
514 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
515
2725
d43d73277c5c Win32 master/workers model
Igor Sysoev <igor@sysoev.ru>
parents: 2562
diff changeset
516 if (c) {
d43d73277c5c Win32 master/workers model
Igor Sysoev <igor@sysoev.ru>
parents: 2562
diff changeset
517 if (c->read->active) {
d43d73277c5c Win32 master/workers model
Igor Sysoev <igor@sysoev.ru>
parents: 2562
diff changeset
518 if (ngx_event_flags & NGX_USE_RTSIG_EVENT) {
d43d73277c5c Win32 master/workers model
Igor Sysoev <igor@sysoev.ru>
parents: 2562
diff changeset
519 ngx_del_conn(c, NGX_CLOSE_EVENT);
1833
86464f8eddd6 workaround for Linux 2.6 OpenVZ
Igor Sysoev <igor@sysoev.ru>
parents: 1435
diff changeset
520
2725
d43d73277c5c Win32 master/workers model
Igor Sysoev <igor@sysoev.ru>
parents: 2562
diff changeset
521 } else 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
522
2725
d43d73277c5c Win32 master/workers model
Igor Sysoev <igor@sysoev.ru>
parents: 2562
diff changeset
523 /*
d43d73277c5c Win32 master/workers model
Igor Sysoev <igor@sysoev.ru>
parents: 2562
diff changeset
524 * it seems that Linux-2.6.x OpenVZ sends events
d43d73277c5c Win32 master/workers model
Igor Sysoev <igor@sysoev.ru>
parents: 2562
diff changeset
525 * for closed shared listening sockets unless
d43d73277c5c Win32 master/workers model
Igor Sysoev <igor@sysoev.ru>
parents: 2562
diff changeset
526 * the events was explicity deleted
d43d73277c5c Win32 master/workers model
Igor Sysoev <igor@sysoev.ru>
parents: 2562
diff changeset
527 */
1833
86464f8eddd6 workaround for Linux 2.6 OpenVZ
Igor Sysoev <igor@sysoev.ru>
parents: 1435
diff changeset
528
2725
d43d73277c5c Win32 master/workers model
Igor Sysoev <igor@sysoev.ru>
parents: 2562
diff changeset
529 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
530
2725
d43d73277c5c Win32 master/workers model
Igor Sysoev <igor@sysoev.ru>
parents: 2562
diff changeset
531 } else {
d43d73277c5c Win32 master/workers model
Igor Sysoev <igor@sysoev.ru>
parents: 2562
diff changeset
532 ngx_del_event(c->read, NGX_READ_EVENT, NGX_CLOSE_EVENT);
d43d73277c5c Win32 master/workers model
Igor Sysoev <igor@sysoev.ru>
parents: 2562
diff changeset
533 }
317
1308b98496a2 nginx-0.0.3-2004-04-15-19:34:36 import
Igor Sysoev <igor@sysoev.ru>
parents: 303
diff changeset
534 }
2725
d43d73277c5c Win32 master/workers model
Igor Sysoev <igor@sysoev.ru>
parents: 2562
diff changeset
535
d43d73277c5c Win32 master/workers model
Igor Sysoev <igor@sysoev.ru>
parents: 2562
diff changeset
536 ngx_free_connection(c);
d43d73277c5c Win32 master/workers model
Igor Sysoev <igor@sysoev.ru>
parents: 2562
diff changeset
537
d43d73277c5c Win32 master/workers model
Igor Sysoev <igor@sysoev.ru>
parents: 2562
diff changeset
538 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
539 }
218
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
540
563
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
541 ngx_log_debug2(NGX_LOG_DEBUG_CORE, cycle->log, 0,
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
542 "close listening %V #%d ", &ls[i].addr_text, ls[i].fd);
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
543
543
511a89da35ad nginx-0.2.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 541
diff changeset
544 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
545 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_socket_errno,
461
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 452
diff changeset
546 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
547 }
543
511a89da35ad nginx-0.2.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 541
diff changeset
548 }
511a89da35ad nginx-0.2.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 541
diff changeset
549 }
218
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
550
543
511a89da35ad nginx-0.2.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 541
diff changeset
551
511a89da35ad nginx-0.2.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 541
diff changeset
552 ngx_connection_t *
511a89da35ad nginx-0.2.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 541
diff changeset
553 ngx_get_connection(ngx_socket_t s, ngx_log_t *log)
511a89da35ad nginx-0.2.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 541
diff changeset
554 {
561
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 543
diff changeset
555 ngx_uint_t instance;
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 543
diff changeset
556 ngx_event_t *rev, *wev;
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 543
diff changeset
557 ngx_connection_t *c;
543
511a89da35ad nginx-0.2.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 541
diff changeset
558
511a89da35ad nginx-0.2.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 541
diff changeset
559 /* disable warning: Win32 SOCKET is u_int while UNIX socket is int */
511a89da35ad nginx-0.2.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 541
diff changeset
560
511a89da35ad nginx-0.2.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 541
diff changeset
561 if (ngx_cycle->files && (ngx_uint_t) s >= ngx_cycle->files_n) {
511a89da35ad nginx-0.2.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 541
diff changeset
562 ngx_log_error(NGX_LOG_ALERT, log, 0,
511a89da35ad nginx-0.2.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 541
diff changeset
563 "the new socket has number %d, "
511a89da35ad nginx-0.2.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 541
diff changeset
564 "but only %ui files are available",
511a89da35ad nginx-0.2.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 541
diff changeset
565 s, ngx_cycle->files_n);
511a89da35ad nginx-0.2.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 541
diff changeset
566 return NULL;
511a89da35ad nginx-0.2.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 541
diff changeset
567 }
511a89da35ad nginx-0.2.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 541
diff changeset
568
511a89da35ad nginx-0.2.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 541
diff changeset
569 /* ngx_mutex_lock */
511a89da35ad nginx-0.2.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 541
diff changeset
570
511a89da35ad nginx-0.2.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 541
diff changeset
571 c = ngx_cycle->free_connections;
511a89da35ad nginx-0.2.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 541
diff changeset
572
511a89da35ad nginx-0.2.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 541
diff changeset
573 if (c == NULL) {
511a89da35ad nginx-0.2.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 541
diff changeset
574 ngx_log_error(NGX_LOG_ALERT, log, 0,
2254
353dbe12845e fix grammar
Igor Sysoev <igor@sysoev.ru>
parents: 2198
diff changeset
575 "%ui worker_connections are not enough",
543
511a89da35ad nginx-0.2.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 541
diff changeset
576 ngx_cycle->connection_n);
511a89da35ad nginx-0.2.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 541
diff changeset
577
511a89da35ad nginx-0.2.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 541
diff changeset
578 /* ngx_mutex_unlock */
511a89da35ad nginx-0.2.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 541
diff changeset
579
511a89da35ad nginx-0.2.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 541
diff changeset
580 return NULL;
511a89da35ad nginx-0.2.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 541
diff changeset
581 }
511a89da35ad nginx-0.2.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 541
diff changeset
582
511a89da35ad nginx-0.2.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 541
diff changeset
583 ngx_cycle->free_connections = c->data;
511a89da35ad nginx-0.2.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 541
diff changeset
584 ngx_cycle->free_connection_n--;
511a89da35ad nginx-0.2.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 541
diff changeset
585
511a89da35ad nginx-0.2.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 541
diff changeset
586 /* ngx_mutex_unlock */
511a89da35ad nginx-0.2.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 541
diff changeset
587
511a89da35ad nginx-0.2.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 541
diff changeset
588 if (ngx_cycle->files) {
511a89da35ad nginx-0.2.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 541
diff changeset
589 ngx_cycle->files[s] = c;
511a89da35ad nginx-0.2.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 541
diff changeset
590 }
511a89da35ad nginx-0.2.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 541
diff changeset
591
561
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 543
diff changeset
592 rev = c->read;
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 543
diff changeset
593 wev = c->write;
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 543
diff changeset
594
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 543
diff changeset
595 ngx_memzero(c, sizeof(ngx_connection_t));
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 543
diff changeset
596
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 543
diff changeset
597 c->read = rev;
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 543
diff changeset
598 c->write = wev;
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 543
diff changeset
599 c->fd = s;
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 543
diff changeset
600 c->log = log;
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 543
diff changeset
601
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 543
diff changeset
602 instance = rev->instance;
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 543
diff changeset
603
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 543
diff changeset
604 ngx_memzero(rev, sizeof(ngx_event_t));
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 543
diff changeset
605 ngx_memzero(wev, sizeof(ngx_event_t));
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 543
diff changeset
606
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 543
diff changeset
607 rev->instance = !instance;
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 543
diff changeset
608 wev->instance = !instance;
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 543
diff changeset
609
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 543
diff changeset
610 rev->index = NGX_INVALID_INDEX;
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 543
diff changeset
611 wev->index = NGX_INVALID_INDEX;
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 543
diff changeset
612
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 543
diff changeset
613 rev->data = c;
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 543
diff changeset
614 wev->data = c;
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 543
diff changeset
615
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 543
diff changeset
616 wev->write = 1;
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 543
diff changeset
617
543
511a89da35ad nginx-0.2.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 541
diff changeset
618 return c;
511a89da35ad nginx-0.2.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 541
diff changeset
619 }
511a89da35ad nginx-0.2.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 541
diff changeset
620
511a89da35ad nginx-0.2.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 541
diff changeset
621
511a89da35ad nginx-0.2.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 541
diff changeset
622 void
511a89da35ad nginx-0.2.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 541
diff changeset
623 ngx_free_connection(ngx_connection_t *c)
511a89da35ad nginx-0.2.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 541
diff changeset
624 {
511a89da35ad nginx-0.2.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 541
diff changeset
625 /* ngx_mutex_lock */
511a89da35ad nginx-0.2.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 541
diff changeset
626
511a89da35ad nginx-0.2.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 541
diff changeset
627 c->data = ngx_cycle->free_connections;
511a89da35ad nginx-0.2.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 541
diff changeset
628 ngx_cycle->free_connections = c;
511a89da35ad nginx-0.2.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 541
diff changeset
629 ngx_cycle->free_connection_n++;
511a89da35ad nginx-0.2.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 541
diff changeset
630
511a89da35ad nginx-0.2.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 541
diff changeset
631 /* ngx_mutex_unlock */
511a89da35ad nginx-0.2.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 541
diff changeset
632
511a89da35ad nginx-0.2.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 541
diff changeset
633 if (ngx_cycle->files) {
511a89da35ad nginx-0.2.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 541
diff changeset
634 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
635 }
05592fd7a436 nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
636 }
253
b6793bc5034b nginx-0.0.2-2004-02-09-10:46:43 import
Igor Sysoev <igor@sysoev.ru>
parents: 242
diff changeset
637
b6793bc5034b nginx-0.0.2-2004-02-09-10:46:43 import
Igor Sysoev <igor@sysoev.ru>
parents: 242
diff changeset
638
521
6f00349b98e5 nginx-0.1.35-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
639 void
6f00349b98e5 nginx-0.1.35-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
640 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
641 {
1917
1b2e83c4886d decrease log level of connection errors while closing socket
Igor Sysoev <igor@sysoev.ru>
parents: 1869
diff changeset
642 ngx_err_t err;
1b2e83c4886d decrease log level of connection errors while closing socket
Igor Sysoev <igor@sysoev.ru>
parents: 1869
diff changeset
643 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
644 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
645
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 477
diff changeset
646 if (c->fd == -1) {
417
0526206251f6 nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents: 346
diff changeset
647 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
648 return;
0526206251f6 nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents: 346
diff changeset
649 }
0526206251f6 nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents: 346
diff changeset
650
0526206251f6 nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents: 346
diff changeset
651 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
652 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
653 }
577
4d9ea73a627a nginx-0.3.10-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
654
417
0526206251f6 nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents: 346
diff changeset
655 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
656 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
657 }
577
4d9ea73a627a nginx-0.3.10-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 569
diff changeset
658
417
0526206251f6 nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents: 346
diff changeset
659 if (ngx_del_conn) {
0526206251f6 nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents: 346
diff changeset
660 ngx_del_conn(c, NGX_CLOSE_EVENT);
0526206251f6 nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents: 346
diff changeset
661
0526206251f6 nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents: 346
diff changeset
662 } else {
0526206251f6 nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents: 346
diff changeset
663 if (c->read->active || c->read->disabled) {
0526206251f6 nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents: 346
diff changeset
664 ngx_del_event(c->read, NGX_READ_EVENT, NGX_CLOSE_EVENT);
0526206251f6 nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents: 346
diff changeset
665 }
0526206251f6 nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents: 346
diff changeset
666
0526206251f6 nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents: 346
diff changeset
667 if (c->write->active || c->write->disabled) {
0526206251f6 nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents: 346
diff changeset
668 ngx_del_event(c->write, NGX_WRITE_EVENT, NGX_CLOSE_EVENT);
0526206251f6 nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents: 346
diff changeset
669 }
0526206251f6 nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents: 346
diff changeset
670 }
0526206251f6 nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents: 346
diff changeset
671
0526206251f6 nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents: 346
diff changeset
672 #if (NGX_THREADS)
0526206251f6 nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents: 346
diff changeset
673
0526206251f6 nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents: 346
diff changeset
674 /*
0526206251f6 nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents: 346
diff changeset
675 * we have to clean the connection information before the closing
0526206251f6 nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents: 346
diff changeset
676 * because another thread may reopen the same file descriptor
0526206251f6 nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents: 346
diff changeset
677 * before we clean the connection
0526206251f6 nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents: 346
diff changeset
678 */
0526206251f6 nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents: 346
diff changeset
679
563
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
680 ngx_mutex_lock(ngx_posted_events_mutex);
417
0526206251f6 nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents: 346
diff changeset
681
563
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
682 if (c->read->prev) {
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
683 ngx_delete_posted_event(c->read);
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
684 }
417
0526206251f6 nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents: 346
diff changeset
685
563
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
686 if (c->write->prev) {
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
687 ngx_delete_posted_event(c->write);
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
688 }
417
0526206251f6 nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents: 346
diff changeset
689
563
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
690 c->read->closed = 1;
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
691 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
692
563
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
693 if (c->single_connection) {
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
694 ngx_unlock(&c->lock);
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
695 c->read->locked = 0;
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
696 c->write->locked = 0;
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
697 }
417
0526206251f6 nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents: 346
diff changeset
698
563
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
699 ngx_mutex_unlock(ngx_posted_events_mutex);
417
0526206251f6 nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents: 346
diff changeset
700
0526206251f6 nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents: 346
diff changeset
701 #else
0526206251f6 nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents: 346
diff changeset
702
0526206251f6 nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents: 346
diff changeset
703 if (c->read->prev) {
0526206251f6 nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents: 346
diff changeset
704 ngx_delete_posted_event(c->read);
0526206251f6 nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents: 346
diff changeset
705 }
0526206251f6 nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents: 346
diff changeset
706
0526206251f6 nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents: 346
diff changeset
707 if (c->write->prev) {
0526206251f6 nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents: 346
diff changeset
708 ngx_delete_posted_event(c->write);
0526206251f6 nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents: 346
diff changeset
709 }
0526206251f6 nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents: 346
diff changeset
710
0526206251f6 nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents: 346
diff changeset
711 c->read->closed = 1;
0526206251f6 nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents: 346
diff changeset
712 c->write->closed = 1;
0526206251f6 nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents: 346
diff changeset
713
0526206251f6 nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents: 346
diff changeset
714 #endif
0526206251f6 nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents: 346
diff changeset
715
1917
1b2e83c4886d decrease log level of connection errors while closing socket
Igor Sysoev <igor@sysoev.ru>
parents: 1869
diff changeset
716 log_error = c->log_error;
1b2e83c4886d decrease log level of connection errors while closing socket
Igor Sysoev <igor@sysoev.ru>
parents: 1869
diff changeset
717
543
511a89da35ad nginx-0.2.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 541
diff changeset
718 ngx_free_connection(c);
511a89da35ad nginx-0.2.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 541
diff changeset
719
417
0526206251f6 nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents: 346
diff changeset
720 fd = c->fd;
0526206251f6 nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents: 346
diff changeset
721 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
722
0526206251f6 nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents: 346
diff changeset
723 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
724
1917
1b2e83c4886d decrease log level of connection errors while closing socket
Igor Sysoev <igor@sysoev.ru>
parents: 1869
diff changeset
725 err = ngx_socket_errno;
1b2e83c4886d decrease log level of connection errors while closing socket
Igor Sysoev <igor@sysoev.ru>
parents: 1869
diff changeset
726
1b2e83c4886d decrease log level of connection errors while closing socket
Igor Sysoev <igor@sysoev.ru>
parents: 1869
diff changeset
727 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
728
1b2e83c4886d decrease log level of connection errors while closing socket
Igor Sysoev <igor@sysoev.ru>
parents: 1869
diff changeset
729 switch (log_error) {
1b2e83c4886d decrease log level of connection errors while closing socket
Igor Sysoev <igor@sysoev.ru>
parents: 1869
diff changeset
730
1b2e83c4886d decrease log level of connection errors while closing socket
Igor Sysoev <igor@sysoev.ru>
parents: 1869
diff changeset
731 case NGX_ERROR_INFO:
1b2e83c4886d decrease log level of connection errors while closing socket
Igor Sysoev <igor@sysoev.ru>
parents: 1869
diff changeset
732 level = NGX_LOG_INFO;
1b2e83c4886d decrease log level of connection errors while closing socket
Igor Sysoev <igor@sysoev.ru>
parents: 1869
diff changeset
733 break;
1b2e83c4886d decrease log level of connection errors while closing socket
Igor Sysoev <igor@sysoev.ru>
parents: 1869
diff changeset
734
1b2e83c4886d decrease log level of connection errors while closing socket
Igor Sysoev <igor@sysoev.ru>
parents: 1869
diff changeset
735 case NGX_ERROR_ERR:
1b2e83c4886d decrease log level of connection errors while closing socket
Igor Sysoev <igor@sysoev.ru>
parents: 1869
diff changeset
736 level = NGX_LOG_ERR;
1b2e83c4886d decrease log level of connection errors while closing socket
Igor Sysoev <igor@sysoev.ru>
parents: 1869
diff changeset
737 break;
1b2e83c4886d decrease log level of connection errors while closing socket
Igor Sysoev <igor@sysoev.ru>
parents: 1869
diff changeset
738
1b2e83c4886d decrease log level of connection errors while closing socket
Igor Sysoev <igor@sysoev.ru>
parents: 1869
diff changeset
739 default:
1b2e83c4886d decrease log level of connection errors while closing socket
Igor Sysoev <igor@sysoev.ru>
parents: 1869
diff changeset
740 level = NGX_LOG_CRIT;
1b2e83c4886d decrease log level of connection errors while closing socket
Igor Sysoev <igor@sysoev.ru>
parents: 1869
diff changeset
741 }
1b2e83c4886d decrease log level of connection errors while closing socket
Igor Sysoev <igor@sysoev.ru>
parents: 1869
diff changeset
742
1b2e83c4886d decrease log level of connection errors while closing socket
Igor Sysoev <igor@sysoev.ru>
parents: 1869
diff changeset
743 } else {
1b2e83c4886d decrease log level of connection errors while closing socket
Igor Sysoev <igor@sysoev.ru>
parents: 1869
diff changeset
744 level = NGX_LOG_CRIT;
1b2e83c4886d decrease log level of connection errors while closing socket
Igor Sysoev <igor@sysoev.ru>
parents: 1869
diff changeset
745 }
1b2e83c4886d decrease log level of connection errors while closing socket
Igor Sysoev <igor@sysoev.ru>
parents: 1869
diff changeset
746
417
0526206251f6 nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents: 346
diff changeset
747 /* we use ngx_cycle->log because c->log was in c->pool */
0526206251f6 nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents: 346
diff changeset
748
1917
1b2e83c4886d decrease log level of connection errors while closing socket
Igor Sysoev <igor@sysoev.ru>
parents: 1869
diff changeset
749 ngx_log_error(level, ngx_cycle->log, err,
1435
0d37ad506bb6 log socket number
Igor Sysoev <igor@sysoev.ru>
parents: 1377
diff changeset
750 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
751 }
0526206251f6 nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents: 346
diff changeset
752 }
0526206251f6 nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents: 346
diff changeset
753
0526206251f6 nginx-0.0.10-2004-09-07-19:29:22 import
Igor Sysoev <igor@sysoev.ru>
parents: 346
diff changeset
754
521
6f00349b98e5 nginx-0.1.35-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
755 ngx_int_t
6f00349b98e5 nginx-0.1.35-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
756 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
757 {
257
70e1c7d2b83d nginx-0.0.2-2004-02-11-20:08:49 import
Igor Sysoev <igor@sysoev.ru>
parents: 256
diff changeset
758 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
759
2775
01c691e31032 fix the previous commit
Igor Sysoev <igor@sysoev.ru>
parents: 2774
diff changeset
760 /* 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
761
2775
01c691e31032 fix the previous commit
Igor Sysoev <igor@sysoev.ru>
parents: 2774
diff changeset
762 if ((err == NGX_ECONNRESET
01c691e31032 fix the previous commit
Igor Sysoev <igor@sysoev.ru>
parents: 2774
diff changeset
763 #if (NGX_WIN32)
01c691e31032 fix the previous commit
Igor Sysoev <igor@sysoev.ru>
parents: 2774
diff changeset
764 || err == NGX_ECONNABORTED
2774
baad3036086e Winsock uses ECONNABORTED instead of ECONNRESET
Igor Sysoev <igor@sysoev.ru>
parents: 2725
diff changeset
765 #endif
2775
01c691e31032 fix the previous commit
Igor Sysoev <igor@sysoev.ru>
parents: 2774
diff changeset
766 ) && c->log_error == NGX_ERROR_IGNORE_ECONNRESET)
2774
baad3036086e Winsock uses ECONNABORTED instead of ECONNRESET
Igor Sysoev <igor@sysoev.ru>
parents: 2725
diff changeset
767 {
253
b6793bc5034b nginx-0.0.2-2004-02-09-10:46:43 import
Igor Sysoev <igor@sysoev.ru>
parents: 242
diff changeset
768 return 0;
b6793bc5034b nginx-0.0.2-2004-02-09-10:46:43 import
Igor Sysoev <igor@sysoev.ru>
parents: 242
diff changeset
769 }
b6793bc5034b nginx-0.0.2-2004-02-09-10:46:43 import
Igor Sysoev <igor@sysoev.ru>
parents: 242
diff changeset
770
2560
a7443674e429 ignore EINVAL from setsockopt() on Solaris
Igor Sysoev <igor@sysoev.ru>
parents: 2512
diff changeset
771 #if (NGX_SOLARIS)
a7443674e429 ignore EINVAL from setsockopt() on Solaris
Igor Sysoev <igor@sysoev.ru>
parents: 2512
diff changeset
772 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
773 return 0;
a7443674e429 ignore EINVAL from setsockopt() on Solaris
Igor Sysoev <igor@sysoev.ru>
parents: 2512
diff changeset
774 }
a7443674e429 ignore EINVAL from setsockopt() on Solaris
Igor Sysoev <igor@sysoev.ru>
parents: 2512
diff changeset
775 #endif
a7443674e429 ignore EINVAL from setsockopt() on Solaris
Igor Sysoev <igor@sysoev.ru>
parents: 2512
diff changeset
776
537
c9ad0d9c7d59 nginx-0.1.43-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 523
diff changeset
777 if (err == 0
c9ad0d9c7d59 nginx-0.1.43-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 523
diff changeset
778 || err == NGX_ECONNRESET
2774
baad3036086e Winsock uses ECONNABORTED instead of ECONNRESET
Igor Sysoev <igor@sysoev.ru>
parents: 2725
diff changeset
779 #if (NGX_WIN32)
baad3036086e Winsock uses ECONNABORTED instead of ECONNRESET
Igor Sysoev <igor@sysoev.ru>
parents: 2725
diff changeset
780 || err == NGX_ECONNABORTED
baad3036086e Winsock uses ECONNABORTED instead of ECONNRESET
Igor Sysoev <igor@sysoev.ru>
parents: 2725
diff changeset
781 #else
278
0ba4821f4460 nginx-0.0.2-2004-03-04-10:04:55 import
Igor Sysoev <igor@sysoev.ru>
parents: 257
diff changeset
782 || err == NGX_EPIPE
0ba4821f4460 nginx-0.0.2-2004-03-04-10:04:55 import
Igor Sysoev <igor@sysoev.ru>
parents: 257
diff changeset
783 #endif
288
f81d075ad172 nginx-0.0.2-2004-03-14-23:46:25 import
Igor Sysoev <igor@sysoev.ru>
parents: 282
diff changeset
784 || err == NGX_ENOTCONN
587
284cc140593b nginx-0.3.15-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
785 || 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
786 || err == NGX_ECONNREFUSED
1869
192443881e51 add NGX_ENETDOWN, NGX_ENETUNREACH, and NGX_EHOSTDOWN
Igor Sysoev <igor@sysoev.ru>
parents: 1833
diff changeset
787 || err == NGX_ENETDOWN
192443881e51 add NGX_ENETDOWN, NGX_ENETUNREACH, and NGX_EHOSTDOWN
Igor Sysoev <igor@sysoev.ru>
parents: 1833
diff changeset
788 || err == NGX_ENETUNREACH
192443881e51 add NGX_ENETDOWN, NGX_ENETUNREACH, and NGX_EHOSTDOWN
Igor Sysoev <igor@sysoev.ru>
parents: 1833
diff changeset
789 || err == NGX_EHOSTDOWN
288
f81d075ad172 nginx-0.0.2-2004-03-14-23:46:25 import
Igor Sysoev <igor@sysoev.ru>
parents: 282
diff changeset
790 || err == NGX_EHOSTUNREACH)
278
0ba4821f4460 nginx-0.0.2-2004-03-04-10:04:55 import
Igor Sysoev <igor@sysoev.ru>
parents: 257
diff changeset
791 {
256
8e39cab6abd5 nginx-0.0.2-2004-02-10-19:23:38 import
Igor Sysoev <igor@sysoev.ru>
parents: 253
diff changeset
792 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
793
2560
a7443674e429 ignore EINVAL from setsockopt() on Solaris
Igor Sysoev <igor@sysoev.ru>
parents: 2512
diff changeset
794 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
795 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
796 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
797 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
798 break;
b6793bc5034b nginx-0.0.2-2004-02-09-10:46:43 import
Igor Sysoev <igor@sysoev.ru>
parents: 242
diff changeset
799
b6793bc5034b nginx-0.0.2-2004-02-09-10:46:43 import
Igor Sysoev <igor@sysoev.ru>
parents: 242
diff changeset
800 case NGX_ERROR_ERR:
b6793bc5034b nginx-0.0.2-2004-02-09-10:46:43 import
Igor Sysoev <igor@sysoev.ru>
parents: 242
diff changeset
801 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
802 break;
b6793bc5034b nginx-0.0.2-2004-02-09-10:46:43 import
Igor Sysoev <igor@sysoev.ru>
parents: 242
diff changeset
803
b6793bc5034b nginx-0.0.2-2004-02-09-10:46:43 import
Igor Sysoev <igor@sysoev.ru>
parents: 242
diff changeset
804 default:
1917
1b2e83c4886d decrease log level of connection errors while closing socket
Igor Sysoev <igor@sysoev.ru>
parents: 1869
diff changeset
805 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
806 }
b6793bc5034b nginx-0.0.2-2004-02-09-10:46:43 import
Igor Sysoev <igor@sysoev.ru>
parents: 242
diff changeset
807
b6793bc5034b nginx-0.0.2-2004-02-09-10:46:43 import
Igor Sysoev <igor@sysoev.ru>
parents: 242
diff changeset
808 } else {
1917
1b2e83c4886d decrease log level of connection errors while closing socket
Igor Sysoev <igor@sysoev.ru>
parents: 1869
diff changeset
809 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
810 }
b6793bc5034b nginx-0.0.2-2004-02-09-10:46:43 import
Igor Sysoev <igor@sysoev.ru>
parents: 242
diff changeset
811
b6793bc5034b nginx-0.0.2-2004-02-09-10:46:43 import
Igor Sysoev <igor@sysoev.ru>
parents: 242
diff changeset
812 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
813
b6793bc5034b nginx-0.0.2-2004-02-09-10:46:43 import
Igor Sysoev <igor@sysoev.ru>
parents: 242
diff changeset
814 return NGX_ERROR;
b6793bc5034b nginx-0.0.2-2004-02-09-10:46:43 import
Igor Sysoev <igor@sysoev.ru>
parents: 242
diff changeset
815 }