Mercurial > hg > nginx
annotate src/event/modules/ngx_select_module.c @ 3425:0189a8f4c7c3 stable-0.7
merge r2990, r3324, r3384, r3419:
various proxy/FastCGI fixes:
*) do auto redirect for proxy_pass/fastcgi_pass with variables
*) allow "proxy_pass http://$backend" without URI part
*) add conf/fastcgi.conf
*) delete u->cleanup mark, this fixes large values in $upstream_response_time,
the bug had been introduced in r3246
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Mon, 01 Feb 2010 14:01:24 +0000 |
parents | c00763aa5e1b |
children | a66d6dfd53f1 e1409e56ba7c |
rev | line source |
---|---|
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
87
diff
changeset
|
1 |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
87
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 |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
87
diff
changeset
|
4 */ |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
87
diff
changeset
|
5 |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
6 |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
7 #include <ngx_config.h> |
8
708f8bb772ec
nginx-0.0.1-2002-09-02-18:48:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
7
diff
changeset
|
8 #include <ngx_core.h> |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
9 #include <ngx_event.h> |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
10 |
26
53cb81681040
nginx-0.0.1-2002-12-15-09:25:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
23
diff
changeset
|
11 |
563 | 12 static ngx_int_t ngx_select_init(ngx_cycle_t *cycle, ngx_msec_t timer); |
114
ac69ab96328d
nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
107
diff
changeset
|
13 static void ngx_select_done(ngx_cycle_t *cycle); |
1354
f69d1aab6a0f
make 64-bit ngx_int_t on 64-bit platforms
Igor Sysoev <igor@sysoev.ru>
parents:
708
diff
changeset
|
14 static ngx_int_t ngx_select_add_event(ngx_event_t *ev, ngx_int_t event, |
f69d1aab6a0f
make 64-bit ngx_int_t on 64-bit platforms
Igor Sysoev <igor@sysoev.ru>
parents:
708
diff
changeset
|
15 ngx_uint_t flags); |
f69d1aab6a0f
make 64-bit ngx_int_t on 64-bit platforms
Igor Sysoev <igor@sysoev.ru>
parents:
708
diff
changeset
|
16 static ngx_int_t ngx_select_del_event(ngx_event_t *ev, ngx_int_t event, |
f69d1aab6a0f
make 64-bit ngx_int_t on 64-bit platforms
Igor Sysoev <igor@sysoev.ru>
parents:
708
diff
changeset
|
17 ngx_uint_t flags); |
563 | 18 static ngx_int_t ngx_select_process_events(ngx_cycle_t *cycle, ngx_msec_t timer, |
19 ngx_uint_t flags); | |
2780 | 20 static void ngx_select_repair_fd_sets(ngx_cycle_t *cycle); |
114
ac69ab96328d
nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
107
diff
changeset
|
21 static char *ngx_select_init_conf(ngx_cycle_t *cycle, void *conf); |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
87
diff
changeset
|
22 |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
87
diff
changeset
|
23 |
26
53cb81681040
nginx-0.0.1-2002-12-15-09:25:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
23
diff
changeset
|
24 static fd_set master_read_fd_set; |
53cb81681040
nginx-0.0.1-2002-12-15-09:25:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
23
diff
changeset
|
25 static fd_set master_write_fd_set; |
53cb81681040
nginx-0.0.1-2002-12-15-09:25:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
23
diff
changeset
|
26 static fd_set work_read_fd_set; |
53cb81681040
nginx-0.0.1-2002-12-15-09:25:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
23
diff
changeset
|
27 static fd_set work_write_fd_set; |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
28 |
1354
f69d1aab6a0f
make 64-bit ngx_int_t on 64-bit platforms
Igor Sysoev <igor@sysoev.ru>
parents:
708
diff
changeset
|
29 static ngx_int_t max_fd; |
314
d71c87d11b16
nginx-0.0.3-2004-04-14-09:57:36 import
Igor Sysoev <igor@sysoev.ru>
parents:
302
diff
changeset
|
30 static ngx_uint_t nevents; |
17
8dd06e2844f5
nginx-0.0.1-2002-09-27-19:05:29 import
Igor Sysoev <igor@sysoev.ru>
parents:
13
diff
changeset
|
31 |
8dd06e2844f5
nginx-0.0.1-2002-09-27-19:05:29 import
Igor Sysoev <igor@sysoev.ru>
parents:
13
diff
changeset
|
32 static ngx_event_t **event_index; |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
87
diff
changeset
|
33 |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
87
diff
changeset
|
34 |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
87
diff
changeset
|
35 static ngx_str_t select_name = ngx_string("select"); |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
87
diff
changeset
|
36 |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
87
diff
changeset
|
37 ngx_event_module_t ngx_select_module_ctx = { |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
87
diff
changeset
|
38 &select_name, |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
87
diff
changeset
|
39 NULL, /* create configuration */ |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
87
diff
changeset
|
40 ngx_select_init_conf, /* init configuration */ |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
41 |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
87
diff
changeset
|
42 { |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
87
diff
changeset
|
43 ngx_select_add_event, /* add an event */ |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
87
diff
changeset
|
44 ngx_select_del_event, /* delete an event */ |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
87
diff
changeset
|
45 ngx_select_add_event, /* enable an event */ |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
87
diff
changeset
|
46 ngx_select_del_event, /* disable an event */ |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
87
diff
changeset
|
47 NULL, /* add an connection */ |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
87
diff
changeset
|
48 NULL, /* delete an connection */ |
380
5ce6561246a5
nginx-0.0.7-2004-07-07-10:15:04 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
49 NULL, /* process the changes */ |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
87
diff
changeset
|
50 ngx_select_process_events, /* process the events */ |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
87
diff
changeset
|
51 ngx_select_init, /* init the events */ |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
87
diff
changeset
|
52 ngx_select_done /* done the events */ |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
87
diff
changeset
|
53 } |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
87
diff
changeset
|
54 |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
87
diff
changeset
|
55 }; |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
87
diff
changeset
|
56 |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
87
diff
changeset
|
57 ngx_module_t ngx_select_module = { |
509 | 58 NGX_MODULE_V1, |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
87
diff
changeset
|
59 &ngx_select_module_ctx, /* module context */ |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
87
diff
changeset
|
60 NULL, /* module directives */ |
96
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
92
diff
changeset
|
61 NGX_EVENT_MODULE, /* module type */ |
541 | 62 NULL, /* init master */ |
114
ac69ab96328d
nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
107
diff
changeset
|
63 NULL, /* init module */ |
541 | 64 NULL, /* init process */ |
65 NULL, /* init thread */ | |
66 NULL, /* exit thread */ | |
67 NULL, /* exit process */ | |
68 NULL, /* exit master */ | |
69 NGX_MODULE_V1_PADDING | |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
87
diff
changeset
|
70 }; |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
87
diff
changeset
|
71 |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
87
diff
changeset
|
72 |
501 | 73 static ngx_int_t |
563 | 74 ngx_select_init(ngx_cycle_t *cycle, ngx_msec_t timer) |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
75 { |
114
ac69ab96328d
nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
107
diff
changeset
|
76 ngx_event_t **index; |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
87
diff
changeset
|
77 |
114
ac69ab96328d
nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
107
diff
changeset
|
78 if (event_index == NULL) { |
ac69ab96328d
nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
107
diff
changeset
|
79 FD_ZERO(&master_read_fd_set); |
ac69ab96328d
nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
107
diff
changeset
|
80 FD_ZERO(&master_write_fd_set); |
ac69ab96328d
nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
107
diff
changeset
|
81 nevents = 0; |
ac69ab96328d
nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
107
diff
changeset
|
82 } |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
83 |
314
d71c87d11b16
nginx-0.0.3-2004-04-14-09:57:36 import
Igor Sysoev <igor@sysoev.ru>
parents:
302
diff
changeset
|
84 if (ngx_process == NGX_PROCESS_WORKER |
d71c87d11b16
nginx-0.0.3-2004-04-14-09:57:36 import
Igor Sysoev <igor@sysoev.ru>
parents:
302
diff
changeset
|
85 || cycle->old_cycle == NULL |
114
ac69ab96328d
nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
107
diff
changeset
|
86 || cycle->old_cycle->connection_n < cycle->connection_n) |
ac69ab96328d
nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
107
diff
changeset
|
87 { |
501 | 88 index = ngx_alloc(sizeof(ngx_event_t *) * 2 * cycle->connection_n, |
89 cycle->log); | |
90 if (index == NULL) { | |
91 return NGX_ERROR; | |
92 } | |
17
8dd06e2844f5
nginx-0.0.1-2002-09-27-19:05:29 import
Igor Sysoev <igor@sysoev.ru>
parents:
13
diff
changeset
|
93 |
114
ac69ab96328d
nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
107
diff
changeset
|
94 if (event_index) { |
ac69ab96328d
nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
107
diff
changeset
|
95 ngx_memcpy(index, event_index, sizeof(ngx_event_t *) * nevents); |
ac69ab96328d
nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
107
diff
changeset
|
96 ngx_free(event_index); |
ac69ab96328d
nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
107
diff
changeset
|
97 } |
563 | 98 |
114
ac69ab96328d
nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
107
diff
changeset
|
99 event_index = index; |
ac69ab96328d
nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
107
diff
changeset
|
100 } |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
101 |
114
ac69ab96328d
nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
107
diff
changeset
|
102 ngx_io = ngx_os_io; |
ac69ab96328d
nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
107
diff
changeset
|
103 |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
87
diff
changeset
|
104 ngx_event_actions = ngx_select_module_ctx.actions; |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
87
diff
changeset
|
105 |
563 | 106 ngx_event_flags = NGX_USE_LEVEL_EVENT; |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
107 |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
108 max_fd = -1; |
17
8dd06e2844f5
nginx-0.0.1-2002-09-27-19:05:29 import
Igor Sysoev <igor@sysoev.ru>
parents:
13
diff
changeset
|
109 |
8dd06e2844f5
nginx-0.0.1-2002-09-27-19:05:29 import
Igor Sysoev <igor@sysoev.ru>
parents:
13
diff
changeset
|
110 return NGX_OK; |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
111 } |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
112 |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
87
diff
changeset
|
113 |
501 | 114 static void |
115 ngx_select_done(ngx_cycle_t *cycle) | |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
87
diff
changeset
|
116 { |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
87
diff
changeset
|
117 ngx_free(event_index); |
114
ac69ab96328d
nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
107
diff
changeset
|
118 |
ac69ab96328d
nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
107
diff
changeset
|
119 event_index = NULL; |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
87
diff
changeset
|
120 } |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
87
diff
changeset
|
121 |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
87
diff
changeset
|
122 |
501 | 123 static ngx_int_t |
1354
f69d1aab6a0f
make 64-bit ngx_int_t on 64-bit platforms
Igor Sysoev <igor@sysoev.ru>
parents:
708
diff
changeset
|
124 ngx_select_add_event(ngx_event_t *ev, ngx_int_t event, ngx_uint_t flags) |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
125 { |
39
83fa61cd3d2f
nginx-0.0.1-2002-12-24-20:30:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
38
diff
changeset
|
126 ngx_connection_t *c; |
8
708f8bb772ec
nginx-0.0.1-2002-09-02-18:48:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
7
diff
changeset
|
127 |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
87
diff
changeset
|
128 c = ev->data; |
8
708f8bb772ec
nginx-0.0.1-2002-09-02-18:48:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
7
diff
changeset
|
129 |
245
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
230
diff
changeset
|
130 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, ev->log, 0, |
1354
f69d1aab6a0f
make 64-bit ngx_int_t on 64-bit platforms
Igor Sysoev <igor@sysoev.ru>
parents:
708
diff
changeset
|
131 "select add event fd:%d ev:%i", c->fd, event); |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
132 |
38
2ffaa35fba42
nginx-0.0.1-2002-12-24-10:09:57 import
Igor Sysoev <igor@sysoev.ru>
parents:
36
diff
changeset
|
133 if (ev->index != NGX_INVALID_INDEX) { |
2ffaa35fba42
nginx-0.0.1-2002-12-24-10:09:57 import
Igor Sysoev <igor@sysoev.ru>
parents:
36
diff
changeset
|
134 ngx_log_error(NGX_LOG_ALERT, ev->log, 0, |
1354
f69d1aab6a0f
make 64-bit ngx_int_t on 64-bit platforms
Igor Sysoev <igor@sysoev.ru>
parents:
708
diff
changeset
|
135 "select event fd:%d ev:%i is already set", c->fd, event); |
38
2ffaa35fba42
nginx-0.0.1-2002-12-24-10:09:57 import
Igor Sysoev <igor@sysoev.ru>
parents:
36
diff
changeset
|
136 return NGX_OK; |
2ffaa35fba42
nginx-0.0.1-2002-12-24-10:09:57 import
Igor Sysoev <igor@sysoev.ru>
parents:
36
diff
changeset
|
137 } |
2ffaa35fba42
nginx-0.0.1-2002-12-24-10:09:57 import
Igor Sysoev <igor@sysoev.ru>
parents:
36
diff
changeset
|
138 |
2808
b7b2b0ea3366
test event type to prevent errors
Igor Sysoev <igor@sysoev.ru>
parents:
2781
diff
changeset
|
139 if ((event == NGX_READ_EVENT && ev->write) |
b7b2b0ea3366
test event type to prevent errors
Igor Sysoev <igor@sysoev.ru>
parents:
2781
diff
changeset
|
140 || (event == NGX_WRITE_EVENT && !ev->write)) |
b7b2b0ea3366
test event type to prevent errors
Igor Sysoev <igor@sysoev.ru>
parents:
2781
diff
changeset
|
141 { |
b7b2b0ea3366
test event type to prevent errors
Igor Sysoev <igor@sysoev.ru>
parents:
2781
diff
changeset
|
142 ngx_log_error(NGX_LOG_ALERT, ev->log, 0, |
b7b2b0ea3366
test event type to prevent errors
Igor Sysoev <igor@sysoev.ru>
parents:
2781
diff
changeset
|
143 "invalid select %s event fd:%d ev:%i", |
b7b2b0ea3366
test event type to prevent errors
Igor Sysoev <igor@sysoev.ru>
parents:
2781
diff
changeset
|
144 ev->write ? "write" : "read", c->fd, event); |
b7b2b0ea3366
test event type to prevent errors
Igor Sysoev <igor@sysoev.ru>
parents:
2781
diff
changeset
|
145 return NGX_ERROR; |
b7b2b0ea3366
test event type to prevent errors
Igor Sysoev <igor@sysoev.ru>
parents:
2781
diff
changeset
|
146 } |
b7b2b0ea3366
test event type to prevent errors
Igor Sysoev <igor@sysoev.ru>
parents:
2781
diff
changeset
|
147 |
92
19cc647ecd91
nginx-0.0.1-2003-05-20-19:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
91
diff
changeset
|
148 if (event == NGX_READ_EVENT) { |
8
708f8bb772ec
nginx-0.0.1-2002-09-02-18:48:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
7
diff
changeset
|
149 FD_SET(c->fd, &master_read_fd_set); |
708f8bb772ec
nginx-0.0.1-2002-09-02-18:48:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
7
diff
changeset
|
150 |
92
19cc647ecd91
nginx-0.0.1-2003-05-20-19:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
91
diff
changeset
|
151 } else if (event == NGX_WRITE_EVENT) { |
8
708f8bb772ec
nginx-0.0.1-2002-09-02-18:48:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
7
diff
changeset
|
152 FD_SET(c->fd, &master_write_fd_set); |
92
19cc647ecd91
nginx-0.0.1-2003-05-20-19:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
91
diff
changeset
|
153 } |
8
708f8bb772ec
nginx-0.0.1-2002-09-02-18:48:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
7
diff
changeset
|
154 |
92
19cc647ecd91
nginx-0.0.1-2003-05-20-19:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
91
diff
changeset
|
155 if (max_fd != -1 && max_fd < c->fd) { |
8
708f8bb772ec
nginx-0.0.1-2002-09-02-18:48:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
7
diff
changeset
|
156 max_fd = c->fd; |
92
19cc647ecd91
nginx-0.0.1-2003-05-20-19:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
91
diff
changeset
|
157 } |
8
708f8bb772ec
nginx-0.0.1-2002-09-02-18:48:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
7
diff
changeset
|
158 |
39
83fa61cd3d2f
nginx-0.0.1-2002-12-24-20:30:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
38
diff
changeset
|
159 ev->active = 1; |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
160 |
17
8dd06e2844f5
nginx-0.0.1-2002-09-27-19:05:29 import
Igor Sysoev <igor@sysoev.ru>
parents:
13
diff
changeset
|
161 event_index[nevents] = ev; |
8dd06e2844f5
nginx-0.0.1-2002-09-27-19:05:29 import
Igor Sysoev <igor@sysoev.ru>
parents:
13
diff
changeset
|
162 ev->index = nevents; |
8dd06e2844f5
nginx-0.0.1-2002-09-27-19:05:29 import
Igor Sysoev <igor@sysoev.ru>
parents:
13
diff
changeset
|
163 nevents++; |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
164 |
8
708f8bb772ec
nginx-0.0.1-2002-09-02-18:48:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
7
diff
changeset
|
165 return NGX_OK; |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
166 } |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
167 |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
87
diff
changeset
|
168 |
501 | 169 static ngx_int_t |
1354
f69d1aab6a0f
make 64-bit ngx_int_t on 64-bit platforms
Igor Sysoev <igor@sysoev.ru>
parents:
708
diff
changeset
|
170 ngx_select_del_event(ngx_event_t *ev, ngx_int_t event, ngx_uint_t flags) |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
171 { |
2809 | 172 ngx_event_t *e; |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
87
diff
changeset
|
173 ngx_connection_t *c; |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
87
diff
changeset
|
174 |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
87
diff
changeset
|
175 c = ev->data; |
8
708f8bb772ec
nginx-0.0.1-2002-09-02-18:48:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
7
diff
changeset
|
176 |
314
d71c87d11b16
nginx-0.0.3-2004-04-14-09:57:36 import
Igor Sysoev <igor@sysoev.ru>
parents:
302
diff
changeset
|
177 ev->active = 0; |
d71c87d11b16
nginx-0.0.3-2004-04-14-09:57:36 import
Igor Sysoev <igor@sysoev.ru>
parents:
302
diff
changeset
|
178 |
92
19cc647ecd91
nginx-0.0.1-2003-05-20-19:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
91
diff
changeset
|
179 if (ev->index == NGX_INVALID_INDEX) { |
26
53cb81681040
nginx-0.0.1-2002-12-15-09:25:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
23
diff
changeset
|
180 return NGX_OK; |
92
19cc647ecd91
nginx-0.0.1-2003-05-20-19:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
91
diff
changeset
|
181 } |
26
53cb81681040
nginx-0.0.1-2002-12-15-09:25:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
23
diff
changeset
|
182 |
245
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
230
diff
changeset
|
183 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, ev->log, 0, |
1354
f69d1aab6a0f
make 64-bit ngx_int_t on 64-bit platforms
Igor Sysoev <igor@sysoev.ru>
parents:
708
diff
changeset
|
184 "select del event fd:%d ev:%i", c->fd, event); |
23
f540a63026c9
nginx-0.0.1-2002-12-06-19:32:33 import
Igor Sysoev <igor@sysoev.ru>
parents:
17
diff
changeset
|
185 |
92
19cc647ecd91
nginx-0.0.1-2003-05-20-19:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
91
diff
changeset
|
186 if (event == NGX_READ_EVENT) { |
8
708f8bb772ec
nginx-0.0.1-2002-09-02-18:48:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
7
diff
changeset
|
187 FD_CLR(c->fd, &master_read_fd_set); |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
188 |
92
19cc647ecd91
nginx-0.0.1-2003-05-20-19:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
91
diff
changeset
|
189 } else if (event == NGX_WRITE_EVENT) { |
8
708f8bb772ec
nginx-0.0.1-2002-09-02-18:48:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
7
diff
changeset
|
190 FD_CLR(c->fd, &master_write_fd_set); |
92
19cc647ecd91
nginx-0.0.1-2003-05-20-19:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
91
diff
changeset
|
191 } |
8
708f8bb772ec
nginx-0.0.1-2002-09-02-18:48:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
7
diff
changeset
|
192 |
92
19cc647ecd91
nginx-0.0.1-2003-05-20-19:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
91
diff
changeset
|
193 if (max_fd == c->fd) { |
8
708f8bb772ec
nginx-0.0.1-2002-09-02-18:48:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
7
diff
changeset
|
194 max_fd = -1; |
92
19cc647ecd91
nginx-0.0.1-2003-05-20-19:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
91
diff
changeset
|
195 } |
19cc647ecd91
nginx-0.0.1-2003-05-20-19:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
91
diff
changeset
|
196 |
1354
f69d1aab6a0f
make 64-bit ngx_int_t on 64-bit platforms
Igor Sysoev <igor@sysoev.ru>
parents:
708
diff
changeset
|
197 if (ev->index < --nevents) { |
2809 | 198 e = event_index[nevents]; |
199 event_index[ev->index] = e; | |
200 e->index = ev->index; | |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
201 } |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
202 |
26
53cb81681040
nginx-0.0.1-2002-12-15-09:25:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
23
diff
changeset
|
203 ev->index = NGX_INVALID_INDEX; |
53cb81681040
nginx-0.0.1-2002-12-15-09:25:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
23
diff
changeset
|
204 |
8
708f8bb772ec
nginx-0.0.1-2002-09-02-18:48:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
7
diff
changeset
|
205 return NGX_OK; |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
206 } |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
207 |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
87
diff
changeset
|
208 |
501 | 209 static ngx_int_t |
563 | 210 ngx_select_process_events(ngx_cycle_t *cycle, ngx_msec_t timer, |
211 ngx_uint_t flags) | |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
212 { |
2778 | 213 int ready, nready; |
214 ngx_err_t err; | |
215 ngx_uint_t i, found; | |
216 ngx_event_t *ev, **queue; | |
217 struct timeval tv, *tp; | |
218 ngx_connection_t *c; | |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
219 |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
220 if (max_fd == -1) { |
17
8dd06e2844f5
nginx-0.0.1-2002-09-27-19:05:29 import
Igor Sysoev <igor@sysoev.ru>
parents:
13
diff
changeset
|
221 for (i = 0; i < nevents; i++) { |
250
1903c6821958
nginx-0.0.2-2004-02-03-23:27:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
248
diff
changeset
|
222 c = event_index[i]->data; |
92
19cc647ecd91
nginx-0.0.1-2003-05-20-19:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
91
diff
changeset
|
223 if (max_fd < c->fd) { |
8
708f8bb772ec
nginx-0.0.1-2002-09-02-18:48:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
7
diff
changeset
|
224 max_fd = c->fd; |
92
19cc647ecd91
nginx-0.0.1-2003-05-20-19:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
91
diff
changeset
|
225 } |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
226 } |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
227 |
302
1526e7686b20
nginx-0.0.3-2004-04-01-10:21:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
228 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0, |
245
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
230
diff
changeset
|
229 "change max_fd: %d", max_fd); |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
230 } |
314
d71c87d11b16
nginx-0.0.3-2004-04-14-09:57:36 import
Igor Sysoev <igor@sysoev.ru>
parents:
302
diff
changeset
|
231 |
315
39b6f2df45c0
nginx-0.0.3-2004-04-14-21:44:28 import
Igor Sysoev <igor@sysoev.ru>
parents:
314
diff
changeset
|
232 #if (NGX_DEBUG) |
323
ba876b26b76d
nginx-0.0.3-2004-04-21-22:54:33 import
Igor Sysoev <igor@sysoev.ru>
parents:
321
diff
changeset
|
233 if (cycle->log->log_level & NGX_LOG_DEBUG_ALL) { |
ba876b26b76d
nginx-0.0.3-2004-04-21-22:54:33 import
Igor Sysoev <igor@sysoev.ru>
parents:
321
diff
changeset
|
234 for (i = 0; i < nevents; i++) { |
ba876b26b76d
nginx-0.0.3-2004-04-21-22:54:33 import
Igor Sysoev <igor@sysoev.ru>
parents:
321
diff
changeset
|
235 ev = event_index[i]; |
ba876b26b76d
nginx-0.0.3-2004-04-21-22:54:33 import
Igor Sysoev <igor@sysoev.ru>
parents:
321
diff
changeset
|
236 c = ev->data; |
ba876b26b76d
nginx-0.0.3-2004-04-21-22:54:33 import
Igor Sysoev <igor@sysoev.ru>
parents:
321
diff
changeset
|
237 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, cycle->log, 0, |
ba876b26b76d
nginx-0.0.3-2004-04-21-22:54:33 import
Igor Sysoev <igor@sysoev.ru>
parents:
321
diff
changeset
|
238 "select event: fd:%d wr:%d", c->fd, ev->write); |
ba876b26b76d
nginx-0.0.3-2004-04-21-22:54:33 import
Igor Sysoev <igor@sysoev.ru>
parents:
321
diff
changeset
|
239 } |
ba876b26b76d
nginx-0.0.3-2004-04-21-22:54:33 import
Igor Sysoev <igor@sysoev.ru>
parents:
321
diff
changeset
|
240 |
ba876b26b76d
nginx-0.0.3-2004-04-21-22:54:33 import
Igor Sysoev <igor@sysoev.ru>
parents:
321
diff
changeset
|
241 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0, |
ba876b26b76d
nginx-0.0.3-2004-04-21-22:54:33 import
Igor Sysoev <igor@sysoev.ru>
parents:
321
diff
changeset
|
242 "max_fd: %d", max_fd); |
315
39b6f2df45c0
nginx-0.0.3-2004-04-14-21:44:28 import
Igor Sysoev <igor@sysoev.ru>
parents:
314
diff
changeset
|
243 } |
39b6f2df45c0
nginx-0.0.3-2004-04-14-21:44:28 import
Igor Sysoev <igor@sysoev.ru>
parents:
314
diff
changeset
|
244 #endif |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
245 |
316
a0beefedaf94
nginx-0.0.3-2004-04-15-00:34:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
315
diff
changeset
|
246 if (timer == NGX_TIMER_INFINITE) { |
a0beefedaf94
nginx-0.0.3-2004-04-15-00:34:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
315
diff
changeset
|
247 tp = NULL; |
315
39b6f2df45c0
nginx-0.0.3-2004-04-14-21:44:28 import
Igor Sysoev <igor@sysoev.ru>
parents:
314
diff
changeset
|
248 |
316
a0beefedaf94
nginx-0.0.3-2004-04-15-00:34:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
315
diff
changeset
|
249 } else { |
557 | 250 tv.tv_sec = (long) (timer / 1000); |
251 tv.tv_usec = (long) ((timer % 1000) * 1000); | |
315
39b6f2df45c0
nginx-0.0.3-2004-04-14-21:44:28 import
Igor Sysoev <igor@sysoev.ru>
parents:
314
diff
changeset
|
252 tp = &tv; |
26
53cb81681040
nginx-0.0.1-2002-12-15-09:25:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
23
diff
changeset
|
253 } |
314
d71c87d11b16
nginx-0.0.3-2004-04-14-09:57:36 import
Igor Sysoev <igor@sysoev.ru>
parents:
302
diff
changeset
|
254 |
302
1526e7686b20
nginx-0.0.3-2004-04-01-10:21:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
255 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0, |
557 | 256 "select timer: %M", timer); |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
257 |
315
39b6f2df45c0
nginx-0.0.3-2004-04-14-21:44:28 import
Igor Sysoev <igor@sysoev.ru>
parents:
314
diff
changeset
|
258 work_read_fd_set = master_read_fd_set; |
39b6f2df45c0
nginx-0.0.3-2004-04-14-21:44:28 import
Igor Sysoev <igor@sysoev.ru>
parents:
314
diff
changeset
|
259 work_write_fd_set = master_write_fd_set; |
39b6f2df45c0
nginx-0.0.3-2004-04-14-21:44:28 import
Igor Sysoev <igor@sysoev.ru>
parents:
314
diff
changeset
|
260 |
114
ac69ab96328d
nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
107
diff
changeset
|
261 ready = select(max_fd + 1, &work_read_fd_set, &work_write_fd_set, NULL, tp); |
563 | 262 |
114
ac69ab96328d
nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
107
diff
changeset
|
263 if (ready == -1) { |
ac69ab96328d
nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
107
diff
changeset
|
264 err = ngx_socket_errno; |
ac69ab96328d
nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
107
diff
changeset
|
265 } else { |
ac69ab96328d
nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
107
diff
changeset
|
266 err = 0; |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
267 } |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
268 |
563 | 269 if (flags & NGX_UPDATE_TIME) { |
270 ngx_time_update(0, 0); | |
271 } | |
178
a8ff48d26cca
nginx-0.0.1-2003-11-11-00:09:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
272 |
302
1526e7686b20
nginx-0.0.3-2004-04-01-10:21:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
273 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0, |
1526e7686b20
nginx-0.0.3-2004-04-01-10:21:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
274 "select ready %d", ready); |
245
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
230
diff
changeset
|
275 |
563 | 276 if (err) { |
1704
e584e946e198
move condition declarations inside blocks where they are used
Igor Sysoev <igor@sysoev.ru>
parents:
1354
diff
changeset
|
277 ngx_uint_t level; |
e584e946e198
move condition declarations inside blocks where they are used
Igor Sysoev <igor@sysoev.ru>
parents:
1354
diff
changeset
|
278 |
563 | 279 if (err == NGX_EINTR) { |
280 | |
281 if (ngx_event_timer_alarm) { | |
282 ngx_event_timer_alarm = 0; | |
283 return NGX_OK; | |
284 } | |
577 | 285 |
563 | 286 level = NGX_LOG_INFO; |
577 | 287 |
288 } else { | |
563 | 289 level = NGX_LOG_ALERT; |
290 } | |
291 | |
292 ngx_log_error(level, cycle->log, err, "select() failed"); | |
2780 | 293 |
294 if (err == EBADF) { | |
295 ngx_select_repair_fd_sets(cycle); | |
296 } | |
297 | |
314
d71c87d11b16
nginx-0.0.3-2004-04-14-09:57:36 import
Igor Sysoev <igor@sysoev.ru>
parents:
302
diff
changeset
|
298 return NGX_ERROR; |
d71c87d11b16
nginx-0.0.3-2004-04-14-09:57:36 import
Igor Sysoev <igor@sysoev.ru>
parents:
302
diff
changeset
|
299 } |
d71c87d11b16
nginx-0.0.3-2004-04-14-09:57:36 import
Igor Sysoev <igor@sysoev.ru>
parents:
302
diff
changeset
|
300 |
567 | 301 if (ready == 0) { |
302 if (timer != NGX_TIMER_INFINITE) { | |
303 return NGX_OK; | |
304 } | |
305 | |
306 ngx_log_error(NGX_LOG_ALERT, cycle->log, 0, | |
307 "select() returned no events without timeout"); | |
308 return NGX_ERROR; | |
563 | 309 } |
310 | |
311 ngx_mutex_lock(ngx_posted_events_mutex); | |
312 | |
17
8dd06e2844f5
nginx-0.0.1-2002-09-27-19:05:29 import
Igor Sysoev <igor@sysoev.ru>
parents:
13
diff
changeset
|
313 nready = 0; |
8dd06e2844f5
nginx-0.0.1-2002-09-27-19:05:29 import
Igor Sysoev <igor@sysoev.ru>
parents:
13
diff
changeset
|
314 |
8dd06e2844f5
nginx-0.0.1-2002-09-27-19:05:29 import
Igor Sysoev <igor@sysoev.ru>
parents:
13
diff
changeset
|
315 for (i = 0; i < nevents; i++) { |
8dd06e2844f5
nginx-0.0.1-2002-09-27-19:05:29 import
Igor Sysoev <igor@sysoev.ru>
parents:
13
diff
changeset
|
316 ev = event_index[i]; |
250
1903c6821958
nginx-0.0.2-2004-02-03-23:27:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
248
diff
changeset
|
317 c = ev->data; |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
318 found = 0; |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
319 |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
320 if (ev->write) { |
8
708f8bb772ec
nginx-0.0.1-2002-09-02-18:48:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
7
diff
changeset
|
321 if (FD_ISSET(c->fd, &work_write_fd_set)) { |
39
83fa61cd3d2f
nginx-0.0.1-2002-12-24-20:30:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
38
diff
changeset
|
322 found = 1; |
302
1526e7686b20
nginx-0.0.3-2004-04-01-10:21:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
323 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0, |
245
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
230
diff
changeset
|
324 "select write %d", c->fd); |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
325 } |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
326 |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
327 } else { |
8
708f8bb772ec
nginx-0.0.1-2002-09-02-18:48:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
7
diff
changeset
|
328 if (FD_ISSET(c->fd, &work_read_fd_set)) { |
39
83fa61cd3d2f
nginx-0.0.1-2002-12-24-20:30:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
38
diff
changeset
|
329 found = 1; |
302
1526e7686b20
nginx-0.0.3-2004-04-01-10:21:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
330 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0, |
245
e6c005b66b3a
nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
230
diff
changeset
|
331 "select read %d", c->fd); |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
332 } |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
333 } |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
334 |
17
8dd06e2844f5
nginx-0.0.1-2002-09-27-19:05:29 import
Igor Sysoev <igor@sysoev.ru>
parents:
13
diff
changeset
|
335 if (found) { |
314
d71c87d11b16
nginx-0.0.3-2004-04-14-09:57:36 import
Igor Sysoev <igor@sysoev.ru>
parents:
302
diff
changeset
|
336 ev->ready = 1; |
d71c87d11b16
nginx-0.0.3-2004-04-14-09:57:36 import
Igor Sysoev <igor@sysoev.ru>
parents:
302
diff
changeset
|
337 |
563 | 338 queue = (ngx_event_t **) (ev->accept ? &ngx_posted_accept_events: |
339 &ngx_posted_events); | |
577 | 340 ngx_locked_post_event(ev, queue); |
314
d71c87d11b16
nginx-0.0.3-2004-04-14-09:57:36 import
Igor Sysoev <igor@sysoev.ru>
parents:
302
diff
changeset
|
341 |
d71c87d11b16
nginx-0.0.3-2004-04-14-09:57:36 import
Igor Sysoev <igor@sysoev.ru>
parents:
302
diff
changeset
|
342 nready++; |
17
8dd06e2844f5
nginx-0.0.1-2002-09-27-19:05:29 import
Igor Sysoev <igor@sysoev.ru>
parents:
13
diff
changeset
|
343 } |
8dd06e2844f5
nginx-0.0.1-2002-09-27-19:05:29 import
Igor Sysoev <igor@sysoev.ru>
parents:
13
diff
changeset
|
344 } |
13
2aba961a1d34
nginx-0.0.1-2002-09-16-19:01:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
8
diff
changeset
|
345 |
563 | 346 ngx_mutex_unlock(ngx_posted_events_mutex); |
314
d71c87d11b16
nginx-0.0.3-2004-04-14-09:57:36 import
Igor Sysoev <igor@sysoev.ru>
parents:
302
diff
changeset
|
347 |
d71c87d11b16
nginx-0.0.3-2004-04-14-09:57:36 import
Igor Sysoev <igor@sysoev.ru>
parents:
302
diff
changeset
|
348 if (ready != nready) { |
2781
f545c81e5ddb
try to repair the case "select ready != events"
Igor Sysoev <igor@sysoev.ru>
parents:
2780
diff
changeset
|
349 ngx_log_error(NGX_LOG_ALERT, cycle->log, 0, |
f545c81e5ddb
try to repair the case "select ready != events"
Igor Sysoev <igor@sysoev.ru>
parents:
2780
diff
changeset
|
350 "select ready != events: %d:%d", ready, nready); |
f545c81e5ddb
try to repair the case "select ready != events"
Igor Sysoev <igor@sysoev.ru>
parents:
2780
diff
changeset
|
351 |
f545c81e5ddb
try to repair the case "select ready != events"
Igor Sysoev <igor@sysoev.ru>
parents:
2780
diff
changeset
|
352 ngx_select_repair_fd_sets(cycle); |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
353 } |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
354 |
8
708f8bb772ec
nginx-0.0.1-2002-09-02-18:48:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
7
diff
changeset
|
355 return NGX_OK; |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
356 } |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
87
diff
changeset
|
357 |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
87
diff
changeset
|
358 |
2780 | 359 static void |
360 ngx_select_repair_fd_sets(ngx_cycle_t *cycle) | |
361 { | |
362 int n; | |
363 socklen_t len; | |
364 ngx_err_t err; | |
365 ngx_socket_t s; | |
366 | |
367 for (s = 0; s <= max_fd; s++) { | |
368 | |
369 if (FD_ISSET(s, &master_read_fd_set) == 0) { | |
370 continue; | |
371 } | |
372 | |
373 len = sizeof(int); | |
374 | |
375 if (getsockopt(s, SOL_SOCKET, SO_TYPE, &n, &len) == -1) { | |
376 err = ngx_socket_errno; | |
377 | |
378 ngx_log_error(NGX_LOG_ALERT, cycle->log, err, | |
379 "invalid descriptor #%d in read fd_set", s); | |
380 | |
381 FD_CLR(s, &master_read_fd_set); | |
382 } | |
383 } | |
384 | |
385 for (s = 0; s <= max_fd; s++) { | |
386 | |
387 if (FD_ISSET(s, &master_write_fd_set) == 0) { | |
388 continue; | |
389 } | |
390 | |
391 len = sizeof(int); | |
392 | |
393 if (getsockopt(s, SOL_SOCKET, SO_TYPE, &n, &len) == -1) { | |
394 err = ngx_socket_errno; | |
395 | |
396 ngx_log_error(NGX_LOG_ALERT, cycle->log, err, | |
397 "invalid descriptor #%d in write fd_set", s); | |
398 | |
399 FD_CLR(s, &master_write_fd_set); | |
400 } | |
401 } | |
402 | |
403 max_fd = -1; | |
404 } | |
405 | |
406 | |
501 | 407 static char * |
408 ngx_select_init_conf(ngx_cycle_t *cycle, void *conf) | |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
87
diff
changeset
|
409 { |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
87
diff
changeset
|
410 ngx_event_conf_t *ecf; |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
87
diff
changeset
|
411 |
114
ac69ab96328d
nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
107
diff
changeset
|
412 ecf = ngx_event_get_conf(cycle->conf_ctx, ngx_event_core_module); |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
87
diff
changeset
|
413 |
321
32847588a82a
nginx-0.0.3-2004-04-19-20:36:08 import
Igor Sysoev <igor@sysoev.ru>
parents:
318
diff
changeset
|
414 if (ecf->use != ngx_select_module.ctx_index) { |
32847588a82a
nginx-0.0.3-2004-04-19-20:36:08 import
Igor Sysoev <igor@sysoev.ru>
parents:
318
diff
changeset
|
415 return NGX_CONF_OK; |
32847588a82a
nginx-0.0.3-2004-04-19-20:36:08 import
Igor Sysoev <igor@sysoev.ru>
parents:
318
diff
changeset
|
416 } |
32847588a82a
nginx-0.0.3-2004-04-19-20:36:08 import
Igor Sysoev <igor@sysoev.ru>
parents:
318
diff
changeset
|
417 |
121
b3655b21375a
nginx-0.0.1-2003-07-22-23:53:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
120
diff
changeset
|
418 /* disable warning: the default FD_SETSIZE is 1024U in FreeBSD 5.x */ |
103
6dfda4cf5200
nginx-0.0.1-2003-06-11-19:28:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
102
diff
changeset
|
419 |
2062
90312b616162
prepare to allow various number of connections in child processes
Igor Sysoev <igor@sysoev.ru>
parents:
1704
diff
changeset
|
420 if (cycle->connection_n > FD_SETSIZE) { |
248
e885208c518b
nginx-0.0.2-2004-02-03-00:19:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
245
diff
changeset
|
421 ngx_log_error(NGX_LOG_EMERG, cycle->log, 0, |
e885208c518b
nginx-0.0.2-2004-02-03-00:19:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
245
diff
changeset
|
422 "the maximum number of files " |
2062
90312b616162
prepare to allow various number of connections in child processes
Igor Sysoev <igor@sysoev.ru>
parents:
1704
diff
changeset
|
423 "supported by select() is %ud", FD_SETSIZE); |
248
e885208c518b
nginx-0.0.2-2004-02-03-00:19:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
245
diff
changeset
|
424 return NGX_CONF_ERROR; |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
87
diff
changeset
|
425 } |
563 | 426 |
2813
c00763aa5e1b
divide select module into two modules: Unix and Win32 ones
Igor Sysoev <igor@sysoev.ru>
parents:
2809
diff
changeset
|
427 #if (NGX_THREADS) |
563 | 428 |
381
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
429 ngx_log_error(NGX_LOG_EMERG, cycle->log, 0, |
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
430 "select() is not supported in the threaded mode"); |
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
431 return NGX_CONF_ERROR; |
563 | 432 |
381
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
433 #else |
563 | 434 |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
87
diff
changeset
|
435 return NGX_CONF_OK; |
563 | 436 |
381
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
437 #endif |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
87
diff
changeset
|
438 } |