Mercurial > hg > nginx
annotate src/event/ngx_event_accept.c @ 8496:c5324bb3a704 quic
QUIC: limited the number of client-initiated streams.
The limits on active bidi and uni client streams are maintained at their
initial values initial_max_streams_bidi and initial_max_streams_uni by sending
a MAX_STREAMS frame upon each client stream closure.
Also, the following is changed for data arriving to non-existing streams:
- if a stream was already closed, such data is ignored
- when creating a new stream, all streams of the same type with lower ids are
created too
author | Roman Arutyunyan <arut@nginx.com> |
---|---|
date | Mon, 27 Jul 2020 19:15:17 +0300 |
parents | 88a624c9b491 |
children | fdc3d40979b0 |
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 |
6153
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
13 static ngx_int_t ngx_disable_accept_events(ngx_cycle_t *cycle, ngx_uint_t all); |
543 | 14 static void ngx_close_accepted_connection(ngx_connection_t *c); |
191
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
164
diff
changeset
|
15 |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
164
diff
changeset
|
16 |
493 | 17 void |
18 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
|
19 { |
714 | 20 socklen_t socklen; |
483 | 21 ngx_err_t err; |
22 ngx_log_t *log; | |
4618
c05cfc46b3bc
Accept moderation in case of EMFILE/ENFILE.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4613
diff
changeset
|
23 ngx_uint_t level; |
483 | 24 ngx_socket_t s; |
25 ngx_event_t *rev, *wev; | |
6559
adf25b8d0431
Introduced the ngx_sockaddr_t type.
Ruslan Ermilov <ru@nginx.com>
parents:
6532
diff
changeset
|
26 ngx_sockaddr_t sa; |
543 | 27 ngx_listening_t *ls; |
28 ngx_connection_t *c, *lc; | |
483 | 29 ngx_event_conf_t *ecf; |
3812
ef27dc1a7832
fallback to accept() if accept4() is not implemented,
Igor Sysoev <igor@sysoev.ru>
parents:
3786
diff
changeset
|
30 #if (NGX_HAVE_ACCEPT4) |
ef27dc1a7832
fallback to accept() if accept4() is not implemented,
Igor Sysoev <igor@sysoev.ru>
parents:
3786
diff
changeset
|
31 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
|
32 #endif |
26
53cb81681040
nginx-0.0.1-2002-12-15-09:25:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
24
diff
changeset
|
33 |
4618
c05cfc46b3bc
Accept moderation in case of EMFILE/ENFILE.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4613
diff
changeset
|
34 if (ev->timedout) { |
c05cfc46b3bc
Accept moderation in case of EMFILE/ENFILE.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4613
diff
changeset
|
35 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
|
36 return; |
c05cfc46b3bc
Accept moderation in case of EMFILE/ENFILE.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4613
diff
changeset
|
37 } |
c05cfc46b3bc
Accept moderation in case of EMFILE/ENFILE.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4613
diff
changeset
|
38 |
c05cfc46b3bc
Accept moderation in case of EMFILE/ENFILE.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4613
diff
changeset
|
39 ev->timedout = 0; |
c05cfc46b3bc
Accept moderation in case of EMFILE/ENFILE.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4613
diff
changeset
|
40 } |
c05cfc46b3bc
Accept moderation in case of EMFILE/ENFILE.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4613
diff
changeset
|
41 |
114
ac69ab96328d
nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
113
diff
changeset
|
42 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
|
43 |
6126
adba26ff70b5
Removed the obsolete rtsig module.
Ruslan Ermilov <ru@nginx.com>
parents:
6125
diff
changeset
|
44 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
|
45 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
|
46 } |
e885208c518b
nginx-0.0.2-2004-02-03-00:19:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
247
diff
changeset
|
47 |
543 | 48 lc = ev->data; |
49 ls = lc->listening; | |
50 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
|
51 |
257
70e1c7d2b83d
nginx-0.0.2-2004-02-11-20:08:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
253
diff
changeset
|
52 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, ev->log, 0, |
543 | 53 "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
|
54 |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
55 do { |
6559
adf25b8d0431
Introduced the ngx_sockaddr_t type.
Ruslan Ermilov <ru@nginx.com>
parents:
6532
diff
changeset
|
56 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
|
57 |
3786 | 58 #if (NGX_HAVE_ACCEPT4) |
3812
ef27dc1a7832
fallback to accept() if accept4() is not implemented,
Igor Sysoev <igor@sysoev.ru>
parents:
3786
diff
changeset
|
59 if (use_accept4) { |
6559
adf25b8d0431
Introduced the ngx_sockaddr_t type.
Ruslan Ermilov <ru@nginx.com>
parents:
6532
diff
changeset
|
60 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
|
61 } else { |
6559
adf25b8d0431
Introduced the ngx_sockaddr_t type.
Ruslan Ermilov <ru@nginx.com>
parents:
6532
diff
changeset
|
62 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
|
63 } |
3786 | 64 #else |
6559
adf25b8d0431
Introduced the ngx_sockaddr_t type.
Ruslan Ermilov <ru@nginx.com>
parents:
6532
diff
changeset
|
65 s = accept(lc->fd, &sa.sockaddr, &socklen); |
3786 | 66 #endif |
477 | 67 |
5360
3d2d3e1cf427
Win32: MinGW GCC compatibility.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5359
diff
changeset
|
68 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
|
69 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
|
70 |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
71 if (err == NGX_EAGAIN) { |
719
f30b1a75fd3b
Solaris 10 event ports support
Igor Sysoev <igor@sysoev.ru>
parents:
714
diff
changeset
|
72 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
|
73 "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
|
74 return; |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
75 } |
6
669801705ab1
nginx-0.0.1-2002-08-26-19:18:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
3
diff
changeset
|
76 |
4618
c05cfc46b3bc
Accept moderation in case of EMFILE/ENFILE.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4613
diff
changeset
|
77 level = NGX_LOG_ALERT; |
c05cfc46b3bc
Accept moderation in case of EMFILE/ENFILE.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4613
diff
changeset
|
78 |
c05cfc46b3bc
Accept moderation in case of EMFILE/ENFILE.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4613
diff
changeset
|
79 if (err == NGX_ECONNABORTED) { |
c05cfc46b3bc
Accept moderation in case of EMFILE/ENFILE.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4613
diff
changeset
|
80 level = NGX_LOG_ERR; |
c05cfc46b3bc
Accept moderation in case of EMFILE/ENFILE.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4613
diff
changeset
|
81 |
c05cfc46b3bc
Accept moderation in case of EMFILE/ENFILE.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4613
diff
changeset
|
82 } 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
|
83 level = NGX_LOG_CRIT; |
c05cfc46b3bc
Accept moderation in case of EMFILE/ENFILE.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4613
diff
changeset
|
84 } |
c05cfc46b3bc
Accept moderation in case of EMFILE/ENFILE.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4613
diff
changeset
|
85 |
3813
c870fb78550c
fix building by msvc8 introduced by the previous commit
Igor Sysoev <igor@sysoev.ru>
parents:
3812
diff
changeset
|
86 #if (NGX_HAVE_ACCEPT4) |
4618
c05cfc46b3bc
Accept moderation in case of EMFILE/ENFILE.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4613
diff
changeset
|
87 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
|
88 use_accept4 ? "accept4() failed" : "accept() failed"); |
ef27dc1a7832
fallback to accept() if accept4() is not implemented,
Igor Sysoev <igor@sysoev.ru>
parents:
3786
diff
changeset
|
89 |
ef27dc1a7832
fallback to accept() if accept4() is not implemented,
Igor Sysoev <igor@sysoev.ru>
parents:
3786
diff
changeset
|
90 if (use_accept4 && err == NGX_ENOSYS) { |
ef27dc1a7832
fallback to accept() if accept4() is not implemented,
Igor Sysoev <igor@sysoev.ru>
parents:
3786
diff
changeset
|
91 use_accept4 = 0; |
ef27dc1a7832
fallback to accept() if accept4() is not implemented,
Igor Sysoev <igor@sysoev.ru>
parents:
3786
diff
changeset
|
92 ngx_inherited_nonblocking = 0; |
ef27dc1a7832
fallback to accept() if accept4() is not implemented,
Igor Sysoev <igor@sysoev.ru>
parents:
3786
diff
changeset
|
93 continue; |
ef27dc1a7832
fallback to accept() if accept4() is not implemented,
Igor Sysoev <igor@sysoev.ru>
parents:
3786
diff
changeset
|
94 } |
3813
c870fb78550c
fix building by msvc8 introduced by the previous commit
Igor Sysoev <igor@sysoev.ru>
parents:
3812
diff
changeset
|
95 #else |
4618
c05cfc46b3bc
Accept moderation in case of EMFILE/ENFILE.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4613
diff
changeset
|
96 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
|
97 #endif |
97
70d2345a903f
nginx-0.0.1-2003-05-29-17:02:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
96
diff
changeset
|
98 |
248
e885208c518b
nginx-0.0.2-2004-02-03-00:19:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
247
diff
changeset
|
99 if (err == NGX_ECONNABORTED) { |
455 | 100 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
|
101 ev->available--; |
e885208c518b
nginx-0.0.2-2004-02-03-00:19:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
247
diff
changeset
|
102 } |
e885208c518b
nginx-0.0.2-2004-02-03-00:19:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
247
diff
changeset
|
103 |
e885208c518b
nginx-0.0.2-2004-02-03-00:19:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
247
diff
changeset
|
104 if (ev->available) { |
e885208c518b
nginx-0.0.2-2004-02-03-00:19:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
247
diff
changeset
|
105 continue; |
e885208c518b
nginx-0.0.2-2004-02-03-00:19:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
247
diff
changeset
|
106 } |
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 |
4618
c05cfc46b3bc
Accept moderation in case of EMFILE/ENFILE.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4613
diff
changeset
|
109 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
|
110 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
|
111 != NGX_OK) |
c05cfc46b3bc
Accept moderation in case of EMFILE/ENFILE.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4613
diff
changeset
|
112 { |
c05cfc46b3bc
Accept moderation in case of EMFILE/ENFILE.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4613
diff
changeset
|
113 return; |
c05cfc46b3bc
Accept moderation in case of EMFILE/ENFILE.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4613
diff
changeset
|
114 } |
c05cfc46b3bc
Accept moderation in case of EMFILE/ENFILE.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4613
diff
changeset
|
115 |
c05cfc46b3bc
Accept moderation in case of EMFILE/ENFILE.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4613
diff
changeset
|
116 if (ngx_use_accept_mutex) { |
c05cfc46b3bc
Accept moderation in case of EMFILE/ENFILE.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4613
diff
changeset
|
117 if (ngx_accept_mutex_held) { |
c05cfc46b3bc
Accept moderation in case of EMFILE/ENFILE.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4613
diff
changeset
|
118 ngx_shmtx_unlock(&ngx_accept_mutex); |
c05cfc46b3bc
Accept moderation in case of EMFILE/ENFILE.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4613
diff
changeset
|
119 ngx_accept_mutex_held = 0; |
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 |
c05cfc46b3bc
Accept moderation in case of EMFILE/ENFILE.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4613
diff
changeset
|
122 ngx_accept_disabled = 1; |
c05cfc46b3bc
Accept moderation in case of EMFILE/ENFILE.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4613
diff
changeset
|
123 |
c05cfc46b3bc
Accept moderation in case of EMFILE/ENFILE.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4613
diff
changeset
|
124 } else { |
c05cfc46b3bc
Accept moderation in case of EMFILE/ENFILE.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4613
diff
changeset
|
125 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
|
126 } |
c05cfc46b3bc
Accept moderation in case of EMFILE/ENFILE.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4613
diff
changeset
|
127 } |
c05cfc46b3bc
Accept moderation in case of EMFILE/ENFILE.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4613
diff
changeset
|
128 |
97
70d2345a903f
nginx-0.0.1-2003-05-29-17:02:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
96
diff
changeset
|
129 return; |
70d2345a903f
nginx-0.0.1-2003-05-29-17:02:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
96
diff
changeset
|
130 } |
70d2345a903f
nginx-0.0.1-2003-05-29-17:02:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
96
diff
changeset
|
131 |
426
3f88935a02e8
nginx-0.0.10-2004-09-14-23:39:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
425
diff
changeset
|
132 #if (NGX_STAT_STUB) |
2951
5acd98486a33
ignore ngx_atomic_fetch_add() result
Igor Sysoev <igor@sysoev.ru>
parents:
2723
diff
changeset
|
133 (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
|
134 #endif |
323
ba876b26b76d
nginx-0.0.3-2004-04-21-22:54:33 import
Igor Sysoev <igor@sysoev.ru>
parents:
315
diff
changeset
|
135 |
2255 | 136 ngx_accept_disabled = ngx_cycle->connection_n / 8 |
543 | 137 - ngx_cycle->free_connection_n; |
138 | |
139 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
|
140 |
543 | 141 if (c == NULL) { |
142 if (ngx_close_socket(s) == -1) { | |
143 ngx_log_error(NGX_LOG_ALERT, ev->log, ngx_socket_errno, | |
144 ngx_close_socket_n " failed"); | |
145 } | |
119
cd54bcbaf3b5
nginx-0.0.1-2003-07-21-01:15:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
117
diff
changeset
|
146 |
543 | 147 return; |
148 } | |
149 | |
6436 | 150 c->type = SOCK_STREAM; |
151 | |
635 | 152 #if (NGX_STAT_STUB) |
2951
5acd98486a33
ignore ngx_atomic_fetch_add() result
Igor Sysoev <igor@sysoev.ru>
parents:
2723
diff
changeset
|
153 (void) ngx_atomic_fetch_add(ngx_stat_active, 1); |
635 | 154 #endif |
155 | |
543 | 156 c->pool = ngx_create_pool(ls->pool_size, ev->log); |
157 if (c->pool == NULL) { | |
158 ngx_close_accepted_connection(c); | |
159 return; | |
160 } | |
97
70d2345a903f
nginx-0.0.1-2003-05-29-17:02:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
96
diff
changeset
|
161 |
7119
fef61d26da39
Fixed buffer overread with unix sockets after accept().
Maxim Dounin <mdounin@mdounin.ru>
parents:
7005
diff
changeset
|
162 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
|
163 socklen = sizeof(ngx_sockaddr_t); |
fef61d26da39
Fixed buffer overread with unix sockets after accept().
Maxim Dounin <mdounin@mdounin.ru>
parents:
7005
diff
changeset
|
164 } |
fef61d26da39
Fixed buffer overread with unix sockets after accept().
Maxim Dounin <mdounin@mdounin.ru>
parents:
7005
diff
changeset
|
165 |
714 | 166 c->sockaddr = ngx_palloc(c->pool, socklen); |
543 | 167 if (c->sockaddr == NULL) { |
168 ngx_close_accepted_connection(c); | |
169 return; | |
170 } | |
171 | |
6559
adf25b8d0431
Introduced the ngx_sockaddr_t type.
Ruslan Ermilov <ru@nginx.com>
parents:
6532
diff
changeset
|
172 ngx_memcpy(c->sockaddr, &sa, socklen); |
543 | 173 |
174 log = ngx_palloc(c->pool, sizeof(ngx_log_t)); | |
175 if (log == NULL) { | |
176 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
|
177 return; |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
178 } |
6
669801705ab1
nginx-0.0.1-2002-08-26-19:18:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
3
diff
changeset
|
179 |
6125
4dc8e7b62216
Removed the obsolete aio module.
Ruslan Ermilov <ru@nginx.com>
parents:
5820
diff
changeset
|
180 /* 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
|
181 |
93
738fe44c70d5
nginx-0.0.1-2003-05-21-17:28:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
92
diff
changeset
|
182 if (ngx_inherited_nonblocking) { |
6125
4dc8e7b62216
Removed the obsolete aio module.
Ruslan Ermilov <ru@nginx.com>
parents:
5820
diff
changeset
|
183 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
|
184 if (ngx_blocking(s) == -1) { |
543 | 185 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
|
186 ngx_blocking_n " failed"); |
543 | 187 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
|
188 return; |
738fe44c70d5
nginx-0.0.1-2003-05-21-17:28:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
92
diff
changeset
|
189 } |
738fe44c70d5
nginx-0.0.1-2003-05-21-17:28:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
92
diff
changeset
|
190 } |
738fe44c70d5
nginx-0.0.1-2003-05-21-17:28:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
92
diff
changeset
|
191 |
738fe44c70d5
nginx-0.0.1-2003-05-21-17:28:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
92
diff
changeset
|
192 } else { |
6126
adba26ff70b5
Removed the obsolete rtsig module.
Ruslan Ermilov <ru@nginx.com>
parents:
6125
diff
changeset
|
193 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
|
194 if (ngx_nonblocking(s) == -1) { |
543 | 195 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
|
196 ngx_nonblocking_n " failed"); |
543 | 197 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
|
198 return; |
738fe44c70d5
nginx-0.0.1-2003-05-21-17:28:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
92
diff
changeset
|
199 } |
59
e8cdc2989cee
nginx-0.0.1-2003-02-06-20:21:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
57
diff
changeset
|
200 } |
e8cdc2989cee
nginx-0.0.1-2003-02-06-20:21:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
57
diff
changeset
|
201 } |
e8cdc2989cee
nginx-0.0.1-2003-02-06-20:21:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
57
diff
changeset
|
202 |
543 | 203 *log = ls->log; |
204 | |
205 c->recv = ngx_recv; | |
206 c->send = ngx_send; | |
577 | 207 c->recv_chain = ngx_recv_chain; |
543 | 208 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
|
209 |
543 | 210 c->log = log; |
211 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
|
212 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2255
diff
changeset
|
213 c->socklen = socklen; |
543 | 214 c->listening = ls; |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2255
diff
changeset
|
215 c->local_sockaddr = ls->sockaddr; |
5463
1ab1cf63f885
Core: keep the length of the local sockaddr.
Ruslan Ermilov <ru@nginx.com>
parents:
5360
diff
changeset
|
216 c->local_socklen = ls->socklen; |
543 | 217 |
3230
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
2951
diff
changeset
|
218 #if (NGX_HAVE_UNIX_DOMAIN) |
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
2951
diff
changeset
|
219 if (c->sockaddr->sa_family == AF_UNIX) { |
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
2951
diff
changeset
|
220 c->tcp_nopush = NGX_TCP_NOPUSH_DISABLED; |
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
2951
diff
changeset
|
221 c->tcp_nodelay = NGX_TCP_NODELAY_DISABLED; |
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
2951
diff
changeset
|
222 #if (NGX_SOLARIS) |
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
2951
diff
changeset
|
223 /* 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
|
224 c->sendfile = 0; |
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
2951
diff
changeset
|
225 #endif |
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
2951
diff
changeset
|
226 } |
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
2951
diff
changeset
|
227 #endif |
a7491af45540
http listen unix domain sockets
Igor Sysoev <igor@sysoev.ru>
parents:
2951
diff
changeset
|
228 |
561 | 229 rev = c->read; |
230 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
|
231 |
164
84036764e215
nginx-0.0.1-2003-10-29-11:30:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
121
diff
changeset
|
232 wev->ready = 1; |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
233 |
6126
adba26ff70b5
Removed the obsolete rtsig module.
Ruslan Ermilov <ru@nginx.com>
parents:
6125
diff
changeset
|
234 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
|
235 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
|
236 } |
e8cdc2989cee
nginx-0.0.1-2003-02-06-20:21:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
57
diff
changeset
|
237 |
245
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
236
diff
changeset
|
238 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
|
239 rev->ready = 1; |
7005
3e2d90073adf
Fixed deferred accept with EPOLLRDHUP enabled (ticket #1278).
Roman Arutyunyan <arut@nginx.com>
parents:
6692
diff
changeset
|
240 #if (NGX_HAVE_KQUEUE || NGX_HAVE_EPOLLRDHUP) |
523 | 241 rev->available = 1; |
242 #endif | |
245
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
236
diff
changeset
|
243 } |
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
236
diff
changeset
|
244 |
191
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
164
diff
changeset
|
245 rev->log = log; |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
164
diff
changeset
|
246 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
|
247 |
208
0b67be7d4489
nginx-0.0.1-2003-12-08-23:48:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
206
diff
changeset
|
248 /* |
561 | 249 * 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
|
250 * 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
|
251 * |
0b67be7d4489
nginx-0.0.1-2003-12-08-23:48:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
206
diff
changeset
|
252 * TODO: MP: - allocated in a shared memory |
561 | 253 * - 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
|
254 * 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
|
255 */ |
212
679f60139863
nginx-0.0.1-2003-12-19-11:15:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
256 |
561 | 257 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
|
258 |
495 | 259 #if (NGX_STAT_STUB) |
2951
5acd98486a33
ignore ngx_atomic_fetch_add() result
Igor Sysoev <igor@sysoev.ru>
parents:
2723
diff
changeset
|
260 (void) ngx_atomic_fetch_add(ngx_stat_handled, 1); |
495 | 261 #endif |
262 | |
543 | 263 if (ls->addr_ntop) { |
2049 | 264 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
|
265 if (c->addr_text.data == NULL) { |
543 | 266 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
|
267 return; |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
396
diff
changeset
|
268 } |
577 | 269 |
5263
05ba5bce31e0
Core: extended ngx_sock_ntop() with socklen parameter.
Vladimir Homutov <vl@nginx.com>
parents:
4618
diff
changeset
|
270 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
|
271 c->addr_text.data, |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2255
diff
changeset
|
272 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
|
273 if (c->addr_text.len == 0) { |
543 | 274 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
|
275 return; |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
396
diff
changeset
|
276 } |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
396
diff
changeset
|
277 } |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
396
diff
changeset
|
278 |
307
ce375c313e96
nginx-0.0.3-2004-04-08-19:58:25 import
Igor Sysoev <igor@sysoev.ru>
parents:
306
diff
changeset
|
279 #if (NGX_DEBUG) |
ce375c313e96
nginx-0.0.3-2004-04-08-19:58:25 import
Igor Sysoev <igor@sysoev.ru>
parents:
306
diff
changeset
|
280 { |
6436 | 281 ngx_str_t addr; |
282 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
|
283 |
6436 | 284 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
|
285 |
5704
524741fd50ed
Core: output client port number when logging accept event.
Ruslan Ermilov <ru@nginx.com>
parents:
5600
diff
changeset
|
286 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
|
287 addr.data = text; |
524741fd50ed
Core: output client port number when logging accept event.
Ruslan Ermilov <ru@nginx.com>
parents:
5600
diff
changeset
|
288 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
|
289 NGX_SOCKADDR_STRLEN, 1); |
524741fd50ed
Core: output client port number when logging accept event.
Ruslan Ermilov <ru@nginx.com>
parents:
5600
diff
changeset
|
290 |
524741fd50ed
Core: output client port number when logging accept event.
Ruslan Ermilov <ru@nginx.com>
parents:
5600
diff
changeset
|
291 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
|
292 "*%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
|
293 } |
524741fd50ed
Core: output client port number when logging accept event.
Ruslan Ermilov <ru@nginx.com>
parents:
5600
diff
changeset
|
294 |
307
ce375c313e96
nginx-0.0.3-2004-04-08-19:58:25 import
Igor Sysoev <igor@sysoev.ru>
parents:
306
diff
changeset
|
295 } |
ce375c313e96
nginx-0.0.3-2004-04-08-19:58:25 import
Igor Sysoev <igor@sysoev.ru>
parents:
306
diff
changeset
|
296 #endif |
ce375c313e96
nginx-0.0.3-2004-04-08-19:58:25 import
Igor Sysoev <igor@sysoev.ru>
parents:
306
diff
changeset
|
297 |
381
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
298 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
|
299 if (ngx_add_conn(c) == NGX_ERROR) { |
543 | 300 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
|
301 return; |
64
34d647deb1da
nginx-0.0.1-2003-03-04-09:33:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
63
diff
changeset
|
302 } |
34d647deb1da
nginx-0.0.1-2003-03-04-09:33:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
63
diff
changeset
|
303 } |
34d647deb1da
nginx-0.0.1-2003-03-04-09:33:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
63
diff
changeset
|
304 |
191
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
164
diff
changeset
|
305 log->data = NULL; |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
164
diff
changeset
|
306 log->handler = NULL; |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
164
diff
changeset
|
307 |
543 | 308 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
|
309 |
455 | 310 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
|
311 ev->available--; |
57
a499e0d1f16e
nginx-0.0.1-2003-01-30-10:28:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
44
diff
changeset
|
312 } |
191
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
164
diff
changeset
|
313 |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
314 } while (ev->available); |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
315 } |
191
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
164
diff
changeset
|
316 |
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
164
diff
changeset
|
317 |
493 | 318 ngx_int_t |
319 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
|
320 { |
611 | 321 if (ngx_shmtx_trylock(&ngx_accept_mutex)) { |
322 | |
301
744965ec6275
nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
323 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
|
324 "accept mutex locked"); |
744965ec6275
nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
325 |
6126
adba26ff70b5
Removed the obsolete rtsig module.
Ruslan Ermilov <ru@nginx.com>
parents:
6125
diff
changeset
|
326 if (ngx_accept_mutex_held && ngx_accept_events == 0) { |
573 | 327 return NGX_OK; |
328 } | |
301
744965ec6275
nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
329 |
573 | 330 if (ngx_enable_accept_events(cycle) == NGX_ERROR) { |
611 | 331 ngx_shmtx_unlock(&ngx_accept_mutex); |
573 | 332 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
|
333 } |
744965ec6275
nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
334 |
719
f30b1a75fd3b
Solaris 10 event ports support
Igor Sysoev <igor@sysoev.ru>
parents:
714
diff
changeset
|
335 ngx_accept_events = 0; |
573 | 336 ngx_accept_mutex_held = 1; |
337 | |
301
744965ec6275
nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
338 return NGX_OK; |
744965ec6275
nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
339 } |
744965ec6275
nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
340 |
719
f30b1a75fd3b
Solaris 10 event ports support
Igor Sysoev <igor@sysoev.ru>
parents:
714
diff
changeset
|
341 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
|
342 "accept mutex lock failed: %ui", ngx_accept_mutex_held); |
f30b1a75fd3b
Solaris 10 event ports support
Igor Sysoev <igor@sysoev.ru>
parents:
714
diff
changeset
|
343 |
302
1526e7686b20
nginx-0.0.3-2004-04-01-10:21:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
301
diff
changeset
|
344 if (ngx_accept_mutex_held) { |
6153
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
345 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
|
346 return NGX_ERROR; |
744965ec6275
nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
347 } |
744965ec6275
nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
348 |
302
1526e7686b20
nginx-0.0.3-2004-04-01-10:21:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
301
diff
changeset
|
349 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
|
350 } |
744965ec6275
nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
351 |
744965ec6275
nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
352 return NGX_OK; |
744965ec6275
nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
353 } |
744965ec6275
nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
354 |
744965ec6275
nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
355 |
7285
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
7284
diff
changeset
|
356 ngx_int_t |
493 | 357 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
|
358 { |
543 | 359 ngx_uint_t i; |
360 ngx_listening_t *ls; | |
361 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
|
362 |
543 | 363 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
|
364 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
|
365 |
543 | 366 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
|
367 |
6153
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
368 if (c == NULL || c->read->active) { |
4618
c05cfc46b3bc
Accept moderation in case of EMFILE/ENFILE.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4613
diff
changeset
|
369 continue; |
c05cfc46b3bc
Accept moderation in case of EMFILE/ENFILE.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4613
diff
changeset
|
370 } |
c05cfc46b3bc
Accept moderation in case of EMFILE/ENFILE.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4613
diff
changeset
|
371 |
6126
adba26ff70b5
Removed the obsolete rtsig module.
Ruslan Ermilov <ru@nginx.com>
parents:
6125
diff
changeset
|
372 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
|
373 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
|
374 } |
744965ec6275
nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
375 } |
744965ec6275
nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
376 |
744965ec6275
nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
377 return NGX_OK; |
744965ec6275
nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
378 } |
744965ec6275
nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
379 |
744965ec6275
nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
380 |
573 | 381 static ngx_int_t |
6153
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
382 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
|
383 { |
543 | 384 ngx_uint_t i; |
385 ngx_listening_t *ls; | |
386 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
|
387 |
543 | 388 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
|
389 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
|
390 |
543 | 391 c = ls[i].connection; |
392 | |
6153
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
393 if (c == NULL || !c->read->active) { |
543 | 394 continue; |
395 } | |
301
744965ec6275
nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
396 |
6153
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
397 #if (NGX_HAVE_REUSEPORT) |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
398 |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
399 /* |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
400 * 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
|
401 * 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
|
402 */ |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
403 |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
404 if (ls[i].reuseport && !all) { |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
405 continue; |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
406 } |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
407 |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
408 #endif |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6126
diff
changeset
|
409 |
6126
adba26ff70b5
Removed the obsolete rtsig module.
Ruslan Ermilov <ru@nginx.com>
parents:
6125
diff
changeset
|
410 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
|
411 == NGX_ERROR) |
adba26ff70b5
Removed the obsolete rtsig module.
Ruslan Ermilov <ru@nginx.com>
parents:
6125
diff
changeset
|
412 { |
adba26ff70b5
Removed the obsolete rtsig module.
Ruslan Ermilov <ru@nginx.com>
parents:
6125
diff
changeset
|
413 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
|
414 } |
744965ec6275
nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
415 } |
744965ec6275
nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
416 |
744965ec6275
nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
417 return NGX_OK; |
744965ec6275
nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
418 } |
744965ec6275
nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
419 |
744965ec6275
nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
420 |
493 | 421 static void |
543 | 422 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
|
423 { |
543 | 424 ngx_socket_t fd; |
425 | |
426 ngx_free_connection(c); | |
427 | |
428 fd = c->fd; | |
429 c->fd = (ngx_socket_t) -1; | |
430 | |
7285
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
7284
diff
changeset
|
431 if (ngx_close_socket(fd) == -1) { |
543 | 432 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
|
433 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
|
434 } |
495 | 435 |
543 | 436 if (c->pool) { |
437 ngx_destroy_pool(c->pool); | |
438 } | |
439 | |
495 | 440 #if (NGX_STAT_STUB) |
2951
5acd98486a33
ignore ngx_atomic_fetch_add() result
Igor Sysoev <igor@sysoev.ru>
parents:
2723
diff
changeset
|
441 (void) ngx_atomic_fetch_add(ngx_stat_active, -1); |
495 | 442 #endif |
419
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
396
diff
changeset
|
443 } |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
396
diff
changeset
|
444 |
47709bff4468
nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
396
diff
changeset
|
445 |
543 | 446 u_char * |
493 | 447 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
|
448 { |
543 | 449 return ngx_snprintf(buf, len, " while accepting new connection on %V", |
450 log->data); | |
191
71ce40b3c37b
nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
164
diff
changeset
|
451 } |
6436 | 452 |
453 | |
454 #if (NGX_DEBUG) | |
455 | |
7285
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
7284
diff
changeset
|
456 void |
6436 | 457 ngx_debug_accepted_connection(ngx_event_conf_t *ecf, ngx_connection_t *c) |
458 { | |
459 struct sockaddr_in *sin; | |
460 ngx_cidr_t *cidr; | |
461 ngx_uint_t i; | |
462 #if (NGX_HAVE_INET6) | |
463 struct sockaddr_in6 *sin6; | |
464 ngx_uint_t n; | |
465 #endif | |
466 | |
467 cidr = ecf->debug_connection.elts; | |
468 for (i = 0; i < ecf->debug_connection.nelts; i++) { | |
469 if (cidr[i].family != (ngx_uint_t) c->sockaddr->sa_family) { | |
470 goto next; | |
471 } | |
472 | |
473 switch (cidr[i].family) { | |
474 | |
475 #if (NGX_HAVE_INET6) | |
476 case AF_INET6: | |
477 sin6 = (struct sockaddr_in6 *) c->sockaddr; | |
478 for (n = 0; n < 16; n++) { | |
479 if ((sin6->sin6_addr.s6_addr[n] | |
480 & cidr[i].u.in6.mask.s6_addr[n]) | |
481 != cidr[i].u.in6.addr.s6_addr[n]) | |
482 { | |
483 goto next; | |
484 } | |
485 } | |
486 break; | |
487 #endif | |
488 | |
489 #if (NGX_HAVE_UNIX_DOMAIN) | |
490 case AF_UNIX: | |
491 break; | |
492 #endif | |
493 | |
494 default: /* AF_INET */ | |
495 sin = (struct sockaddr_in *) c->sockaddr; | |
496 if ((sin->sin_addr.s_addr & cidr[i].u.in.mask) | |
497 != cidr[i].u.in.addr) | |
498 { | |
499 goto next; | |
500 } | |
501 break; | |
502 } | |
503 | |
504 c->log->log_level = NGX_LOG_DEBUG_CONNECTION|NGX_LOG_DEBUG_ALL; | |
505 break; | |
506 | |
507 next: | |
508 continue; | |
509 } | |
510 } | |
511 | |
512 #endif |