annotate src/event/ngx_event_accept.c @ 495:fc9909c369b2 release-0.1.22

nginx-0.1.22-RELEASE import *) Bugfix: the ngx_http_stub_status_module showed incorrect handled connections statistics if the proxying or FastCGI server were used. *) Bugfix: the installation paths were incorrectly quoted on Linux and Solaris; the bug had appeared in 0.1.21.
author Igor Sysoev <igor@sysoev.ru>
date Thu, 24 Feb 2005 12:29:09 +0000
parents 975f62e77f02
children d4ea69372b94
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
441
da8c5707af39 nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents: 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
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
4 */
da8c5707af39 nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents: 431
diff changeset
5
97
70d2345a903f nginx-0.0.1-2003-05-29-17:02:09 import
Igor Sysoev <igor@sysoev.ru>
parents: 96
diff changeset
6
70d2345a903f nginx-0.0.1-2003-05-29-17:02:09 import
Igor Sysoev <igor@sysoev.ru>
parents: 96
diff changeset
7 #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
8 #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
9 #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
10
4eff17414a43 nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
11
419
47709bff4468 nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 396
diff changeset
12 static void ngx_close_accepted_socket(ngx_socket_t s, ngx_log_t *log);
483
621229427cba nginx-0.1.16-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 479
diff changeset
13 static u_char *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
14
71ce40b3c37b nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents: 164
diff changeset
15
493
975f62e77f02 nginx-0.1.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 487
diff changeset
16 void
975f62e77f02 nginx-0.1.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 487
diff changeset
17 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
18 {
483
621229427cba nginx-0.1.16-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 479
diff changeset
19 ngx_uint_t instance, accepted;
621229427cba nginx-0.1.16-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 479
diff changeset
20 socklen_t len;
621229427cba nginx-0.1.16-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 479
diff changeset
21 struct sockaddr *sa;
621229427cba nginx-0.1.16-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 479
diff changeset
22 ngx_err_t err;
621229427cba nginx-0.1.16-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 479
diff changeset
23 ngx_log_t *log;
621229427cba nginx-0.1.16-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 479
diff changeset
24 ngx_pool_t *pool;
621229427cba nginx-0.1.16-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 479
diff changeset
25 ngx_socket_t s;
621229427cba nginx-0.1.16-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 479
diff changeset
26 ngx_event_t *rev, *wev;
621229427cba nginx-0.1.16-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 479
diff changeset
27 ngx_connection_t *c, *ls;
621229427cba nginx-0.1.16-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 479
diff changeset
28 ngx_event_conf_t *ecf;
26
53cb81681040 nginx-0.0.1-2002-12-15-09:25:09 import
Igor Sysoev <igor@sysoev.ru>
parents: 24
diff changeset
29
114
ac69ab96328d nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents: 113
diff changeset
30 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
31
381
02a511569afb nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents: 380
diff changeset
32 if (ngx_event_flags & NGX_USE_RTSIG_EVENT) {
248
e885208c518b nginx-0.0.2-2004-02-03-00:19:52 import
Igor Sysoev <igor@sysoev.ru>
parents: 247
diff changeset
33 ev->available = 1;
e885208c518b nginx-0.0.2-2004-02-03-00:19:52 import
Igor Sysoev <igor@sysoev.ru>
parents: 247
diff changeset
34
455
295d97d70c69 nginx-0.1.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 444
diff changeset
35 } else 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
36 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
37 }
e885208c518b nginx-0.0.2-2004-02-03-00:19:52 import
Igor Sysoev <igor@sysoev.ru>
parents: 247
diff changeset
38
97
70d2345a903f nginx-0.0.1-2003-05-29-17:02:09 import
Igor Sysoev <igor@sysoev.ru>
parents: 96
diff changeset
39 ls = ev->data;
57
a499e0d1f16e nginx-0.0.1-2003-01-30-10:28:09 import
Igor Sysoev <igor@sysoev.ru>
parents: 44
diff changeset
40
257
70e1c7d2b83d nginx-0.0.2-2004-02-11-20:08:49 import
Igor Sysoev <igor@sysoev.ru>
parents: 253
diff changeset
41 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, ev->log, 0,
461
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 455
diff changeset
42 "accept on %V, ready: %d",
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 455
diff changeset
43 &ls->listening->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
44
0
4eff17414a43 nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
45 ev->ready = 0;
191
71ce40b3c37b nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents: 164
diff changeset
46 accepted = 0;
248
e885208c518b nginx-0.0.2-2004-02-03-00:19:52 import
Igor Sysoev <igor@sysoev.ru>
parents: 247
diff changeset
47 pool = NULL;
57
a499e0d1f16e nginx-0.0.1-2003-01-30-10:28:09 import
Igor Sysoev <igor@sysoev.ru>
parents: 44
diff changeset
48
0
4eff17414a43 nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
49 do {
92
19cc647ecd91 nginx-0.0.1-2003-05-20-19:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents: 91
diff changeset
50
248
e885208c518b nginx-0.0.2-2004-02-03-00:19:52 import
Igor Sysoev <igor@sysoev.ru>
parents: 247
diff changeset
51 if (pool == NULL) {
92
19cc647ecd91 nginx-0.0.1-2003-05-20-19:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents: 91
diff changeset
52
248
e885208c518b nginx-0.0.2-2004-02-03-00:19:52 import
Igor Sysoev <igor@sysoev.ru>
parents: 247
diff changeset
53 /*
346
55e496a8ece3 nginx-0.0.3-2004-06-06-23:49:18 import
Igor Sysoev <igor@sysoev.ru>
parents: 323
diff changeset
54 * Create the pool before accept() to avoid the copying of
55e496a8ece3 nginx-0.0.3-2004-06-06-23:49:18 import
Igor Sysoev <igor@sysoev.ru>
parents: 323
diff changeset
55 * the sockaddr. Although accept() can fail it is uncommon
493
975f62e77f02 nginx-0.1.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 487
diff changeset
56 * case and besides the pool can be got from the free pool list.
248
e885208c518b nginx-0.0.2-2004-02-03-00:19:52 import
Igor Sysoev <igor@sysoev.ru>
parents: 247
diff changeset
57 */
e885208c518b nginx-0.0.2-2004-02-03-00:19:52 import
Igor Sysoev <igor@sysoev.ru>
parents: 247
diff changeset
58
e885208c518b nginx-0.0.2-2004-02-03-00:19:52 import
Igor Sysoev <igor@sysoev.ru>
parents: 247
diff changeset
59 if (!(pool = ngx_create_pool(ls->listening->pool_size, ev->log))) {
e885208c518b nginx-0.0.2-2004-02-03-00:19:52 import
Igor Sysoev <igor@sysoev.ru>
parents: 247
diff changeset
60 return;
e885208c518b nginx-0.0.2-2004-02-03-00:19:52 import
Igor Sysoev <igor@sysoev.ru>
parents: 247
diff changeset
61 }
191
71ce40b3c37b nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents: 164
diff changeset
62 }
71ce40b3c37b nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents: 164
diff changeset
63
71ce40b3c37b nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents: 164
diff changeset
64 if (!(sa = ngx_palloc(pool, ls->listening->socklen))) {
248
e885208c518b nginx-0.0.2-2004-02-03-00:19:52 import
Igor Sysoev <igor@sysoev.ru>
parents: 247
diff changeset
65 ngx_destroy_pool(pool);
87
5f6d848dcbef nginx-0.0.1-2003-05-13-20:02:32 import
Igor Sysoev <igor@sysoev.ru>
parents: 86
diff changeset
66 return;
5f6d848dcbef nginx-0.0.1-2003-05-13-20:02:32 import
Igor Sysoev <igor@sysoev.ru>
parents: 86
diff changeset
67 }
57
a499e0d1f16e nginx-0.0.1-2003-01-30-10:28:09 import
Igor Sysoev <igor@sysoev.ru>
parents: 44
diff changeset
68
191
71ce40b3c37b nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents: 164
diff changeset
69 if (!(log = ngx_palloc(pool, sizeof(ngx_log_t)))) {
248
e885208c518b nginx-0.0.2-2004-02-03-00:19:52 import
Igor Sysoev <igor@sysoev.ru>
parents: 247
diff changeset
70 ngx_destroy_pool(pool);
87
5f6d848dcbef nginx-0.0.1-2003-05-13-20:02:32 import
Igor Sysoev <igor@sysoev.ru>
parents: 86
diff changeset
71 return;
5f6d848dcbef nginx-0.0.1-2003-05-13-20:02:32 import
Igor Sysoev <igor@sysoev.ru>
parents: 86
diff changeset
72 }
248
e885208c518b nginx-0.0.2-2004-02-03-00:19:52 import
Igor Sysoev <igor@sysoev.ru>
parents: 247
diff changeset
73
191
71ce40b3c37b nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents: 164
diff changeset
74 ngx_memcpy(log, ls->log, sizeof(ngx_log_t));
71ce40b3c37b nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents: 164
diff changeset
75 pool->log = log;
71ce40b3c37b nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents: 164
diff changeset
76
483
621229427cba nginx-0.1.16-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 479
diff changeset
77 log->data = &ls->listening->addr_text;
191
71ce40b3c37b nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents: 164
diff changeset
78 log->handler = ngx_accept_log_error;
87
5f6d848dcbef nginx-0.0.1-2003-05-13-20:02:32 import
Igor Sysoev <igor@sysoev.ru>
parents: 86
diff changeset
79
103
6dfda4cf5200 nginx-0.0.1-2003-06-11-19:28:34 import
Igor Sysoev <igor@sysoev.ru>
parents: 100
diff changeset
80 len = ls->listening->socklen;
6dfda4cf5200 nginx-0.0.1-2003-06-11-19:28:34 import
Igor Sysoev <igor@sysoev.ru>
parents: 100
diff changeset
81
57
a499e0d1f16e nginx-0.0.1-2003-01-30-10:28:09 import
Igor Sysoev <igor@sysoev.ru>
parents: 44
diff changeset
82 s = accept(ls->fd, sa, &len);
477
ad1e9ebf93bb nginx-0.1.13-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 461
diff changeset
83
57
a499e0d1f16e nginx-0.0.1-2003-01-30-10:28:09 import
Igor Sysoev <igor@sysoev.ru>
parents: 44
diff changeset
84 if (s == -1) {
0
4eff17414a43 nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
85 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
86
0
4eff17414a43 nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
87 if (err == NGX_EAGAIN) {
425
bd39260a1383 nginx-0.0.10-2004-09-14-19:55:24 import
Igor Sysoev <igor@sysoev.ru>
parents: 419
diff changeset
88 #if 0
381
02a511569afb nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents: 380
diff changeset
89 if (!(ngx_event_flags & NGX_USE_RTSIG_EVENT))
260
5dacbb4daaf6 nginx-0.0.2-2004-02-17-20:53:12 import
Igor Sysoev <igor@sysoev.ru>
parents: 259
diff changeset
90 {
5dacbb4daaf6 nginx-0.0.2-2004-02-17-20:53:12 import
Igor Sysoev <igor@sysoev.ru>
parents: 259
diff changeset
91 ngx_log_error(NGX_LOG_NOTICE, log, err,
5dacbb4daaf6 nginx-0.0.2-2004-02-17-20:53:12 import
Igor Sysoev <igor@sysoev.ru>
parents: 259
diff changeset
92 "EAGAIN after %d accepted connection(s)",
5dacbb4daaf6 nginx-0.0.2-2004-02-17-20:53:12 import
Igor Sysoev <igor@sysoev.ru>
parents: 259
diff changeset
93 accepted);
5dacbb4daaf6 nginx-0.0.2-2004-02-17-20:53:12 import
Igor Sysoev <igor@sysoev.ru>
parents: 259
diff changeset
94 }
425
bd39260a1383 nginx-0.0.10-2004-09-14-19:55:24 import
Igor Sysoev <igor@sysoev.ru>
parents: 419
diff changeset
95 #endif
248
e885208c518b nginx-0.0.2-2004-02-03-00:19:52 import
Igor Sysoev <igor@sysoev.ru>
parents: 247
diff changeset
96
e885208c518b nginx-0.0.2-2004-02-03-00:19:52 import
Igor Sysoev <igor@sysoev.ru>
parents: 247
diff changeset
97 ngx_destroy_pool(pool);
87
5f6d848dcbef nginx-0.0.1-2003-05-13-20:02:32 import
Igor Sysoev <igor@sysoev.ru>
parents: 86
diff changeset
98 return;
0
4eff17414a43 nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
99 }
6
669801705ab1 nginx-0.0.1-2002-08-26-19:18:19 import
Igor Sysoev <igor@sysoev.ru>
parents: 3
diff changeset
100
57
a499e0d1f16e nginx-0.0.1-2003-01-30-10:28:09 import
Igor Sysoev <igor@sysoev.ru>
parents: 44
diff changeset
101 ngx_log_error(NGX_LOG_ALERT, ev->log, err,
461
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 455
diff changeset
102 "accept() on %V failed", &ls->listening->addr_text);
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
295d97d70c69 nginx-0.1.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 444
diff changeset
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 /* reuse the previously allocated pool */
e885208c518b nginx-0.0.2-2004-02-03-00:19:52 import
Igor Sysoev <igor@sysoev.ru>
parents: 247
diff changeset
111 continue;
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 }
e885208c518b nginx-0.0.2-2004-02-03-00:19:52 import
Igor Sysoev <igor@sysoev.ru>
parents: 247
diff changeset
114
97
70d2345a903f nginx-0.0.1-2003-05-29-17:02:09 import
Igor Sysoev <igor@sysoev.ru>
parents: 96
diff changeset
115 ngx_destroy_pool(pool);
70d2345a903f nginx-0.0.1-2003-05-29-17:02:09 import
Igor Sysoev <igor@sysoev.ru>
parents: 96
diff changeset
116 return;
70d2345a903f nginx-0.0.1-2003-05-29-17:02:09 import
Igor Sysoev <igor@sysoev.ru>
parents: 96
diff changeset
117 }
70d2345a903f nginx-0.0.1-2003-05-29-17:02:09 import
Igor Sysoev <igor@sysoev.ru>
parents: 96
diff changeset
118
426
3f88935a02e8 nginx-0.0.10-2004-09-14-23:39:54 import
Igor Sysoev <igor@sysoev.ru>
parents: 425
diff changeset
119 #if (NGX_STAT_STUB)
493
975f62e77f02 nginx-0.1.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 487
diff changeset
120 ngx_atomic_inc(ngx_stat_accepted);
495
fc9909c369b2 nginx-0.1.22-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 493
diff changeset
121 ngx_atomic_inc(ngx_stat_active);
426
3f88935a02e8 nginx-0.0.10-2004-09-14-23:39:54 import
Igor Sysoev <igor@sysoev.ru>
parents: 425
diff changeset
122 #endif
323
ba876b26b76d nginx-0.0.3-2004-04-21-22:54:33 import
Igor Sysoev <igor@sysoev.ru>
parents: 315
diff changeset
123
ba876b26b76d nginx-0.0.3-2004-04-21-22:54:33 import
Igor Sysoev <igor@sysoev.ru>
parents: 315
diff changeset
124 ngx_accept_disabled = (ngx_uint_t) s + NGX_ACCEPT_THRESHOLD
ba876b26b76d nginx-0.0.3-2004-04-21-22:54:33 import
Igor Sysoev <igor@sysoev.ru>
parents: 315
diff changeset
125 - ecf->connections;
ba876b26b76d nginx-0.0.3-2004-04-21-22:54:33 import
Igor Sysoev <igor@sysoev.ru>
parents: 315
diff changeset
126
121
b3655b21375a nginx-0.0.1-2003-07-22-23:53:10 import
Igor Sysoev <igor@sysoev.ru>
parents: 119
diff changeset
127 /* disable warning: Win32 SOCKET is u_int while UNIX socket is int */
119
cd54bcbaf3b5 nginx-0.0.1-2003-07-21-01:15:59 import
Igor Sysoev <igor@sysoev.ru>
parents: 117
diff changeset
128
323
ba876b26b76d nginx-0.0.3-2004-04-21-22:54:33 import
Igor Sysoev <igor@sysoev.ru>
parents: 315
diff changeset
129 if ((ngx_uint_t) s >= ecf->connections) {
97
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 ngx_log_error(NGX_LOG_ALERT, ev->log, 0,
461
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 455
diff changeset
132 "accept() on %V returned socket #%d while "
97
70d2345a903f nginx-0.0.1-2003-05-29-17:02:09 import
Igor Sysoev <igor@sysoev.ru>
parents: 96
diff changeset
133 "only %d connections was configured, "
192
31824be1fc66 nginx-0.0.1-2003-11-20-10:05:50 import; auto/configure
Igor Sysoev <igor@sysoev.ru>
parents: 191
diff changeset
134 "closing the connection",
461
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 455
diff changeset
135 &ls->listening->addr_text, s, ecf->connections);
97
70d2345a903f nginx-0.0.1-2003-05-29-17:02:09 import
Igor Sysoev <igor@sysoev.ru>
parents: 96
diff changeset
136
419
47709bff4468 nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 396
diff changeset
137 ngx_close_accepted_socket(s, log);
97
70d2345a903f nginx-0.0.1-2003-05-29-17:02:09 import
Igor Sysoev <igor@sysoev.ru>
parents: 96
diff changeset
138 ngx_destroy_pool(pool);
87
5f6d848dcbef nginx-0.0.1-2003-05-13-20:02:32 import
Igor Sysoev <igor@sysoev.ru>
parents: 86
diff changeset
139 return;
0
4eff17414a43 nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
140 }
6
669801705ab1 nginx-0.0.1-2002-08-26-19:18:19 import
Igor Sysoev <igor@sysoev.ru>
parents: 3
diff changeset
141
487
31ff3e943e16 nginx-0.1.18-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 483
diff changeset
142 /* set a blocking mode for aio 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
143
93
738fe44c70d5 nginx-0.0.1-2003-05-21-17:28:21 import
Igor Sysoev <igor@sysoev.ru>
parents: 92
diff changeset
144 if (ngx_inherited_nonblocking) {
738fe44c70d5 nginx-0.0.1-2003-05-21-17:28:21 import
Igor Sysoev <igor@sysoev.ru>
parents: 92
diff changeset
145 if ((ngx_event_flags & NGX_USE_AIO_EVENT)) {
738fe44c70d5 nginx-0.0.1-2003-05-21-17:28:21 import
Igor Sysoev <igor@sysoev.ru>
parents: 92
diff changeset
146 if (ngx_blocking(s) == -1) {
191
71ce40b3c37b nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents: 164
diff changeset
147 ngx_log_error(NGX_LOG_ALERT, log, ngx_socket_errno,
71ce40b3c37b nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents: 164
diff changeset
148 ngx_blocking_n " failed");
97
70d2345a903f nginx-0.0.1-2003-05-29-17:02:09 import
Igor Sysoev <igor@sysoev.ru>
parents: 96
diff changeset
149
419
47709bff4468 nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 396
diff changeset
150 ngx_close_accepted_socket(s, log);
97
70d2345a903f nginx-0.0.1-2003-05-29-17:02:09 import
Igor Sysoev <igor@sysoev.ru>
parents: 96
diff changeset
151 ngx_destroy_pool(pool);
93
738fe44c70d5 nginx-0.0.1-2003-05-21-17:28:21 import
Igor Sysoev <igor@sysoev.ru>
parents: 92
diff changeset
152 return;
738fe44c70d5 nginx-0.0.1-2003-05-21-17:28:21 import
Igor Sysoev <igor@sysoev.ru>
parents: 92
diff changeset
153 }
738fe44c70d5 nginx-0.0.1-2003-05-21-17:28:21 import
Igor Sysoev <igor@sysoev.ru>
parents: 92
diff changeset
154 }
738fe44c70d5 nginx-0.0.1-2003-05-21-17:28:21 import
Igor Sysoev <igor@sysoev.ru>
parents: 92
diff changeset
155
738fe44c70d5 nginx-0.0.1-2003-05-21-17:28:21 import
Igor Sysoev <igor@sysoev.ru>
parents: 92
diff changeset
156 } else {
346
55e496a8ece3 nginx-0.0.3-2004-06-06-23:49:18 import
Igor Sysoev <igor@sysoev.ru>
parents: 323
diff changeset
157 if (!(ngx_event_flags & (NGX_USE_AIO_EVENT|NGX_USE_RTSIG_EVENT))) {
93
738fe44c70d5 nginx-0.0.1-2003-05-21-17:28:21 import
Igor Sysoev <igor@sysoev.ru>
parents: 92
diff changeset
158 if (ngx_nonblocking(s) == -1) {
191
71ce40b3c37b nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents: 164
diff changeset
159 ngx_log_error(NGX_LOG_ALERT, log, ngx_socket_errno,
71ce40b3c37b nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents: 164
diff changeset
160 ngx_nonblocking_n " failed");
97
70d2345a903f nginx-0.0.1-2003-05-29-17:02:09 import
Igor Sysoev <igor@sysoev.ru>
parents: 96
diff changeset
161
419
47709bff4468 nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 396
diff changeset
162 ngx_close_accepted_socket(s, log);
97
70d2345a903f nginx-0.0.1-2003-05-29-17:02:09 import
Igor Sysoev <igor@sysoev.ru>
parents: 96
diff changeset
163 ngx_destroy_pool(pool);
93
738fe44c70d5 nginx-0.0.1-2003-05-21-17:28:21 import
Igor Sysoev <igor@sysoev.ru>
parents: 92
diff changeset
164 return;
738fe44c70d5 nginx-0.0.1-2003-05-21-17:28:21 import
Igor Sysoev <igor@sysoev.ru>
parents: 92
diff changeset
165 }
59
e8cdc2989cee nginx-0.0.1-2003-02-06-20:21:13 import
Igor Sysoev <igor@sysoev.ru>
parents: 57
diff changeset
166 }
e8cdc2989cee nginx-0.0.1-2003-02-06-20:21:13 import
Igor Sysoev <igor@sysoev.ru>
parents: 57
diff changeset
167 }
e8cdc2989cee nginx-0.0.1-2003-02-06-20:21:13 import
Igor Sysoev <igor@sysoev.ru>
parents: 57
diff changeset
168
461
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 455
diff changeset
169 #if (NGX_WIN32)
103
6dfda4cf5200 nginx-0.0.1-2003-06-11-19:28:34 import
Igor Sysoev <igor@sysoev.ru>
parents: 100
diff changeset
170 /*
6dfda4cf5200 nginx-0.0.1-2003-06-11-19:28:34 import
Igor Sysoev <igor@sysoev.ru>
parents: 100
diff changeset
171 * Winsock assignes a socket number divisible by 4
6dfda4cf5200 nginx-0.0.1-2003-06-11-19:28:34 import
Igor Sysoev <igor@sysoev.ru>
parents: 100
diff changeset
172 * so to find a connection we divide a socket number by 4.
6dfda4cf5200 nginx-0.0.1-2003-06-11-19:28:34 import
Igor Sysoev <igor@sysoev.ru>
parents: 100
diff changeset
173 */
6dfda4cf5200 nginx-0.0.1-2003-06-11-19:28:34 import
Igor Sysoev <igor@sysoev.ru>
parents: 100
diff changeset
174
6dfda4cf5200 nginx-0.0.1-2003-06-11-19:28:34 import
Igor Sysoev <igor@sysoev.ru>
parents: 100
diff changeset
175 if (s % 4) {
191
71ce40b3c37b nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents: 164
diff changeset
176 ngx_log_error(NGX_LOG_EMERG, ev->log, 0,
461
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 455
diff changeset
177 "accept() on %V returned socket #%d, "
191
71ce40b3c37b nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents: 164
diff changeset
178 "not divisible by 4",
461
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 455
diff changeset
179 &ls->listening->addr_text, s);
103
6dfda4cf5200 nginx-0.0.1-2003-06-11-19:28:34 import
Igor Sysoev <igor@sysoev.ru>
parents: 100
diff changeset
180 exit(1);
6dfda4cf5200 nginx-0.0.1-2003-06-11-19:28:34 import
Igor Sysoev <igor@sysoev.ru>
parents: 100
diff changeset
181 }
6dfda4cf5200 nginx-0.0.1-2003-06-11-19:28:34 import
Igor Sysoev <igor@sysoev.ru>
parents: 100
diff changeset
182
114
ac69ab96328d nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents: 113
diff changeset
183 c = &ngx_cycle->connections[s / 4];
ac69ab96328d nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents: 113
diff changeset
184 rev = &ngx_cycle->read_events[s / 4];
ac69ab96328d nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents: 113
diff changeset
185 wev = &ngx_cycle->write_events[s / 4];
103
6dfda4cf5200 nginx-0.0.1-2003-06-11-19:28:34 import
Igor Sysoev <igor@sysoev.ru>
parents: 100
diff changeset
186 #else
114
ac69ab96328d nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents: 113
diff changeset
187 c = &ngx_cycle->connections[s];
ac69ab96328d nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents: 113
diff changeset
188 rev = &ngx_cycle->read_events[s];
ac69ab96328d nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents: 113
diff changeset
189 wev = &ngx_cycle->write_events[s];
103
6dfda4cf5200 nginx-0.0.1-2003-06-11-19:28:34 import
Igor Sysoev <igor@sysoev.ru>
parents: 100
diff changeset
190 #endif
26
53cb81681040 nginx-0.0.1-2002-12-15-09:25:09 import
Igor Sysoev <igor@sysoev.ru>
parents: 24
diff changeset
191
86
3973260705cc nginx-0.0.1-2003-05-12-19:52:24 import
Igor Sysoev <igor@sysoev.ru>
parents: 75
diff changeset
192 instance = rev->instance;
3973260705cc nginx-0.0.1-2003-05-12-19:52:24 import
Igor Sysoev <igor@sysoev.ru>
parents: 75
diff changeset
193
377
41437e4fd9b4 nginx-0.0.7-2004-07-05-19:08:23 import
Igor Sysoev <igor@sysoev.ru>
parents: 374
diff changeset
194 #if (NGX_THREADS)
380
5ce6561246a5 nginx-0.0.7-2004-07-07-10:15:04 import
Igor Sysoev <igor@sysoev.ru>
parents: 379
diff changeset
195
5ce6561246a5 nginx-0.0.7-2004-07-07-10:15:04 import
Igor Sysoev <igor@sysoev.ru>
parents: 379
diff changeset
196 if (*(&c->lock)) {
379
73688d5d7fc3 nginx-0.0.7-2004-07-06-20:12:16 import
Igor Sysoev <igor@sysoev.ru>
parents: 377
diff changeset
197 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, ev->log, 0,
380
5ce6561246a5 nginx-0.0.7-2004-07-07-10:15:04 import
Igor Sysoev <igor@sysoev.ru>
parents: 379
diff changeset
198 "spinlock in accept, fd:%", s);
5ce6561246a5 nginx-0.0.7-2004-07-07-10:15:04 import
Igor Sysoev <igor@sysoev.ru>
parents: 379
diff changeset
199 ngx_spinlock(&c->lock, 1000);
5ce6561246a5 nginx-0.0.7-2004-07-07-10:15:04 import
Igor Sysoev <igor@sysoev.ru>
parents: 379
diff changeset
200 ngx_unlock(&c->lock);
377
41437e4fd9b4 nginx-0.0.7-2004-07-05-19:08:23 import
Igor Sysoev <igor@sysoev.ru>
parents: 374
diff changeset
201 }
380
5ce6561246a5 nginx-0.0.7-2004-07-07-10:15:04 import
Igor Sysoev <igor@sysoev.ru>
parents: 379
diff changeset
202
377
41437e4fd9b4 nginx-0.0.7-2004-07-05-19:08:23 import
Igor Sysoev <igor@sysoev.ru>
parents: 374
diff changeset
203 #endif
41437e4fd9b4 nginx-0.0.7-2004-07-05-19:08:23 import
Igor Sysoev <igor@sysoev.ru>
parents: 374
diff changeset
204
26
53cb81681040 nginx-0.0.1-2002-12-15-09:25:09 import
Igor Sysoev <igor@sysoev.ru>
parents: 24
diff changeset
205 ngx_memzero(rev, sizeof(ngx_event_t));
53cb81681040 nginx-0.0.1-2002-12-15-09:25:09 import
Igor Sysoev <igor@sysoev.ru>
parents: 24
diff changeset
206 ngx_memzero(wev, sizeof(ngx_event_t));
53cb81681040 nginx-0.0.1-2002-12-15-09:25:09 import
Igor Sysoev <igor@sysoev.ru>
parents: 24
diff changeset
207 ngx_memzero(c, sizeof(ngx_connection_t));
0
4eff17414a43 nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
208
57
a499e0d1f16e nginx-0.0.1-2003-01-30-10:28:09 import
Igor Sysoev <igor@sysoev.ru>
parents: 44
diff changeset
209 c->pool = pool;
a499e0d1f16e nginx-0.0.1-2003-01-30-10:28:09 import
Igor Sysoev <igor@sysoev.ru>
parents: 44
diff changeset
210
103
6dfda4cf5200 nginx-0.0.1-2003-06-11-19:28:34 import
Igor Sysoev <igor@sysoev.ru>
parents: 100
diff changeset
211 c->listening = ls->listening;
57
a499e0d1f16e nginx-0.0.1-2003-01-30-10:28:09 import
Igor Sysoev <igor@sysoev.ru>
parents: 44
diff changeset
212 c->sockaddr = sa;
a499e0d1f16e nginx-0.0.1-2003-01-30-10:28:09 import
Igor Sysoev <igor@sysoev.ru>
parents: 44
diff changeset
213 c->socklen = len;
6
669801705ab1 nginx-0.0.1-2002-08-26-19:18:19 import
Igor Sysoev <igor@sysoev.ru>
parents: 3
diff changeset
214
381
02a511569afb nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents: 380
diff changeset
215 rev->instance = !instance;
02a511569afb nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents: 380
diff changeset
216 wev->instance = !instance;
86
3973260705cc nginx-0.0.1-2003-05-12-19:52:24 import
Igor Sysoev <igor@sysoev.ru>
parents: 75
diff changeset
217
191
71ce40b3c37b nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents: 164
diff changeset
218 rev->index = NGX_INVALID_INDEX;
71ce40b3c37b nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents: 164
diff changeset
219 wev->index = NGX_INVALID_INDEX;
0
4eff17414a43 nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
220
191
71ce40b3c37b nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents: 164
diff changeset
221 rev->data = c;
71ce40b3c37b nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents: 164
diff changeset
222 wev->data = c;
71ce40b3c37b nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents: 164
diff changeset
223
26
53cb81681040 nginx-0.0.1-2002-12-15-09:25:09 import
Igor Sysoev <igor@sysoev.ru>
parents: 24
diff changeset
224 c->read = rev;
53cb81681040 nginx-0.0.1-2002-12-15-09:25:09 import
Igor Sysoev <igor@sysoev.ru>
parents: 24
diff changeset
225 c->write = wev;
0
4eff17414a43 nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
226
26
53cb81681040 nginx-0.0.1-2002-12-15-09:25:09 import
Igor Sysoev <igor@sysoev.ru>
parents: 24
diff changeset
227 c->fd = s;
53cb81681040 nginx-0.0.1-2002-12-15-09:25:09 import
Igor Sysoev <igor@sysoev.ru>
parents: 24
diff changeset
228 c->unexpected_eof = 1;
191
71ce40b3c37b nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents: 164
diff changeset
229
26
53cb81681040 nginx-0.0.1-2002-12-15-09:25:09 import
Igor Sysoev <igor@sysoev.ru>
parents: 24
diff changeset
230 wev->write = 1;
164
84036764e215 nginx-0.0.1-2003-10-29-11:30:44 import
Igor Sysoev <igor@sysoev.ru>
parents: 121
diff changeset
231 wev->ready = 1;
0
4eff17414a43 nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
232
381
02a511569afb nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents: 380
diff changeset
233 if (ngx_event_flags & (NGX_USE_AIO_EVENT|NGX_USE_RTSIG_EVENT)) {
493
975f62e77f02 nginx-0.1.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 487
diff changeset
234 /* rtsig, aio, iocp */
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;
e6c005b66b3a nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents: 236
diff changeset
240 }
e6c005b66b3a nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents: 236
diff changeset
241
57
a499e0d1f16e nginx-0.0.1-2003-01-30-10:28:09 import
Igor Sysoev <igor@sysoev.ru>
parents: 44
diff changeset
242 c->ctx = ls->ctx;
a499e0d1f16e nginx-0.0.1-2003-01-30-10:28:09 import
Igor Sysoev <igor@sysoev.ru>
parents: 44
diff changeset
243 c->servers = ls->servers;
0
4eff17414a43 nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
244
396
6f3b20c1ac50 nginx-0.0.7-2004-07-18-23:11:20 import
Igor Sysoev <igor@sysoev.ru>
parents: 381
diff changeset
245 c->recv = ngx_recv;
6f3b20c1ac50 nginx-0.0.7-2004-07-18-23:11:20 import
Igor Sysoev <igor@sysoev.ru>
parents: 381
diff changeset
246 c->send_chain = ngx_send_chain;
6f3b20c1ac50 nginx-0.0.7-2004-07-18-23:11:20 import
Igor Sysoev <igor@sysoev.ru>
parents: 381
diff changeset
247
191
71ce40b3c37b nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents: 164
diff changeset
248 c->log = log;
71ce40b3c37b nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents: 164
diff changeset
249 rev->log = log;
71ce40b3c37b nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents: 164
diff changeset
250 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
251
208
0b67be7d4489 nginx-0.0.1-2003-12-08-23:48:12 import
Igor Sysoev <igor@sysoev.ru>
parents: 206
diff changeset
252 /*
257
70e1c7d2b83d nginx-0.0.2-2004-02-11-20:08:49 import
Igor Sysoev <igor@sysoev.ru>
parents: 253
diff changeset
253 * TODO: MT: - atomic increment (x86: lock xadd)
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 *
0b67be7d4489 nginx-0.0.1-2003-12-08-23:48:12 import
Igor Sysoev <igor@sysoev.ru>
parents: 206
diff changeset
256 * TODO: MP: - allocated in a shared memory
0b67be7d4489 nginx-0.0.1-2003-12-08-23:48:12 import
Igor Sysoev <igor@sysoev.ru>
parents: 206
diff changeset
257 * - atomic increment (x86: lock xadd)
266
5238e93961a1 nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents: 260
diff changeset
258 * 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
259 */
212
679f60139863 nginx-0.0.1-2003-12-19-11:15:11 import
Igor Sysoev <igor@sysoev.ru>
parents: 208
diff changeset
260
309
2e899477243a nginx-0.0.3-2004-04-09-20:03:04 import
Igor Sysoev <igor@sysoev.ru>
parents: 307
diff changeset
261 c->number = ngx_atomic_inc(ngx_connection_counter);
26
53cb81681040 nginx-0.0.1-2002-12-15-09:25:09 import
Igor Sysoev <igor@sysoev.ru>
parents: 24
diff changeset
262
495
fc9909c369b2 nginx-0.1.22-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 493
diff changeset
263 #if (NGX_STAT_STUB)
fc9909c369b2 nginx-0.1.22-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 493
diff changeset
264 ngx_atomic_inc(ngx_stat_handled);
fc9909c369b2 nginx-0.1.22-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 493
diff changeset
265 #endif
fc9909c369b2 nginx-0.1.22-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 493
diff changeset
266
370
54f76b0b8dca nginx-0.0.7-2004-06-27-22:01:57 import
Igor Sysoev <igor@sysoev.ru>
parents: 350
diff changeset
267 #if (NGX_THREADS)
54f76b0b8dca nginx-0.0.7-2004-06-27-22:01:57 import
Igor Sysoev <igor@sysoev.ru>
parents: 350
diff changeset
268 rev->lock = &c->lock;
54f76b0b8dca nginx-0.0.7-2004-06-27-22:01:57 import
Igor Sysoev <igor@sysoev.ru>
parents: 350
diff changeset
269 wev->lock = &c->lock;
380
5ce6561246a5 nginx-0.0.7-2004-07-07-10:15:04 import
Igor Sysoev <igor@sysoev.ru>
parents: 379
diff changeset
270 rev->own_lock = &c->lock;
5ce6561246a5 nginx-0.0.7-2004-07-07-10:15:04 import
Igor Sysoev <igor@sysoev.ru>
parents: 379
diff changeset
271 wev->own_lock = &c->lock;
370
54f76b0b8dca nginx-0.0.7-2004-06-27-22:01:57 import
Igor Sysoev <igor@sysoev.ru>
parents: 350
diff changeset
272 #endif
54f76b0b8dca nginx-0.0.7-2004-06-27-22:01:57 import
Igor Sysoev <igor@sysoev.ru>
parents: 350
diff changeset
273
236
86e473b5641e nginx-0.0.1-2004-01-22-09:47:28 import
Igor Sysoev <igor@sysoev.ru>
parents: 212
diff changeset
274 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, ev->log, 0,
266
5238e93961a1 nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents: 260
diff changeset
275 "accept: fd:%d c:%d", s, c->number);
6
669801705ab1 nginx-0.0.1-2002-08-26-19:18:19 import
Igor Sysoev <igor@sysoev.ru>
parents: 3
diff changeset
276
419
47709bff4468 nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 396
diff changeset
277 if (c->listening->addr_ntop) {
47709bff4468 nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 396
diff changeset
278 c->addr_text.data = ngx_palloc(c->pool,
47709bff4468 nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 396
diff changeset
279 c->listening->addr_text_max_len);
47709bff4468 nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 396
diff changeset
280 if (c->addr_text.data == NULL) {
47709bff4468 nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 396
diff changeset
281 ngx_close_accepted_socket(s, log);
47709bff4468 nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 396
diff changeset
282 ngx_destroy_pool(pool);
47709bff4468 nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 396
diff changeset
283 return;
47709bff4468 nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 396
diff changeset
284 }
47709bff4468 nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 396
diff changeset
285
47709bff4468 nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 396
diff changeset
286 c->addr_text.len = ngx_sock_ntop(c->listening->family, c->sockaddr,
47709bff4468 nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 396
diff changeset
287 c->addr_text.data,
47709bff4468 nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 396
diff changeset
288 c->listening->addr_text_max_len);
47709bff4468 nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 396
diff changeset
289 if (c->addr_text.len == 0) {
47709bff4468 nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 396
diff changeset
290 ngx_close_accepted_socket(s, log);
47709bff4468 nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 396
diff changeset
291 ngx_destroy_pool(pool);
47709bff4468 nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 396
diff changeset
292 return;
47709bff4468 nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 396
diff changeset
293 }
47709bff4468 nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 396
diff changeset
294 }
47709bff4468 nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 396
diff changeset
295
307
ce375c313e96 nginx-0.0.3-2004-04-08-19:58:25 import
Igor Sysoev <igor@sysoev.ru>
parents: 306
diff changeset
296 #if (NGX_DEBUG)
ce375c313e96 nginx-0.0.3-2004-04-08-19:58:25 import
Igor Sysoev <igor@sysoev.ru>
parents: 306
diff changeset
297 {
ce375c313e96 nginx-0.0.3-2004-04-08-19:58:25 import
Igor Sysoev <igor@sysoev.ru>
parents: 306
diff changeset
298
ce375c313e96 nginx-0.0.3-2004-04-08-19:58:25 import
Igor Sysoev <igor@sysoev.ru>
parents: 306
diff changeset
299 uint32_t *addr;
ce375c313e96 nginx-0.0.3-2004-04-08-19:58:25 import
Igor Sysoev <igor@sysoev.ru>
parents: 306
diff changeset
300 in_addr_t i;
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 477
diff changeset
301 struct sockaddr_in *sin;
307
ce375c313e96 nginx-0.0.3-2004-04-08-19:58:25 import
Igor Sysoev <igor@sysoev.ru>
parents: 306
diff changeset
302
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 477
diff changeset
303 sin = (struct sockaddr_in *) sa;
307
ce375c313e96 nginx-0.0.3-2004-04-08-19:58:25 import
Igor Sysoev <igor@sysoev.ru>
parents: 306
diff changeset
304 addr = ecf->debug_connection.elts;
ce375c313e96 nginx-0.0.3-2004-04-08-19:58:25 import
Igor Sysoev <igor@sysoev.ru>
parents: 306
diff changeset
305 for (i = 0; i < ecf->debug_connection.nelts; i++) {
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 477
diff changeset
306 if (addr[i] == sin->sin_addr.s_addr) {
307
ce375c313e96 nginx-0.0.3-2004-04-08-19:58:25 import
Igor Sysoev <igor@sysoev.ru>
parents: 306
diff changeset
307 log->log_level = NGX_LOG_DEBUG_CONNECTION|NGX_LOG_DEBUG_ALL;
ce375c313e96 nginx-0.0.3-2004-04-08-19:58:25 import
Igor Sysoev <igor@sysoev.ru>
parents: 306
diff changeset
308 break;
ce375c313e96 nginx-0.0.3-2004-04-08-19:58:25 import
Igor Sysoev <igor@sysoev.ru>
parents: 306
diff changeset
309 }
ce375c313e96 nginx-0.0.3-2004-04-08-19:58:25 import
Igor Sysoev <igor@sysoev.ru>
parents: 306
diff changeset
310 }
ce375c313e96 nginx-0.0.3-2004-04-08-19:58:25 import
Igor Sysoev <igor@sysoev.ru>
parents: 306
diff changeset
311
ce375c313e96 nginx-0.0.3-2004-04-08-19:58:25 import
Igor Sysoev <igor@sysoev.ru>
parents: 306
diff changeset
312 }
ce375c313e96 nginx-0.0.3-2004-04-08-19:58:25 import
Igor Sysoev <igor@sysoev.ru>
parents: 306
diff changeset
313 #endif
ce375c313e96 nginx-0.0.3-2004-04-08-19:58:25 import
Igor Sysoev <igor@sysoev.ru>
parents: 306
diff changeset
314
381
02a511569afb nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents: 380
diff changeset
315 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
316 if (ngx_add_conn(c) == NGX_ERROR) {
419
47709bff4468 nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 396
diff changeset
317 ngx_close_accepted_socket(s, log);
97
70d2345a903f nginx-0.0.1-2003-05-29-17:02:09 import
Igor Sysoev <igor@sysoev.ru>
parents: 96
diff changeset
318 ngx_destroy_pool(pool);
87
5f6d848dcbef nginx-0.0.1-2003-05-13-20:02:32 import
Igor Sysoev <igor@sysoev.ru>
parents: 86
diff changeset
319 return;
64
34d647deb1da nginx-0.0.1-2003-03-04-09:33:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 63
diff changeset
320 }
34d647deb1da nginx-0.0.1-2003-03-04-09:33:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 63
diff changeset
321 }
34d647deb1da nginx-0.0.1-2003-03-04-09:33:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 63
diff changeset
322
248
e885208c518b nginx-0.0.2-2004-02-03-00:19:52 import
Igor Sysoev <igor@sysoev.ru>
parents: 247
diff changeset
323 pool = NULL;
e885208c518b nginx-0.0.2-2004-02-03-00:19:52 import
Igor Sysoev <igor@sysoev.ru>
parents: 247
diff changeset
324
191
71ce40b3c37b nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents: 164
diff changeset
325 log->data = NULL;
71ce40b3c37b nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents: 164
diff changeset
326 log->handler = NULL;
71ce40b3c37b nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents: 164
diff changeset
327
103
6dfda4cf5200 nginx-0.0.1-2003-06-11-19:28:34 import
Igor Sysoev <igor@sysoev.ru>
parents: 100
diff changeset
328 ls->listening->handler(c);
57
a499e0d1f16e nginx-0.0.1-2003-01-30-10:28:09 import
Igor Sysoev <igor@sysoev.ru>
parents: 44
diff changeset
329
455
295d97d70c69 nginx-0.1.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 444
diff changeset
330 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
331 ev->available--;
57
a499e0d1f16e nginx-0.0.1-2003-01-30-10:28:09 import
Igor Sysoev <igor@sysoev.ru>
parents: 44
diff changeset
332 }
191
71ce40b3c37b nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents: 164
diff changeset
333
71ce40b3c37b nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents: 164
diff changeset
334 accepted++;
57
a499e0d1f16e nginx-0.0.1-2003-01-30-10:28:09 import
Igor Sysoev <igor@sysoev.ru>
parents: 44
diff changeset
335
0
4eff17414a43 nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
336 } while (ev->available);
4eff17414a43 nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
337 }
191
71ce40b3c37b nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents: 164
diff changeset
338
71ce40b3c37b nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents: 164
diff changeset
339
493
975f62e77f02 nginx-0.1.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 487
diff changeset
340 ngx_int_t
975f62e77f02 nginx-0.1.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 487
diff changeset
341 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
342 {
306
6b91bfbc4123 nginx-0.0.3-2004-04-05-00:32:09 import
Igor Sysoev <igor@sysoev.ru>
parents: 303
diff changeset
343 if (*ngx_accept_mutex == 0
6b91bfbc4123 nginx-0.0.3-2004-04-05-00:32:09 import
Igor Sysoev <igor@sysoev.ru>
parents: 303
diff changeset
344 && ngx_atomic_cmp_set(ngx_accept_mutex, 0, ngx_pid))
6b91bfbc4123 nginx-0.0.3-2004-04-05-00:32:09 import
Igor Sysoev <igor@sysoev.ru>
parents: 303
diff changeset
345 {
301
744965ec6275 nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
346 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
347 "accept mutex locked");
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 if (!ngx_accept_mutex_held) {
301
744965ec6275 nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
350 if (ngx_enable_accept_events(cycle) == NGX_ERROR) {
302
1526e7686b20 nginx-0.0.3-2004-04-01-10:21:13 import
Igor Sysoev <igor@sysoev.ru>
parents: 301
diff changeset
351 *ngx_accept_mutex = 0;
301
744965ec6275 nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
352 return NGX_ERROR;
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
302
1526e7686b20 nginx-0.0.3-2004-04-01-10:21:13 import
Igor Sysoev <igor@sysoev.ru>
parents: 301
diff changeset
355 ngx_accept_mutex_held = 1;
301
744965ec6275 nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
356 }
744965ec6275 nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
357
744965ec6275 nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
358 return NGX_OK;
744965ec6275 nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
359 }
744965ec6275 nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
360
302
1526e7686b20 nginx-0.0.3-2004-04-01-10:21:13 import
Igor Sysoev <igor@sysoev.ru>
parents: 301
diff changeset
361 if (ngx_accept_mutex_held) {
301
744965ec6275 nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
362 if (ngx_disable_accept_events(cycle) == NGX_ERROR) {
744965ec6275 nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
363 return NGX_ERROR;
744965ec6275 nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
364 }
744965ec6275 nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
365
302
1526e7686b20 nginx-0.0.3-2004-04-01-10:21:13 import
Igor Sysoev <igor@sysoev.ru>
parents: 301
diff changeset
366 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
367 }
744965ec6275 nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
368
744965ec6275 nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
369 return NGX_OK;
744965ec6275 nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
370 }
744965ec6275 nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
371
744965ec6275 nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
372
493
975f62e77f02 nginx-0.1.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 487
diff changeset
373 ngx_int_t
975f62e77f02 nginx-0.1.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 487
diff changeset
374 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
375 {
744965ec6275 nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
376 ngx_uint_t i;
744965ec6275 nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
377 ngx_listening_t *s;
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 s = cycle->listening.elts;
744965ec6275 nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
380 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
381
744965ec6275 nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
382 /*
346
55e496a8ece3 nginx-0.0.3-2004-06-06-23:49:18 import
Igor Sysoev <igor@sysoev.ru>
parents: 323
diff changeset
383 * we do not need to handle the Winsock sockets here (divide a socket
301
744965ec6275 nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
384 * number by 4) because this function would never called
744965ec6275 nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
385 * in the Winsock environment
744965ec6275 nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
386 */
744965ec6275 nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
387
346
55e496a8ece3 nginx-0.0.3-2004-06-06-23:49:18 import
Igor Sysoev <igor@sysoev.ru>
parents: 323
diff changeset
388 if (ngx_event_flags & NGX_USE_RTSIG_EVENT) {
301
744965ec6275 nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
389 if (ngx_add_conn(&cycle->connections[s[i].fd]) == NGX_ERROR) {
744965ec6275 nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
390 return NGX_ERROR;
744965ec6275 nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
391 }
744965ec6275 nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
392
744965ec6275 nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
393 } else {
744965ec6275 nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
394 if (ngx_add_event(&cycle->read_events[s[i].fd], NGX_READ_EVENT, 0)
744965ec6275 nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
395 == NGX_ERROR)
744965ec6275 nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
396 {
744965ec6275 nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
397 return NGX_ERROR;
744965ec6275 nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
398 }
744965ec6275 nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
399 }
744965ec6275 nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
400 }
744965ec6275 nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
401
744965ec6275 nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
402 return NGX_OK;
744965ec6275 nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
403 }
744965ec6275 nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
404
744965ec6275 nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
405
493
975f62e77f02 nginx-0.1.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 487
diff changeset
406 ngx_int_t
975f62e77f02 nginx-0.1.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 487
diff changeset
407 ngx_disable_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
408 {
744965ec6275 nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
409 ngx_uint_t i;
744965ec6275 nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
410 ngx_listening_t *s;
744965ec6275 nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
411
744965ec6275 nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
412 s = cycle->listening.elts;
744965ec6275 nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
413 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
414
744965ec6275 nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
415 /*
346
55e496a8ece3 nginx-0.0.3-2004-06-06-23:49:18 import
Igor Sysoev <igor@sysoev.ru>
parents: 323
diff changeset
416 * we do not need to handle the Winsock sockets here (divide a socket
301
744965ec6275 nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
417 * number by 4) because this function would never called
744965ec6275 nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
418 * in the Winsock environment
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
346
55e496a8ece3 nginx-0.0.3-2004-06-06-23:49:18 import
Igor Sysoev <igor@sysoev.ru>
parents: 323
diff changeset
421 if (ngx_event_flags & NGX_USE_RTSIG_EVENT) {
315
39b6f2df45c0 nginx-0.0.3-2004-04-14-21:44:28 import
Igor Sysoev <igor@sysoev.ru>
parents: 312
diff changeset
422 if (!cycle->connections[s[i].fd].read->active) {
39b6f2df45c0 nginx-0.0.3-2004-04-14-21:44:28 import
Igor Sysoev <igor@sysoev.ru>
parents: 312
diff changeset
423 continue;
39b6f2df45c0 nginx-0.0.3-2004-04-14-21:44:28 import
Igor Sysoev <igor@sysoev.ru>
parents: 312
diff changeset
424 }
39b6f2df45c0 nginx-0.0.3-2004-04-14-21:44:28 import
Igor Sysoev <igor@sysoev.ru>
parents: 312
diff changeset
425
301
744965ec6275 nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
426 if (ngx_del_conn(&cycle->connections[s[i].fd], NGX_DISABLE_EVENT)
744965ec6275 nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
427 == NGX_ERROR)
744965ec6275 nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
428 {
744965ec6275 nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
429 return NGX_ERROR;
744965ec6275 nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
430 }
744965ec6275 nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
431
744965ec6275 nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
432 } else {
315
39b6f2df45c0 nginx-0.0.3-2004-04-14-21:44:28 import
Igor Sysoev <igor@sysoev.ru>
parents: 312
diff changeset
433 if (!cycle->read_events[s[i].fd].active) {
39b6f2df45c0 nginx-0.0.3-2004-04-14-21:44:28 import
Igor Sysoev <igor@sysoev.ru>
parents: 312
diff changeset
434 continue;
39b6f2df45c0 nginx-0.0.3-2004-04-14-21:44:28 import
Igor Sysoev <igor@sysoev.ru>
parents: 312
diff changeset
435 }
39b6f2df45c0 nginx-0.0.3-2004-04-14-21:44:28 import
Igor Sysoev <igor@sysoev.ru>
parents: 312
diff changeset
436
301
744965ec6275 nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
437 if (ngx_del_event(&cycle->read_events[s[i].fd], NGX_READ_EVENT,
744965ec6275 nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
438 NGX_DISABLE_EVENT) == NGX_ERROR)
744965ec6275 nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
439 {
744965ec6275 nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
440 return NGX_ERROR;
744965ec6275 nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
441 }
744965ec6275 nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
442 }
744965ec6275 nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
443 }
744965ec6275 nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
444
744965ec6275 nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
445 return NGX_OK;
744965ec6275 nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
446 }
744965ec6275 nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
447
744965ec6275 nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
448
493
975f62e77f02 nginx-0.1.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 487
diff changeset
449 static void
975f62e77f02 nginx-0.1.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 487
diff changeset
450 ngx_close_accepted_socket(ngx_socket_t s, ngx_log_t *log)
419
47709bff4468 nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 396
diff changeset
451 {
47709bff4468 nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 396
diff changeset
452 if (ngx_close_socket(s) == -1) {
47709bff4468 nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 396
diff changeset
453 ngx_log_error(NGX_LOG_ALERT, log, ngx_socket_errno,
47709bff4468 nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 396
diff changeset
454 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
455 }
495
fc9909c369b2 nginx-0.1.22-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 493
diff changeset
456
fc9909c369b2 nginx-0.1.22-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 493
diff changeset
457 #if (NGX_STAT_STUB)
fc9909c369b2 nginx-0.1.22-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 493
diff changeset
458 ngx_atomic_dec(ngx_stat_active);
fc9909c369b2 nginx-0.1.22-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 493
diff changeset
459 #endif
419
47709bff4468 nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 396
diff changeset
460 }
47709bff4468 nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 396
diff changeset
461
47709bff4468 nginx-0.0.10-2004-09-09-19:40:48 import
Igor Sysoev <igor@sysoev.ru>
parents: 396
diff changeset
462
493
975f62e77f02 nginx-0.1.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 487
diff changeset
463 static u_char *
975f62e77f02 nginx-0.1.21-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 487
diff changeset
464 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
465 {
483
621229427cba nginx-0.1.16-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 479
diff changeset
466 return ngx_snprintf(buf, len, " while accept() on %V", log->data);
191
71ce40b3c37b nginx-0.0.1-2003-11-19-19:26:41 import
Igor Sysoev <igor@sysoev.ru>
parents: 164
diff changeset
467 }