Mercurial > hg > nginx-quic
annotate src/event/ngx_event_accept.c @ 7405:d1525e45255a stable-1.14
Version bump.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Mon, 03 Dec 2018 20:07:36 +0300 |
parents | fef61d26da39 |
children | d0b897c0bb5b |
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:
431
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:
431
diff
changeset
|
2 /* |
444
42d11f017717
nginx-0.1.0-2004-09-29-20:00:49 import; remove years from copyright
Igor Sysoev <igor@sysoev.ru>
parents:
441
diff
changeset
|
3 * Copyright (C) Igor Sysoev |
4412 | 4 * Copyright (C) Nginx, Inc. |
441
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
431
diff
changeset
|
5 */ |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
431
diff
changeset
|
6 |
97
70d2345a903f
nginx-0.0.1-2003-05-29-17:02:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
96
diff
changeset
|
7 |
70d2345a903f
nginx-0.0.1-2003-05-29-17:02:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
96
diff
changeset
|
8 #include <ngx_config.h> |
70d2345a903f
nginx-0.0.1-2003-05-29-17:02:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
96
diff
changeset
|
9 #include <ngx_core.h> |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
98
diff
changeset
|
10 #include <ngx_event.h> |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
11 |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
12 |
573 | 13 static ngx_int_t ngx_enable_accept_events(ngx_cycle_t *cycle); |
6153
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
14 static ngx_int_t ngx_disable_accept_events(ngx_cycle_t *cycle, ngx_uint_t all); |
543 | 15 static void ngx_close_accepted_connection(ngx_connection_t *c); |
6436 | 16 #if (NGX_DEBUG) |
17 static void ngx_debug_accepted_connection(ngx_event_conf_t *ecf, | |
18 ngx_connection_t *c); | |
19 #endif | |
191
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
164
diff
changeset
|
20 |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
164
diff
changeset
|
21 |
493 | 22 void |
23 ngx_event_accept(ngx_event_t *ev) | |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
24 { |
714 | 25 socklen_t socklen; |
483 | 26 ngx_err_t err; |
27 ngx_log_t *log; | |
4618
c05cfc46b3bc
Accept moderation in case of EMFILE/ENFILE.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4613
diff
changeset
|
28 ngx_uint_t level; |
483 | 29 ngx_socket_t s; |
30 ngx_event_t *rev, *wev; | |
6559
adf25b8d0431
Introduced the ngx_sockaddr_t type.
Ruslan Ermilov <ru@nginx.com>
parents:
6532
diff
changeset
|
31 ngx_sockaddr_t sa; |
543 | 32 ngx_listening_t *ls; |
33 ngx_connection_t *c, *lc; | |
483 | 34 ngx_event_conf_t *ecf; |
3812
ef27dc1a7832
fallback to accept() if accept4() is not implemented,
Igor Sysoev <igor@sysoev.ru>
parents:
3786
diff
changeset
|
35 #if (NGX_HAVE_ACCEPT4) |
ef27dc1a7832
fallback to accept() if accept4() is not implemented,
Igor Sysoev <igor@sysoev.ru>
parents:
3786
diff
changeset
|
36 static ngx_uint_t use_accept4 = 1; |
ef27dc1a7832
fallback to accept() if accept4() is not implemented,
Igor Sysoev <igor@sysoev.ru>
parents:
3786
diff
changeset
|
37 #endif |
26
53cb81681040
nginx-0.0.1-2002-12-15-09:25:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
24
diff
changeset
|
38 |
4618
c05cfc46b3bc
Accept moderation in case of EMFILE/ENFILE.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4613
diff
changeset
|
39 if (ev->timedout) { |
c05cfc46b3bc
Accept moderation in case of EMFILE/ENFILE.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4613
diff
changeset
|
40 if (ngx_enable_accept_events((ngx_cycle_t *) ngx_cycle) != NGX_OK) { |
c05cfc46b3bc
Accept moderation in case of EMFILE/ENFILE.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4613
diff
changeset
|
41 return; |
c05cfc46b3bc
Accept moderation in case of EMFILE/ENFILE.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4613
diff
changeset
|
42 } |
c05cfc46b3bc
Accept moderation in case of EMFILE/ENFILE.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4613
diff
changeset
|
43 |
c05cfc46b3bc
Accept moderation in case of EMFILE/ENFILE.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4613
diff
changeset
|
44 ev->timedout = 0; |
c05cfc46b3bc
Accept moderation in case of EMFILE/ENFILE.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4613
diff
changeset
|
45 } |
c05cfc46b3bc
Accept moderation in case of EMFILE/ENFILE.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4613
diff
changeset
|
46 |
114
ac69ab96328d
nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
113
diff
changeset
|
47 ecf = ngx_event_get_conf(ngx_cycle->conf_ctx, ngx_event_core_module); |
97
70d2345a903f
nginx-0.0.1-2003-05-29-17:02:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
96
diff
changeset
|
48 |
6126
adba26ff70b5
Removed the obsolete rtsig module.
Ruslan Ermilov <ru@nginx.com>
parents:
6125
diff
changeset
|
49 if (!(ngx_event_flags & NGX_USE_KQUEUE_EVENT)) { |
248
e885208c518b
nginx-0.0.2-2004-02-03-00:19:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
247
diff
changeset
|
50 ev->available = ecf->multi_accept; |
e885208c518b
nginx-0.0.2-2004-02-03-00:19:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
247
diff
changeset
|
51 } |
e885208c518b
nginx-0.0.2-2004-02-03-00:19:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
247
diff
changeset
|
52 |
543 | 53 lc = ev->data; |
54 ls = lc->listening; | |
55 ev->ready = 0; | |
57
a499e0d1f16e
nginx-0.0.1-2003-01-30-10:28:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
44
diff
changeset
|
56 |
257
70e1c7d2b83d
nginx-0.0.2-2004-02-11-20:08:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
253
diff
changeset
|
57 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, ev->log, 0, |
543 | 58 "accept on %V, ready: %d", &ls->addr_text, ev->available); |
57
a499e0d1f16e
nginx-0.0.1-2003-01-30-10:28:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
44
diff
changeset
|
59 |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
60 do { |
6559
adf25b8d0431
Introduced the ngx_sockaddr_t type.
Ruslan Ermilov <ru@nginx.com>
parents:
6532
diff
changeset
|
61 socklen = sizeof(ngx_sockaddr_t); |
191
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
164
diff
changeset
|
62 |
3786 | 63 #if (NGX_HAVE_ACCEPT4) |
3812
ef27dc1a7832
fallback to accept() if accept4() is not implemented,
Igor Sysoev <igor@sysoev.ru>
parents:
3786
diff
changeset
|
64 if (use_accept4) { |
6559
adf25b8d0431
Introduced the ngx_sockaddr_t type.
Ruslan Ermilov <ru@nginx.com>
parents:
6532
diff
changeset
|
65 s = accept4(lc->fd, &sa.sockaddr, &socklen, SOCK_NONBLOCK); |
3812
ef27dc1a7832
fallback to accept() if accept4() is not implemented,
Igor Sysoev <igor@sysoev.ru>
parents:
3786
diff
changeset
|
66 } else { |
6559
adf25b8d0431
Introduced the ngx_sockaddr_t type.
Ruslan Ermilov <ru@nginx.com>
parents:
6532
diff
changeset
|
67 s = accept(lc->fd, &sa.sockaddr, &socklen); |
3812
ef27dc1a7832
fallback to accept() if accept4() is not implemented,
Igor Sysoev <igor@sysoev.ru>
parents:
3786
diff
changeset
|
68 } |
3786 | 69 #else |
6559
adf25b8d0431
Introduced the ngx_sockaddr_t type.
Ruslan Ermilov <ru@nginx.com>
parents:
6532
diff
changeset
|
70 s = accept(lc->fd, &sa.sockaddr, &socklen); |
3786 | 71 #endif |
477 | 72 |
5360
3d2d3e1cf427
Win32: MinGW GCC compatibility.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5359
diff
changeset
|
73 if (s == (ngx_socket_t) -1) { |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
74 err = ngx_socket_errno; |
57
a499e0d1f16e
nginx-0.0.1-2003-01-30-10:28:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
44
diff
changeset
|
75 |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
76 if (err == NGX_EAGAIN) { |
719
f30b1a75fd3b
Solaris 10 event ports support
Igor Sysoev <igor@sysoev.ru>
parents:
714
diff
changeset
|
77 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, ev->log, err, |
f30b1a75fd3b
Solaris 10 event ports support
Igor Sysoev <igor@sysoev.ru>
parents:
714
diff
changeset
|
78 "accept() not ready"); |
87
5f6d848dcbef
nginx-0.0.1-2003-05-13-20:02:32 import
Igor Sysoev <igor@sysoev.ru>
parents:
86
diff
changeset
|
79 return; |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
80 } |
6
669801705ab1
nginx-0.0.1-2002-08-26-19:18:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
3
diff
changeset
|
81 |
4618
c05cfc46b3bc
Accept moderation in case of EMFILE/ENFILE.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4613
diff
changeset
|
82 level = NGX_LOG_ALERT; |
c05cfc46b3bc
Accept moderation in case of EMFILE/ENFILE.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4613
diff
changeset
|
83 |
c05cfc46b3bc
Accept moderation in case of EMFILE/ENFILE.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4613
diff
changeset
|
84 if (err == NGX_ECONNABORTED) { |
c05cfc46b3bc
Accept moderation in case of EMFILE/ENFILE.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4613
diff
changeset
|
85 level = NGX_LOG_ERR; |
c05cfc46b3bc
Accept moderation in case of EMFILE/ENFILE.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4613
diff
changeset
|
86 |
c05cfc46b3bc
Accept moderation in case of EMFILE/ENFILE.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4613
diff
changeset
|
87 } else if (err == NGX_EMFILE || err == NGX_ENFILE) { |
c05cfc46b3bc
Accept moderation in case of EMFILE/ENFILE.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4613
diff
changeset
|
88 level = NGX_LOG_CRIT; |
c05cfc46b3bc
Accept moderation in case of EMFILE/ENFILE.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4613
diff
changeset
|
89 } |
c05cfc46b3bc
Accept moderation in case of EMFILE/ENFILE.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4613
diff
changeset
|
90 |
3813
c870fb78550c
fix building by msvc8 introduced by the previous commit
Igor Sysoev <igor@sysoev.ru>
parents:
3812
diff
changeset
|
91 #if (NGX_HAVE_ACCEPT4) |
4618
c05cfc46b3bc
Accept moderation in case of EMFILE/ENFILE.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4613
diff
changeset
|
92 ngx_log_error(level, ev->log, err, |
3812
ef27dc1a7832
fallback to accept() if accept4() is not implemented,
Igor Sysoev <igor@sysoev.ru>
parents:
3786
diff
changeset
|
93 use_accept4 ? "accept4() failed" : "accept() failed"); |
ef27dc1a7832
fallback to accept() if accept4() is not implemented,
Igor Sysoev <igor@sysoev.ru>
parents:
3786
diff
changeset
|
94 |
ef27dc1a7832
fallback to accept() if accept4() is not implemented,
Igor Sysoev <igor@sysoev.ru>
parents:
3786
diff
changeset
|
95 if (use_accept4 && err == NGX_ENOSYS) { |
ef27dc1a7832
fallback to accept() if accept4() is not implemented,
Igor Sysoev <igor@sysoev.ru>
parents:
3786
diff
changeset
|
96 use_accept4 = 0; |
ef27dc1a7832
fallback to accept() if accept4() is not implemented,
Igor Sysoev <igor@sysoev.ru>
parents:
3786
diff
changeset
|
97 ngx_inherited_nonblocking = 0; |
ef27dc1a7832
fallback to accept() if accept4() is not implemented,
Igor Sysoev <igor@sysoev.ru>
parents:
3786
diff
changeset
|
98 continue; |
ef27dc1a7832
fallback to accept() if accept4() is not implemented,
Igor Sysoev <igor@sysoev.ru>
parents:
3786
diff
changeset
|
99 } |
3813
c870fb78550c
fix building by msvc8 introduced by the previous commit
Igor Sysoev <igor@sysoev.ru>
parents:
3812
diff
changeset
|
100 #else |
4618
c05cfc46b3bc
Accept moderation in case of EMFILE/ENFILE.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4613
diff
changeset
|
101 ngx_log_error(level, ev->log, err, "accept() failed"); |
3812
ef27dc1a7832
fallback to accept() if accept4() is not implemented,
Igor Sysoev <igor@sysoev.ru>
parents:
3786
diff
changeset
|
102 #endif |
97
70d2345a903f
nginx-0.0.1-2003-05-29-17:02:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
96
diff
changeset
|
103 |
248
e885208c518b
nginx-0.0.2-2004-02-03-00:19:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
247
diff
changeset
|
104 if (err == NGX_ECONNABORTED) { |
455 | 105 if (ngx_event_flags & NGX_USE_KQUEUE_EVENT) { |
248
e885208c518b
nginx-0.0.2-2004-02-03-00:19:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
247
diff
changeset
|
106 ev->available--; |
e885208c518b
nginx-0.0.2-2004-02-03-00:19:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
247
diff
changeset
|
107 } |
e885208c518b
nginx-0.0.2-2004-02-03-00:19:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
247
diff
changeset
|
108 |
e885208c518b
nginx-0.0.2-2004-02-03-00:19:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
247
diff
changeset
|
109 if (ev->available) { |
e885208c518b
nginx-0.0.2-2004-02-03-00:19:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
247
diff
changeset
|
110 continue; |
e885208c518b
nginx-0.0.2-2004-02-03-00:19:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
247
diff
changeset
|
111 } |
e885208c518b
nginx-0.0.2-2004-02-03-00:19:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
247
diff
changeset
|
112 } |
e885208c518b
nginx-0.0.2-2004-02-03-00:19:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
247
diff
changeset
|
113 |
4618
c05cfc46b3bc
Accept moderation in case of EMFILE/ENFILE.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4613
diff
changeset
|
114 if (err == NGX_EMFILE || err == NGX_ENFILE) { |
6153
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
115 if (ngx_disable_accept_events((ngx_cycle_t *) ngx_cycle, 1) |
4618
c05cfc46b3bc
Accept moderation in case of EMFILE/ENFILE.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4613
diff
changeset
|
116 != NGX_OK) |
c05cfc46b3bc
Accept moderation in case of EMFILE/ENFILE.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4613
diff
changeset
|
117 { |
c05cfc46b3bc
Accept moderation in case of EMFILE/ENFILE.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4613
diff
changeset
|
118 return; |
c05cfc46b3bc
Accept moderation in case of EMFILE/ENFILE.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4613
diff
changeset
|
119 } |
c05cfc46b3bc
Accept moderation in case of EMFILE/ENFILE.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4613
diff
changeset
|
120 |
c05cfc46b3bc
Accept moderation in case of EMFILE/ENFILE.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4613
diff
changeset
|
121 if (ngx_use_accept_mutex) { |
c05cfc46b3bc
Accept moderation in case of EMFILE/ENFILE.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4613
diff
changeset
|
122 if (ngx_accept_mutex_held) { |
c05cfc46b3bc
Accept moderation in case of EMFILE/ENFILE.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4613
diff
changeset
|
123 ngx_shmtx_unlock(&ngx_accept_mutex); |
c05cfc46b3bc
Accept moderation in case of EMFILE/ENFILE.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4613
diff
changeset
|
124 ngx_accept_mutex_held = 0; |
c05cfc46b3bc
Accept moderation in case of EMFILE/ENFILE.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4613
diff
changeset
|
125 } |
c05cfc46b3bc
Accept moderation in case of EMFILE/ENFILE.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4613
diff
changeset
|
126 |
c05cfc46b3bc
Accept moderation in case of EMFILE/ENFILE.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4613
diff
changeset
|
127 ngx_accept_disabled = 1; |
c05cfc46b3bc
Accept moderation in case of EMFILE/ENFILE.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4613
diff
changeset
|
128 |
c05cfc46b3bc
Accept moderation in case of EMFILE/ENFILE.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4613
diff
changeset
|
129 } else { |
c05cfc46b3bc
Accept moderation in case of EMFILE/ENFILE.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4613
diff
changeset
|
130 ngx_add_timer(ev, ecf->accept_mutex_delay); |
c05cfc46b3bc
Accept moderation in case of EMFILE/ENFILE.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4613
diff
changeset
|
131 } |
c05cfc46b3bc
Accept moderation in case of EMFILE/ENFILE.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4613
diff
changeset
|
132 } |
c05cfc46b3bc
Accept moderation in case of EMFILE/ENFILE.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4613
diff
changeset
|
133 |
97
70d2345a903f
nginx-0.0.1-2003-05-29-17:02:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
96
diff
changeset
|
134 return; |
70d2345a903f
nginx-0.0.1-2003-05-29-17:02:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
96
diff
changeset
|
135 } |
70d2345a903f
nginx-0.0.1-2003-05-29-17:02:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
96
diff
changeset
|
136 |
426
3f88935a02e8
nginx-0.0.10-2004-09-14-23:39:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
425
diff
changeset
|
137 #if (NGX_STAT_STUB) |
2951
5acd98486a33
ignore ngx_atomic_fetch_add() result
Igor Sysoev <igor@sysoev.ru>
parents:
2723
diff
changeset
|
138 (void) ngx_atomic_fetch_add(ngx_stat_accepted, 1); |
426
3f88935a02e8
nginx-0.0.10-2004-09-14-23:39:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
425
diff
changeset
|
139 #endif |
323
ba876b26b76d
nginx-0.0.3-2004-04-21-22:54:33 import
Igor Sysoev <igor@sysoev.ru>
parents:
315
diff
changeset
|
140 |
2255 | 141 ngx_accept_disabled = ngx_cycle->connection_n / 8 |
543 | 142 - ngx_cycle->free_connection_n; |
143 | |
144 c = ngx_get_connection(s, ev->log); | |
323
ba876b26b76d
nginx-0.0.3-2004-04-21-22:54:33 import
Igor Sysoev <igor@sysoev.ru>
parents:
315
diff
changeset
|
145 |
543 | 146 if (c == NULL) { |
147 if (ngx_close_socket(s) == -1) { | |
148 ngx_log_error(NGX_LOG_ALERT, ev->log, ngx_socket_errno, | |
149 ngx_close_socket_n " failed"); | |
150 } | |
119
cd54bcbaf3b5
nginx-0.0.1-2003-07-21-01:15:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
117
diff
changeset
|
151 |
543 | 152 return; |
153 } | |
154 | |
6436 | 155 c->type = SOCK_STREAM; |
156 | |
635 | 157 #if (NGX_STAT_STUB) |
2951
5acd98486a33
ignore ngx_atomic_fetch_add() result
Igor Sysoev <igor@sysoev.ru>
parents:
2723
diff
changeset
|
158 (void) ngx_atomic_fetch_add(ngx_stat_active, 1); |
635 | 159 #endif |
160 | |
543 | 161 c->pool = ngx_create_pool(ls->pool_size, ev->log); |
162 if (c->pool == NULL) { | |
163 ngx_close_accepted_connection(c); | |
164 return; | |
165 } | |
97
70d2345a903f
nginx-0.0.1-2003-05-29-17:02:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
96
diff
changeset
|
166 |
7119
fef61d26da39
Fixed buffer overread with unix sockets after accept().
Maxim Dounin <mdounin@mdounin.ru>
parents:
7005
diff
changeset
|
167 if (socklen > (socklen_t) sizeof(ngx_sockaddr_t)) { |
fef61d26da39
Fixed buffer overread with unix sockets after accept().
Maxim Dounin <mdounin@mdounin.ru>
parents:
7005
diff
changeset
|
168 socklen = sizeof(ngx_sockaddr_t); |
fef61d26da39
Fixed buffer overread with unix sockets after accept().
Maxim Dounin <mdounin@mdounin.ru>
parents:
7005
diff
changeset
|
169 } |
fef61d26da39
Fixed buffer overread with unix sockets after accept().
Maxim Dounin <mdounin@mdounin.ru>
parents:
7005
diff
changeset
|
170 |
714 | 171 c->sockaddr = ngx_palloc(c->pool, socklen); |
543 | 172 if (c->sockaddr == NULL) { |
173 ngx_close_accepted_connection(c); | |
174 return; | |
175 } | |
176 | |
6559
adf25b8d0431
Introduced the ngx_sockaddr_t type.
Ruslan Ermilov <ru@nginx.com>
parents:
6532
diff
changeset
|
177 ngx_memcpy(c->sockaddr, &sa, socklen); |
543 | 178 |
179 log = ngx_palloc(c->pool, sizeof(ngx_log_t)); | |
180 if (log == NULL) { | |
181 ngx_close_accepted_connection(c); | |
87
5f6d848dcbef
nginx-0.0.1-2003-05-13-20:02:32 import
Igor Sysoev <igor@sysoev.ru>
parents:
86
diff
changeset
|
182 return; |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
183 } |
6
669801705ab1
nginx-0.0.1-2002-08-26-19:18:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
3
diff
changeset
|
184 |
6125
4dc8e7b62216
Removed the obsolete aio module.
Ruslan Ermilov <ru@nginx.com>
parents:
5820
diff
changeset
|
185 /* set a blocking mode for iocp and non-blocking mode for others */ |
59
e8cdc2989cee
nginx-0.0.1-2003-02-06-20:21:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
57
diff
changeset
|
186 |
93
738fe44c70d5
nginx-0.0.1-2003-05-21-17:28:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
92
diff
changeset
|
187 if (ngx_inherited_nonblocking) { |
6125
4dc8e7b62216
Removed the obsolete aio module.
Ruslan Ermilov <ru@nginx.com>
parents:
5820
diff
changeset
|
188 if (ngx_event_flags & NGX_USE_IOCP_EVENT) { |
93
738fe44c70d5
nginx-0.0.1-2003-05-21-17:28:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
92
diff
changeset
|
189 if (ngx_blocking(s) == -1) { |
543 | 190 ngx_log_error(NGX_LOG_ALERT, ev->log, ngx_socket_errno, |
191
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
164
diff
changeset
|
191 ngx_blocking_n " failed"); |
543 | 192 ngx_close_accepted_connection(c); |
93
738fe44c70d5
nginx-0.0.1-2003-05-21-17:28:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
92
diff
changeset
|
193 return; |
738fe44c70d5
nginx-0.0.1-2003-05-21-17:28:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
92
diff
changeset
|
194 } |
738fe44c70d5
nginx-0.0.1-2003-05-21-17:28:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
92
diff
changeset
|
195 } |
738fe44c70d5
nginx-0.0.1-2003-05-21-17:28:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
92
diff
changeset
|
196 |
738fe44c70d5
nginx-0.0.1-2003-05-21-17:28:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
92
diff
changeset
|
197 } else { |
6126
adba26ff70b5
Removed the obsolete rtsig module.
Ruslan Ermilov <ru@nginx.com>
parents:
6125
diff
changeset
|
198 if (!(ngx_event_flags & NGX_USE_IOCP_EVENT)) { |
93
738fe44c70d5
nginx-0.0.1-2003-05-21-17:28:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
92
diff
changeset
|
199 if (ngx_nonblocking(s) == -1) { |
543 | 200 ngx_log_error(NGX_LOG_ALERT, ev->log, ngx_socket_errno, |
191
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
164
diff
changeset
|
201 ngx_nonblocking_n " failed"); |
543 | 202 ngx_close_accepted_connection(c); |
93
738fe44c70d5
nginx-0.0.1-2003-05-21-17:28:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
92
diff
changeset
|
203 return; |
738fe44c70d5
nginx-0.0.1-2003-05-21-17:28:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
92
diff
changeset
|
204 } |
59
e8cdc2989cee
nginx-0.0.1-2003-02-06-20:21:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
57
diff
changeset
|
205 } |
e8cdc2989cee
nginx-0.0.1-2003-02-06-20:21:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
57
diff
changeset
|
206 } |
e8cdc2989cee
nginx-0.0.1-2003-02-06-20:21:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
57
diff
changeset
|
207 |
543 | 208 *log = ls->log; |
209 | |
210 c->recv = ngx_recv; | |
211 c->send = ngx_send; | |
577 | 212 c->recv_chain = ngx_recv_chain; |
543 | 213 c->send_chain = ngx_send_chain; |
103
6dfda4cf5200
nginx-0.0.1-2003-06-11-19:28:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
214 |
543 | 215 c->log = log; |
216 c->pool->log = log; | |
103
6dfda4cf5200
nginx-0.0.1-2003-06-11-19:28:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
217 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2255
diff
changeset
|
218 c->socklen = socklen; |
543 | 219 c->listening = ls; |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2255
diff
changeset
|
220 c->local_sockaddr = ls->sockaddr; |
5463
1ab1cf63f885
Core: keep the length of the local sockaddr.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
221 c->local_socklen = ls->socklen; |
543 | 222 |
3230
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
2951
diff
changeset
|
223 #if (NGX_HAVE_UNIX_DOMAIN) |
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
2951
diff
changeset
|
224 if (c->sockaddr->sa_family == AF_UNIX) { |
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
2951
diff
changeset
|
225 c->tcp_nopush = NGX_TCP_NOPUSH_DISABLED; |
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
2951
diff
changeset
|
226 c->tcp_nodelay = NGX_TCP_NODELAY_DISABLED; |
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
2951
diff
changeset
|
227 #if (NGX_SOLARIS) |
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
2951
diff
changeset
|
228 /* Solaris's sendfilev() supports AF_NCA, AF_INET, and AF_INET6 */ |
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
2951
diff
changeset
|
229 c->sendfile = 0; |
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
2951
diff
changeset
|
230 #endif |
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
2951
diff
changeset
|
231 } |
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
2951
diff
changeset
|
232 #endif |
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
2951
diff
changeset
|
233 |
561 | 234 rev = c->read; |
235 wev = c->write; | |
86
3973260705cc
nginx-0.0.1-2003-05-12-19:52:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
75
diff
changeset
|
236 |
164
84036764e215
nginx-0.0.1-2003-10-29-11:30:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
121
diff
changeset
|
237 wev->ready = 1; |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
238 |
6126
adba26ff70b5
Removed the obsolete rtsig module.
Ruslan Ermilov <ru@nginx.com>
parents:
6125
diff
changeset
|
239 if (ngx_event_flags & NGX_USE_IOCP_EVENT) { |
164
84036764e215
nginx-0.0.1-2003-10-29-11:30:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
121
diff
changeset
|
240 rev->ready = 1; |
59
e8cdc2989cee
nginx-0.0.1-2003-02-06-20:21:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
57
diff
changeset
|
241 } |
e8cdc2989cee
nginx-0.0.1-2003-02-06-20:21:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
57
diff
changeset
|
242 |
245
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
236
diff
changeset
|
243 if (ev->deferred_accept) { |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
236
diff
changeset
|
244 rev->ready = 1; |
7005
3e2d90073adf
Fixed deferred accept with EPOLLRDHUP enabled (ticket #1278).
Roman Arutyunyan <arut@nginx.com>
parents:
6692
diff
changeset
|
245 #if (NGX_HAVE_KQUEUE || NGX_HAVE_EPOLLRDHUP) |
523 | 246 rev->available = 1; |
247 #endif | |
245
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
236
diff
changeset
|
248 } |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
236
diff
changeset
|
249 |
191
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
164
diff
changeset
|
250 rev->log = log; |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
164
diff
changeset
|
251 wev->log = log; |
57
a499e0d1f16e
nginx-0.0.1-2003-01-30-10:28:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
44
diff
changeset
|
252 |
208
0b67be7d4489
nginx-0.0.1-2003-12-08-23:48:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
206
diff
changeset
|
253 /* |
561 | 254 * TODO: MT: - ngx_atomic_fetch_add() |
266
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
260
diff
changeset
|
255 * or protection by critical section or light mutex |
208
0b67be7d4489
nginx-0.0.1-2003-12-08-23:48:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
206
diff
changeset
|
256 * |
0b67be7d4489
nginx-0.0.1-2003-12-08-23:48:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
206
diff
changeset
|
257 * TODO: MP: - allocated in a shared memory |
561 | 258 * - ngx_atomic_fetch_add() |
266
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
260
diff
changeset
|
259 * or protection by critical section or light mutex |
208
0b67be7d4489
nginx-0.0.1-2003-12-08-23:48:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
206
diff
changeset
|
260 */ |
212
679f60139863
nginx-0.0.1-2003-12-19-11:15:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
261 |
561 | 262 c->number = ngx_atomic_fetch_add(ngx_connection_counter, 1); |
26
53cb81681040
nginx-0.0.1-2002-12-15-09:25:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
24
diff
changeset
|
263 |
495 | 264 #if (NGX_STAT_STUB) |
2951
5acd98486a33
ignore ngx_atomic_fetch_add() result
Igor Sysoev <igor@sysoev.ru>
parents:
2723
diff
changeset
|
265 (void) ngx_atomic_fetch_add(ngx_stat_handled, 1); |
495 | 266 #endif |
267 | |
543 | 268 if (ls->addr_ntop) { |
2049 | 269 c->addr_text.data = ngx_pnalloc(c->pool, ls->addr_text_max_len); |
419
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
396
diff
changeset
|
270 if (c->addr_text.data == NULL) { |
543 | 271 ngx_close_accepted_connection(c); |
419
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
396
diff
changeset
|
272 return; |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
396
diff
changeset
|
273 } |
577 | 274 |
5263
05ba5bce31e0
Core: extended ngx_sock_ntop() with socklen parameter.
Vladimir Homutov <vl@nginx.com>
parents:
4618
diff
changeset
|
275 c->addr_text.len = ngx_sock_ntop(c->sockaddr, c->socklen, |
05ba5bce31e0
Core: extended ngx_sock_ntop() with socklen parameter.
Vladimir Homutov <vl@nginx.com>
parents:
4618
diff
changeset
|
276 c->addr_text.data, |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2255
diff
changeset
|
277 ls->addr_text_max_len, 0); |
419
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
396
diff
changeset
|
278 if (c->addr_text.len == 0) { |
543 | 279 ngx_close_accepted_connection(c); |
419
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
396
diff
changeset
|
280 return; |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
396
diff
changeset
|
281 } |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
396
diff
changeset
|
282 } |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
396
diff
changeset
|
283 |
307
ce375c313e96
nginx-0.0.3-2004-04-08-19:58:25 import
Igor Sysoev <igor@sysoev.ru>
parents:
306
diff
changeset
|
284 #if (NGX_DEBUG) |
ce375c313e96
nginx-0.0.3-2004-04-08-19:58:25 import
Igor Sysoev <igor@sysoev.ru>
parents:
306
diff
changeset
|
285 { |
6436 | 286 ngx_str_t addr; |
287 u_char text[NGX_SOCKADDR_STRLEN]; | |
307
ce375c313e96
nginx-0.0.3-2004-04-08-19:58:25 import
Igor Sysoev <igor@sysoev.ru>
parents:
306
diff
changeset
|
288 |
6436 | 289 ngx_debug_accepted_connection(ecf, c); |
307
ce375c313e96
nginx-0.0.3-2004-04-08-19:58:25 import
Igor Sysoev <igor@sysoev.ru>
parents:
306
diff
changeset
|
290 |
5704
524741fd50ed
Core: output client port number when logging accept event.
Ruslan Ermilov <ru@nginx.com>
parents:
5600
diff
changeset
|
291 if (log->log_level & NGX_LOG_DEBUG_EVENT) { |
524741fd50ed
Core: output client port number when logging accept event.
Ruslan Ermilov <ru@nginx.com>
parents:
5600
diff
changeset
|
292 addr.data = text; |
524741fd50ed
Core: output client port number when logging accept event.
Ruslan Ermilov <ru@nginx.com>
parents:
5600
diff
changeset
|
293 addr.len = ngx_sock_ntop(c->sockaddr, c->socklen, text, |
524741fd50ed
Core: output client port number when logging accept event.
Ruslan Ermilov <ru@nginx.com>
parents:
5600
diff
changeset
|
294 NGX_SOCKADDR_STRLEN, 1); |
524741fd50ed
Core: output client port number when logging accept event.
Ruslan Ermilov <ru@nginx.com>
parents:
5600
diff
changeset
|
295 |
524741fd50ed
Core: output client port number when logging accept event.
Ruslan Ermilov <ru@nginx.com>
parents:
5600
diff
changeset
|
296 ngx_log_debug3(NGX_LOG_DEBUG_EVENT, log, 0, |
524741fd50ed
Core: output client port number when logging accept event.
Ruslan Ermilov <ru@nginx.com>
parents:
5600
diff
changeset
|
297 "*%uA accept: %V fd:%d", c->number, &addr, s); |
524741fd50ed
Core: output client port number when logging accept event.
Ruslan Ermilov <ru@nginx.com>
parents:
5600
diff
changeset
|
298 } |
524741fd50ed
Core: output client port number when logging accept event.
Ruslan Ermilov <ru@nginx.com>
parents:
5600
diff
changeset
|
299 |
307
ce375c313e96
nginx-0.0.3-2004-04-08-19:58:25 import
Igor Sysoev <igor@sysoev.ru>
parents:
306
diff
changeset
|
300 } |
ce375c313e96
nginx-0.0.3-2004-04-08-19:58:25 import
Igor Sysoev <igor@sysoev.ru>
parents:
306
diff
changeset
|
301 #endif |
ce375c313e96
nginx-0.0.3-2004-04-08-19:58:25 import
Igor Sysoev <igor@sysoev.ru>
parents:
306
diff
changeset
|
302 |
381
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
303 if (ngx_add_conn && (ngx_event_flags & NGX_USE_EPOLL_EVENT) == 0) { |
97
70d2345a903f
nginx-0.0.1-2003-05-29-17:02:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
96
diff
changeset
|
304 if (ngx_add_conn(c) == NGX_ERROR) { |
543 | 305 ngx_close_accepted_connection(c); |
87
5f6d848dcbef
nginx-0.0.1-2003-05-13-20:02:32 import
Igor Sysoev <igor@sysoev.ru>
parents:
86
diff
changeset
|
306 return; |
64
34d647deb1da
nginx-0.0.1-2003-03-04-09:33:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
63
diff
changeset
|
307 } |
34d647deb1da
nginx-0.0.1-2003-03-04-09:33:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
63
diff
changeset
|
308 } |
34d647deb1da
nginx-0.0.1-2003-03-04-09:33:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
63
diff
changeset
|
309 |
191
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
164
diff
changeset
|
310 log->data = NULL; |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
164
diff
changeset
|
311 log->handler = NULL; |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
164
diff
changeset
|
312 |
543 | 313 ls->handler(c); |
57
a499e0d1f16e
nginx-0.0.1-2003-01-30-10:28:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
44
diff
changeset
|
314 |
455 | 315 if (ngx_event_flags & NGX_USE_KQUEUE_EVENT) { |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
316 ev->available--; |
57
a499e0d1f16e
nginx-0.0.1-2003-01-30-10:28:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
44
diff
changeset
|
317 } |
191
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
164
diff
changeset
|
318 |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
319 } while (ev->available); |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
320 } |
191
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
164
diff
changeset
|
321 |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
164
diff
changeset
|
322 |
6436 | 323 #if !(NGX_WIN32) |
324 | |
325 void | |
326 ngx_event_recvmsg(ngx_event_t *ev) | |
327 { | |
328 ssize_t n; | |
329 ngx_log_t *log; | |
330 ngx_err_t err; | |
331 ngx_event_t *rev, *wev; | |
332 struct iovec iov[1]; | |
333 struct msghdr msg; | |
6559
adf25b8d0431
Introduced the ngx_sockaddr_t type.
Ruslan Ermilov <ru@nginx.com>
parents:
6532
diff
changeset
|
334 ngx_sockaddr_t sa; |
6436 | 335 ngx_listening_t *ls; |
336 ngx_event_conf_t *ecf; | |
337 ngx_connection_t *c, *lc; | |
338 static u_char buffer[65535]; | |
339 | |
340 #if (NGX_HAVE_MSGHDR_MSG_CONTROL) | |
341 | |
342 #if (NGX_HAVE_IP_RECVDSTADDR) | |
343 u_char msg_control[CMSG_SPACE(sizeof(struct in_addr))]; | |
344 #elif (NGX_HAVE_IP_PKTINFO) | |
345 u_char msg_control[CMSG_SPACE(sizeof(struct in_pktinfo))]; | |
346 #endif | |
347 | |
348 #if (NGX_HAVE_INET6 && NGX_HAVE_IPV6_RECVPKTINFO) | |
349 u_char msg_control6[CMSG_SPACE(sizeof(struct in6_pktinfo))]; | |
350 #endif | |
351 | |
352 #endif | |
353 | |
354 if (ev->timedout) { | |
355 if (ngx_enable_accept_events((ngx_cycle_t *) ngx_cycle) != NGX_OK) { | |
356 return; | |
357 } | |
358 | |
359 ev->timedout = 0; | |
360 } | |
361 | |
362 ecf = ngx_event_get_conf(ngx_cycle->conf_ctx, ngx_event_core_module); | |
363 | |
364 if (!(ngx_event_flags & NGX_USE_KQUEUE_EVENT)) { | |
365 ev->available = ecf->multi_accept; | |
366 } | |
367 | |
368 lc = ev->data; | |
369 ls = lc->listening; | |
370 ev->ready = 0; | |
371 | |
372 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, ev->log, 0, | |
373 "recvmsg on %V, ready: %d", &ls->addr_text, ev->available); | |
374 | |
375 do { | |
376 ngx_memzero(&msg, sizeof(struct msghdr)); | |
377 | |
378 iov[0].iov_base = (void *) buffer; | |
379 iov[0].iov_len = sizeof(buffer); | |
380 | |
381 msg.msg_name = &sa; | |
6559
adf25b8d0431
Introduced the ngx_sockaddr_t type.
Ruslan Ermilov <ru@nginx.com>
parents:
6532
diff
changeset
|
382 msg.msg_namelen = sizeof(ngx_sockaddr_t); |
6436 | 383 msg.msg_iov = iov; |
384 msg.msg_iovlen = 1; | |
385 | |
386 #if (NGX_HAVE_MSGHDR_MSG_CONTROL) | |
387 | |
388 if (ls->wildcard) { | |
389 | |
390 #if (NGX_HAVE_IP_RECVDSTADDR || NGX_HAVE_IP_PKTINFO) | |
391 if (ls->sockaddr->sa_family == AF_INET) { | |
392 msg.msg_control = &msg_control; | |
393 msg.msg_controllen = sizeof(msg_control); | |
394 } | |
395 #endif | |
396 | |
397 #if (NGX_HAVE_INET6 && NGX_HAVE_IPV6_RECVPKTINFO) | |
398 if (ls->sockaddr->sa_family == AF_INET6) { | |
399 msg.msg_control = &msg_control6; | |
400 msg.msg_controllen = sizeof(msg_control6); | |
401 } | |
402 #endif | |
403 } | |
404 | |
405 #endif | |
406 | |
407 n = recvmsg(lc->fd, &msg, 0); | |
408 | |
409 if (n == -1) { | |
410 err = ngx_socket_errno; | |
411 | |
412 if (err == NGX_EAGAIN) { | |
413 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, ev->log, err, | |
414 "recvmsg() not ready"); | |
415 return; | |
416 } | |
417 | |
418 ngx_log_error(NGX_LOG_ALERT, ev->log, err, "recvmsg() failed"); | |
419 | |
420 return; | |
421 } | |
422 | |
423 #if (NGX_STAT_STUB) | |
424 (void) ngx_atomic_fetch_add(ngx_stat_accepted, 1); | |
425 #endif | |
426 | |
427 #if (NGX_HAVE_MSGHDR_MSG_CONTROL) | |
428 if (msg.msg_flags & (MSG_TRUNC|MSG_CTRUNC)) { | |
429 ngx_log_error(NGX_LOG_ALERT, ev->log, 0, | |
430 "recvmsg() truncated data"); | |
431 continue; | |
432 } | |
433 #endif | |
434 | |
435 ngx_accept_disabled = ngx_cycle->connection_n / 8 | |
436 - ngx_cycle->free_connection_n; | |
437 | |
438 c = ngx_get_connection(lc->fd, ev->log); | |
439 if (c == NULL) { | |
440 return; | |
441 } | |
442 | |
443 c->shared = 1; | |
444 c->type = SOCK_DGRAM; | |
445 c->socklen = msg.msg_namelen; | |
446 | |
7119
fef61d26da39
Fixed buffer overread with unix sockets after accept().
Maxim Dounin <mdounin@mdounin.ru>
parents:
7005
diff
changeset
|
447 if (c->socklen > (socklen_t) sizeof(ngx_sockaddr_t)) { |
fef61d26da39
Fixed buffer overread with unix sockets after accept().
Maxim Dounin <mdounin@mdounin.ru>
parents:
7005
diff
changeset
|
448 c->socklen = sizeof(ngx_sockaddr_t); |
fef61d26da39
Fixed buffer overread with unix sockets after accept().
Maxim Dounin <mdounin@mdounin.ru>
parents:
7005
diff
changeset
|
449 } |
fef61d26da39
Fixed buffer overread with unix sockets after accept().
Maxim Dounin <mdounin@mdounin.ru>
parents:
7005
diff
changeset
|
450 |
6436 | 451 #if (NGX_STAT_STUB) |
452 (void) ngx_atomic_fetch_add(ngx_stat_active, 1); | |
453 #endif | |
454 | |
455 c->pool = ngx_create_pool(ls->pool_size, ev->log); | |
456 if (c->pool == NULL) { | |
457 ngx_close_accepted_connection(c); | |
458 return; | |
459 } | |
460 | |
461 c->sockaddr = ngx_palloc(c->pool, c->socklen); | |
462 if (c->sockaddr == NULL) { | |
463 ngx_close_accepted_connection(c); | |
464 return; | |
465 } | |
466 | |
467 ngx_memcpy(c->sockaddr, msg.msg_name, c->socklen); | |
468 | |
469 log = ngx_palloc(c->pool, sizeof(ngx_log_t)); | |
470 if (log == NULL) { | |
471 ngx_close_accepted_connection(c); | |
472 return; | |
473 } | |
474 | |
475 *log = ls->log; | |
476 | |
477 c->send = ngx_udp_send; | |
6692 | 478 c->send_chain = ngx_udp_send_chain; |
6436 | 479 |
480 c->log = log; | |
481 c->pool->log = log; | |
482 | |
483 c->listening = ls; | |
484 c->local_sockaddr = ls->sockaddr; | |
485 c->local_socklen = ls->socklen; | |
486 | |
487 #if (NGX_HAVE_MSGHDR_MSG_CONTROL) | |
488 | |
489 if (ls->wildcard) { | |
490 struct cmsghdr *cmsg; | |
491 struct sockaddr *sockaddr; | |
492 | |
493 sockaddr = ngx_palloc(c->pool, c->local_socklen); | |
494 if (sockaddr == NULL) { | |
495 ngx_close_accepted_connection(c); | |
496 return; | |
497 } | |
498 | |
499 ngx_memcpy(sockaddr, c->local_sockaddr, c->local_socklen); | |
500 c->local_sockaddr = sockaddr; | |
501 | |
502 for (cmsg = CMSG_FIRSTHDR(&msg); | |
503 cmsg != NULL; | |
504 cmsg = CMSG_NXTHDR(&msg, cmsg)) | |
505 { | |
506 | |
507 #if (NGX_HAVE_IP_RECVDSTADDR) | |
508 | |
509 if (cmsg->cmsg_level == IPPROTO_IP | |
510 && cmsg->cmsg_type == IP_RECVDSTADDR | |
511 && sockaddr->sa_family == AF_INET) | |
512 { | |
513 struct in_addr *addr; | |
514 struct sockaddr_in *sin; | |
515 | |
516 addr = (struct in_addr *) CMSG_DATA(cmsg); | |
517 sin = (struct sockaddr_in *) sockaddr; | |
518 sin->sin_addr = *addr; | |
519 | |
520 break; | |
521 } | |
522 | |
523 #elif (NGX_HAVE_IP_PKTINFO) | |
524 | |
525 if (cmsg->cmsg_level == IPPROTO_IP | |
526 && cmsg->cmsg_type == IP_PKTINFO | |
527 && sockaddr->sa_family == AF_INET) | |
528 { | |
529 struct in_pktinfo *pkt; | |
530 struct sockaddr_in *sin; | |
531 | |
532 pkt = (struct in_pktinfo *) CMSG_DATA(cmsg); | |
533 sin = (struct sockaddr_in *) sockaddr; | |
534 sin->sin_addr = pkt->ipi_addr; | |
535 | |
536 break; | |
537 } | |
538 | |
539 #endif | |
540 | |
541 #if (NGX_HAVE_INET6 && NGX_HAVE_IPV6_RECVPKTINFO) | |
542 | |
543 if (cmsg->cmsg_level == IPPROTO_IPV6 | |
544 && cmsg->cmsg_type == IPV6_PKTINFO | |
545 && sockaddr->sa_family == AF_INET6) | |
546 { | |
547 struct in6_pktinfo *pkt6; | |
548 struct sockaddr_in6 *sin6; | |
549 | |
550 pkt6 = (struct in6_pktinfo *) CMSG_DATA(cmsg); | |
551 sin6 = (struct sockaddr_in6 *) sockaddr; | |
552 sin6->sin6_addr = pkt6->ipi6_addr; | |
553 | |
554 break; | |
555 } | |
556 | |
557 #endif | |
558 | |
559 } | |
560 } | |
561 | |
562 #endif | |
563 | |
564 c->buffer = ngx_create_temp_buf(c->pool, n); | |
565 if (c->buffer == NULL) { | |
566 ngx_close_accepted_connection(c); | |
567 return; | |
568 } | |
569 | |
570 c->buffer->last = ngx_cpymem(c->buffer->last, buffer, n); | |
571 | |
572 rev = c->read; | |
573 wev = c->write; | |
574 | |
575 wev->ready = 1; | |
576 | |
577 rev->log = log; | |
578 wev->log = log; | |
579 | |
580 /* | |
581 * TODO: MT: - ngx_atomic_fetch_add() | |
582 * or protection by critical section or light mutex | |
583 * | |
584 * TODO: MP: - allocated in a shared memory | |
585 * - ngx_atomic_fetch_add() | |
586 * or protection by critical section or light mutex | |
587 */ | |
588 | |
589 c->number = ngx_atomic_fetch_add(ngx_connection_counter, 1); | |
590 | |
591 #if (NGX_STAT_STUB) | |
592 (void) ngx_atomic_fetch_add(ngx_stat_handled, 1); | |
593 #endif | |
594 | |
595 if (ls->addr_ntop) { | |
596 c->addr_text.data = ngx_pnalloc(c->pool, ls->addr_text_max_len); | |
597 if (c->addr_text.data == NULL) { | |
598 ngx_close_accepted_connection(c); | |
599 return; | |
600 } | |
601 | |
602 c->addr_text.len = ngx_sock_ntop(c->sockaddr, c->socklen, | |
603 c->addr_text.data, | |
604 ls->addr_text_max_len, 0); | |
605 if (c->addr_text.len == 0) { | |
606 ngx_close_accepted_connection(c); | |
607 return; | |
608 } | |
609 } | |
610 | |
611 #if (NGX_DEBUG) | |
612 { | |
613 ngx_str_t addr; | |
614 u_char text[NGX_SOCKADDR_STRLEN]; | |
615 | |
616 ngx_debug_accepted_connection(ecf, c); | |
617 | |
618 if (log->log_level & NGX_LOG_DEBUG_EVENT) { | |
619 addr.data = text; | |
620 addr.len = ngx_sock_ntop(c->sockaddr, c->socklen, text, | |
621 NGX_SOCKADDR_STRLEN, 1); | |
622 | |
623 ngx_log_debug4(NGX_LOG_DEBUG_EVENT, log, 0, | |
624 "*%uA recvmsg: %V fd:%d n:%z", | |
625 c->number, &addr, c->fd, n); | |
626 } | |
627 | |
628 } | |
629 #endif | |
630 | |
631 log->data = NULL; | |
632 log->handler = NULL; | |
633 | |
634 ls->handler(c); | |
635 | |
636 if (ngx_event_flags & NGX_USE_KQUEUE_EVENT) { | |
637 ev->available -= n; | |
638 } | |
639 | |
640 } while (ev->available); | |
641 } | |
642 | |
643 #endif | |
644 | |
645 | |
493 | 646 ngx_int_t |
647 ngx_trylock_accept_mutex(ngx_cycle_t *cycle) | |
301
744965ec6275
nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
648 { |
611 | 649 if (ngx_shmtx_trylock(&ngx_accept_mutex)) { |
650 | |
301
744965ec6275
nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
651 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0, |
744965ec6275
nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
652 "accept mutex locked"); |
744965ec6275
nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
653 |
6126
adba26ff70b5
Removed the obsolete rtsig module.
Ruslan Ermilov <ru@nginx.com>
parents:
6125
diff
changeset
|
654 if (ngx_accept_mutex_held && ngx_accept_events == 0) { |
573 | 655 return NGX_OK; |
656 } | |
301
744965ec6275
nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
657 |
573 | 658 if (ngx_enable_accept_events(cycle) == NGX_ERROR) { |
611 | 659 ngx_shmtx_unlock(&ngx_accept_mutex); |
573 | 660 return NGX_ERROR; |
301
744965ec6275
nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
661 } |
744965ec6275
nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
662 |
719
f30b1a75fd3b
Solaris 10 event ports support
Igor Sysoev <igor@sysoev.ru>
parents:
714
diff
changeset
|
663 ngx_accept_events = 0; |
573 | 664 ngx_accept_mutex_held = 1; |
665 | |
301
744965ec6275
nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
666 return NGX_OK; |
744965ec6275
nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
667 } |
744965ec6275
nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
668 |
719
f30b1a75fd3b
Solaris 10 event ports support
Igor Sysoev <igor@sysoev.ru>
parents:
714
diff
changeset
|
669 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0, |
f30b1a75fd3b
Solaris 10 event ports support
Igor Sysoev <igor@sysoev.ru>
parents:
714
diff
changeset
|
670 "accept mutex lock failed: %ui", ngx_accept_mutex_held); |
f30b1a75fd3b
Solaris 10 event ports support
Igor Sysoev <igor@sysoev.ru>
parents:
714
diff
changeset
|
671 |
302
1526e7686b20
nginx-0.0.3-2004-04-01-10:21:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
301
diff
changeset
|
672 if (ngx_accept_mutex_held) { |
6153
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
673 if (ngx_disable_accept_events(cycle, 0) == NGX_ERROR) { |
301
744965ec6275
nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
674 return NGX_ERROR; |
744965ec6275
nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
675 } |
744965ec6275
nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
676 |
302
1526e7686b20
nginx-0.0.3-2004-04-01-10:21:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
301
diff
changeset
|
677 ngx_accept_mutex_held = 0; |
301
744965ec6275
nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
678 } |
744965ec6275
nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
679 |
744965ec6275
nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
680 return NGX_OK; |
744965ec6275
nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
681 } |
744965ec6275
nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
682 |
744965ec6275
nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
683 |
573 | 684 static ngx_int_t |
493 | 685 ngx_enable_accept_events(ngx_cycle_t *cycle) |
301
744965ec6275
nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
686 { |
543 | 687 ngx_uint_t i; |
688 ngx_listening_t *ls; | |
689 ngx_connection_t *c; | |
301
744965ec6275
nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
690 |
543 | 691 ls = cycle->listening.elts; |
301
744965ec6275
nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
692 for (i = 0; i < cycle->listening.nelts; i++) { |
744965ec6275
nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
693 |
543 | 694 c = ls[i].connection; |
301
744965ec6275
nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
695 |
6153
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
696 if (c == NULL || c->read->active) { |
4618
c05cfc46b3bc
Accept moderation in case of EMFILE/ENFILE.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4613
diff
changeset
|
697 continue; |
c05cfc46b3bc
Accept moderation in case of EMFILE/ENFILE.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4613
diff
changeset
|
698 } |
c05cfc46b3bc
Accept moderation in case of EMFILE/ENFILE.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4613
diff
changeset
|
699 |
6126
adba26ff70b5
Removed the obsolete rtsig module.
Ruslan Ermilov <ru@nginx.com>
parents:
6125
diff
changeset
|
700 if (ngx_add_event(c->read, NGX_READ_EVENT, 0) == NGX_ERROR) { |
adba26ff70b5
Removed the obsolete rtsig module.
Ruslan Ermilov <ru@nginx.com>
parents:
6125
diff
changeset
|
701 return NGX_ERROR; |
301
744965ec6275
nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
702 } |
744965ec6275
nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
703 } |
744965ec6275
nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
704 |
744965ec6275
nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
705 return NGX_OK; |
744965ec6275
nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
706 } |
744965ec6275
nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
707 |
744965ec6275
nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
708 |
573 | 709 static ngx_int_t |
6153
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
710 ngx_disable_accept_events(ngx_cycle_t *cycle, ngx_uint_t all) |
301
744965ec6275
nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
711 { |
543 | 712 ngx_uint_t i; |
713 ngx_listening_t *ls; | |
714 ngx_connection_t *c; | |
301
744965ec6275
nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
715 |
543 | 716 ls = cycle->listening.elts; |
301
744965ec6275
nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
717 for (i = 0; i < cycle->listening.nelts; i++) { |
744965ec6275
nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
718 |
543 | 719 c = ls[i].connection; |
720 | |
6153
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
721 if (c == NULL || !c->read->active) { |
543 | 722 continue; |
723 } | |
301
744965ec6275
nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
724 |
6153
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
725 #if (NGX_HAVE_REUSEPORT) |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
726 |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
727 /* |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
728 * do not disable accept on worker's own sockets |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
729 * when disabling accept events due to accept mutex |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
730 */ |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
731 |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
732 if (ls[i].reuseport && !all) { |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
733 continue; |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
734 } |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
735 |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
736 #endif |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
737 |
6126
adba26ff70b5
Removed the obsolete rtsig module.
Ruslan Ermilov <ru@nginx.com>
parents:
6125
diff
changeset
|
738 if (ngx_del_event(c->read, NGX_READ_EVENT, NGX_DISABLE_EVENT) |
adba26ff70b5
Removed the obsolete rtsig module.
Ruslan Ermilov <ru@nginx.com>
parents:
6125
diff
changeset
|
739 == NGX_ERROR) |
adba26ff70b5
Removed the obsolete rtsig module.
Ruslan Ermilov <ru@nginx.com>
parents:
6125
diff
changeset
|
740 { |
adba26ff70b5
Removed the obsolete rtsig module.
Ruslan Ermilov <ru@nginx.com>
parents:
6125
diff
changeset
|
741 return NGX_ERROR; |
301
744965ec6275
nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
742 } |
744965ec6275
nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
743 } |
744965ec6275
nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
744 |
744965ec6275
nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
745 return NGX_OK; |
744965ec6275
nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
746 } |
744965ec6275
nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
747 |
744965ec6275
nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
748 |
493 | 749 static void |
543 | 750 ngx_close_accepted_connection(ngx_connection_t *c) |
419
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
396
diff
changeset
|
751 { |
543 | 752 ngx_socket_t fd; |
753 | |
754 ngx_free_connection(c); | |
755 | |
756 fd = c->fd; | |
757 c->fd = (ngx_socket_t) -1; | |
758 | |
6436 | 759 if (!c->shared && ngx_close_socket(fd) == -1) { |
543 | 760 ngx_log_error(NGX_LOG_ALERT, c->log, ngx_socket_errno, |
419
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
396
diff
changeset
|
761 ngx_close_socket_n " failed"); |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
396
diff
changeset
|
762 } |
495 | 763 |
543 | 764 if (c->pool) { |
765 ngx_destroy_pool(c->pool); | |
766 } | |
767 | |
495 | 768 #if (NGX_STAT_STUB) |
2951
5acd98486a33
ignore ngx_atomic_fetch_add() result
Igor Sysoev <igor@sysoev.ru>
parents:
2723
diff
changeset
|
769 (void) ngx_atomic_fetch_add(ngx_stat_active, -1); |
495 | 770 #endif |
419
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
396
diff
changeset
|
771 } |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
396
diff
changeset
|
772 |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
396
diff
changeset
|
773 |
543 | 774 u_char * |
493 | 775 ngx_accept_log_error(ngx_log_t *log, u_char *buf, size_t len) |
191
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
164
diff
changeset
|
776 { |
543 | 777 return ngx_snprintf(buf, len, " while accepting new connection on %V", |
778 log->data); | |
191
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
164
diff
changeset
|
779 } |
6436 | 780 |
781 | |
782 #if (NGX_DEBUG) | |
783 | |
784 static void | |
785 ngx_debug_accepted_connection(ngx_event_conf_t *ecf, ngx_connection_t *c) | |
786 { | |
787 struct sockaddr_in *sin; | |
788 ngx_cidr_t *cidr; | |
789 ngx_uint_t i; | |
790 #if (NGX_HAVE_INET6) | |
791 struct sockaddr_in6 *sin6; | |
792 ngx_uint_t n; | |
793 #endif | |
794 | |
795 cidr = ecf->debug_connection.elts; | |
796 for (i = 0; i < ecf->debug_connection.nelts; i++) { | |
797 if (cidr[i].family != (ngx_uint_t) c->sockaddr->sa_family) { | |
798 goto next; | |
799 } | |
800 | |
801 switch (cidr[i].family) { | |
802 | |
803 #if (NGX_HAVE_INET6) | |
804 case AF_INET6: | |
805 sin6 = (struct sockaddr_in6 *) c->sockaddr; | |
806 for (n = 0; n < 16; n++) { | |
807 if ((sin6->sin6_addr.s6_addr[n] | |
808 & cidr[i].u.in6.mask.s6_addr[n]) | |
809 != cidr[i].u.in6.addr.s6_addr[n]) | |
810 { | |
811 goto next; | |
812 } | |
813 } | |
814 break; | |
815 #endif | |
816 | |
817 #if (NGX_HAVE_UNIX_DOMAIN) | |
818 case AF_UNIX: | |
819 break; | |
820 #endif | |
821 | |
822 default: /* AF_INET */ | |
823 sin = (struct sockaddr_in *) c->sockaddr; | |
824 if ((sin->sin_addr.s_addr & cidr[i].u.in.mask) | |
825 != cidr[i].u.in.addr) | |
826 { | |
827 goto next; | |
828 } | |
829 break; | |
830 } | |
831 | |
832 c->log->log_level = NGX_LOG_DEBUG_CONNECTION|NGX_LOG_DEBUG_ALL; | |
833 break; | |
834 | |
835 next: | |
836 continue; | |
837 } | |
838 } | |
839 | |
840 #endif |