Mercurial > hg > nginx
annotate src/event/modules/ngx_select_module.c @ 4147:7f64de1cc2c0
Fix for double content when return is used in error_page handler.
Test case:
location / {
error_page 405 /nope;
return 405;
}
location /nope {
return 200;
}
This is expected to return 405 with empty body, but in 0.8.42+ will return
builtin 405 error page as well (though not counted in Content-Length, thus
breaking protocol).
Fix is to use status provided by rewrite script execution in case
it's less than NGX_HTTP_BAD_REQUEST even if r->error_status set. This
check is in line with one in ngx_http_script_return_code().
Note that this patch also changes behaviour for "return 302 ..." and
"rewrite ... redirect" used as error handler. E.g.
location / {
error_page 405 /redirect;
return 405;
}
location /redirect {
rewrite ^ http://example.com/;
}
will actually return redirect to "http://example.com/" instead of builtin 405
error page with meaningless Location header. This looks like correct change
and it's in line with what happens on e.g. directory redirects in error
handlers.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Tue, 27 Sep 2011 11:11:30 +0000 |
parents | ab353d7dc182 |
children | d620f497c50f |
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 |
3358
f94e8ff65aa2
add NGX_PROCESS_HELPER process status
Igor Sysoev <igor@sysoev.ru>
parents:
3043
diff
changeset
|
84 if (ngx_process >= NGX_PROCESS_WORKER |
314
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 |
3043 | 263 err = (ready == -1) ? ngx_errno : 0; |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
264 |
3473
0299cf5856fc
do not update time in the timer signal handler,
Igor Sysoev <igor@sysoev.ru>
parents:
3358
diff
changeset
|
265 if (flags & NGX_UPDATE_TIME || ngx_event_timer_alarm) { |
3475
ab353d7dc182
*) introduce ngx_time_sigsafe_update() to update the error log time only
Igor Sysoev <igor@sysoev.ru>
parents:
3474
diff
changeset
|
266 ngx_time_update(); |
563 | 267 } |
178
a8ff48d26cca
nginx-0.0.1-2003-11-11-00:09:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
268 |
302
1526e7686b20
nginx-0.0.3-2004-04-01-10:21:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
269 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
|
270 "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
|
271 |
563 | 272 if (err) { |
1704
e584e946e198
move condition declarations inside blocks where they are used
Igor Sysoev <igor@sysoev.ru>
parents:
1354
diff
changeset
|
273 ngx_uint_t level; |
e584e946e198
move condition declarations inside blocks where they are used
Igor Sysoev <igor@sysoev.ru>
parents:
1354
diff
changeset
|
274 |
563 | 275 if (err == NGX_EINTR) { |
276 | |
277 if (ngx_event_timer_alarm) { | |
278 ngx_event_timer_alarm = 0; | |
279 return NGX_OK; | |
280 } | |
577 | 281 |
563 | 282 level = NGX_LOG_INFO; |
577 | 283 |
284 } else { | |
563 | 285 level = NGX_LOG_ALERT; |
286 } | |
287 | |
288 ngx_log_error(level, cycle->log, err, "select() failed"); | |
2780 | 289 |
290 if (err == EBADF) { | |
291 ngx_select_repair_fd_sets(cycle); | |
292 } | |
293 | |
314
d71c87d11b16
nginx-0.0.3-2004-04-14-09:57:36 import
Igor Sysoev <igor@sysoev.ru>
parents:
302
diff
changeset
|
294 return NGX_ERROR; |
d71c87d11b16
nginx-0.0.3-2004-04-14-09:57:36 import
Igor Sysoev <igor@sysoev.ru>
parents:
302
diff
changeset
|
295 } |
d71c87d11b16
nginx-0.0.3-2004-04-14-09:57:36 import
Igor Sysoev <igor@sysoev.ru>
parents:
302
diff
changeset
|
296 |
567 | 297 if (ready == 0) { |
298 if (timer != NGX_TIMER_INFINITE) { | |
299 return NGX_OK; | |
300 } | |
301 | |
302 ngx_log_error(NGX_LOG_ALERT, cycle->log, 0, | |
303 "select() returned no events without timeout"); | |
304 return NGX_ERROR; | |
563 | 305 } |
306 | |
307 ngx_mutex_lock(ngx_posted_events_mutex); | |
308 | |
17
8dd06e2844f5
nginx-0.0.1-2002-09-27-19:05:29 import
Igor Sysoev <igor@sysoev.ru>
parents:
13
diff
changeset
|
309 nready = 0; |
8dd06e2844f5
nginx-0.0.1-2002-09-27-19:05:29 import
Igor Sysoev <igor@sysoev.ru>
parents:
13
diff
changeset
|
310 |
8dd06e2844f5
nginx-0.0.1-2002-09-27-19:05:29 import
Igor Sysoev <igor@sysoev.ru>
parents:
13
diff
changeset
|
311 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
|
312 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
|
313 c = ev->data; |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
314 found = 0; |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
315 |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
316 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
|
317 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
|
318 found = 1; |
302
1526e7686b20
nginx-0.0.3-2004-04-01-10:21:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
319 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
|
320 "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
|
321 } |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
322 |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
323 } else { |
8
708f8bb772ec
nginx-0.0.1-2002-09-02-18:48:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
7
diff
changeset
|
324 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
|
325 found = 1; |
302
1526e7686b20
nginx-0.0.3-2004-04-01-10:21:13 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
326 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
|
327 "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
|
328 } |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
329 } |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
330 |
17
8dd06e2844f5
nginx-0.0.1-2002-09-27-19:05:29 import
Igor Sysoev <igor@sysoev.ru>
parents:
13
diff
changeset
|
331 if (found) { |
314
d71c87d11b16
nginx-0.0.3-2004-04-14-09:57:36 import
Igor Sysoev <igor@sysoev.ru>
parents:
302
diff
changeset
|
332 ev->ready = 1; |
d71c87d11b16
nginx-0.0.3-2004-04-14-09:57:36 import
Igor Sysoev <igor@sysoev.ru>
parents:
302
diff
changeset
|
333 |
563 | 334 queue = (ngx_event_t **) (ev->accept ? &ngx_posted_accept_events: |
335 &ngx_posted_events); | |
577 | 336 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
|
337 |
d71c87d11b16
nginx-0.0.3-2004-04-14-09:57:36 import
Igor Sysoev <igor@sysoev.ru>
parents:
302
diff
changeset
|
338 nready++; |
17
8dd06e2844f5
nginx-0.0.1-2002-09-27-19:05:29 import
Igor Sysoev <igor@sysoev.ru>
parents:
13
diff
changeset
|
339 } |
8dd06e2844f5
nginx-0.0.1-2002-09-27-19:05:29 import
Igor Sysoev <igor@sysoev.ru>
parents:
13
diff
changeset
|
340 } |
13
2aba961a1d34
nginx-0.0.1-2002-09-16-19:01:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
8
diff
changeset
|
341 |
563 | 342 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
|
343 |
d71c87d11b16
nginx-0.0.3-2004-04-14-09:57:36 import
Igor Sysoev <igor@sysoev.ru>
parents:
302
diff
changeset
|
344 if (ready != nready) { |
2781
f545c81e5ddb
try to repair the case "select ready != events"
Igor Sysoev <igor@sysoev.ru>
parents:
2780
diff
changeset
|
345 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
|
346 "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
|
347 |
f545c81e5ddb
try to repair the case "select ready != events"
Igor Sysoev <igor@sysoev.ru>
parents:
2780
diff
changeset
|
348 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
|
349 } |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
350 |
8
708f8bb772ec
nginx-0.0.1-2002-09-02-18:48:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
7
diff
changeset
|
351 return NGX_OK; |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
352 } |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
87
diff
changeset
|
353 |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
87
diff
changeset
|
354 |
2780 | 355 static void |
356 ngx_select_repair_fd_sets(ngx_cycle_t *cycle) | |
357 { | |
358 int n; | |
359 socklen_t len; | |
360 ngx_err_t err; | |
361 ngx_socket_t s; | |
362 | |
363 for (s = 0; s <= max_fd; s++) { | |
364 | |
365 if (FD_ISSET(s, &master_read_fd_set) == 0) { | |
366 continue; | |
367 } | |
368 | |
369 len = sizeof(int); | |
370 | |
371 if (getsockopt(s, SOL_SOCKET, SO_TYPE, &n, &len) == -1) { | |
372 err = ngx_socket_errno; | |
373 | |
374 ngx_log_error(NGX_LOG_ALERT, cycle->log, err, | |
375 "invalid descriptor #%d in read fd_set", s); | |
376 | |
377 FD_CLR(s, &master_read_fd_set); | |
378 } | |
379 } | |
380 | |
381 for (s = 0; s <= max_fd; s++) { | |
382 | |
383 if (FD_ISSET(s, &master_write_fd_set) == 0) { | |
384 continue; | |
385 } | |
386 | |
387 len = sizeof(int); | |
388 | |
389 if (getsockopt(s, SOL_SOCKET, SO_TYPE, &n, &len) == -1) { | |
390 err = ngx_socket_errno; | |
391 | |
392 ngx_log_error(NGX_LOG_ALERT, cycle->log, err, | |
393 "invalid descriptor #%d in write fd_set", s); | |
394 | |
395 FD_CLR(s, &master_write_fd_set); | |
396 } | |
397 } | |
398 | |
399 max_fd = -1; | |
400 } | |
401 | |
402 | |
501 | 403 static char * |
404 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
|
405 { |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
87
diff
changeset
|
406 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
|
407 |
114
ac69ab96328d
nginx-0.0.1-2003-07-07-10:11:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
107
diff
changeset
|
408 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
|
409 |
321
32847588a82a
nginx-0.0.3-2004-04-19-20:36:08 import
Igor Sysoev <igor@sysoev.ru>
parents:
318
diff
changeset
|
410 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
|
411 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
|
412 } |
32847588a82a
nginx-0.0.3-2004-04-19-20:36:08 import
Igor Sysoev <igor@sysoev.ru>
parents:
318
diff
changeset
|
413 |
121
b3655b21375a
nginx-0.0.1-2003-07-22-23:53:10 import
Igor Sysoev <igor@sysoev.ru>
parents:
120
diff
changeset
|
414 /* 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
|
415 |
2062
90312b616162
prepare to allow various number of connections in child processes
Igor Sysoev <igor@sysoev.ru>
parents:
1704
diff
changeset
|
416 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
|
417 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
|
418 "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
|
419 "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
|
420 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
|
421 } |
563 | 422 |
2813
c00763aa5e1b
divide select module into two modules: Unix and Win32 ones
Igor Sysoev <igor@sysoev.ru>
parents:
2809
diff
changeset
|
423 #if (NGX_THREADS) |
563 | 424 |
381
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
380
diff
changeset
|
425 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
|
426 "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
|
427 return NGX_CONF_ERROR; |
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 #else |
563 | 430 |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
87
diff
changeset
|
431 return NGX_CONF_OK; |
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 #endif |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
87
diff
changeset
|
434 } |