Mercurial > hg > nginx
comparison src/event/ngx_event.c @ 113:d7f606e25b99
nginx-0.0.1-2003-07-04-19:10:33 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Fri, 04 Jul 2003 15:10:33 +0000 |
parents | da763a85be66 |
children | ac69ab96328d |
comparison
equal
deleted
inserted
replaced
112:da763a85be66 | 113:d7f606e25b99 |
---|---|
2 #include <ngx_config.h> | 2 #include <ngx_config.h> |
3 #include <ngx_core.h> | 3 #include <ngx_core.h> |
4 #include <ngx_event.h> | 4 #include <ngx_event.h> |
5 | 5 |
6 | 6 |
7 #define DEF_CONNECTIONS 512 | 7 #define DEFAULT_CONNECTIONS 512 |
8 | 8 |
9 | 9 |
10 extern ngx_module_t ngx_select_module; | 10 extern ngx_module_t ngx_select_module; |
11 | 11 |
12 #if (HAVE_KQUEUE) | 12 #if (HAVE_KQUEUE) |
19 | 19 |
20 #if (HAVE_AIO) | 20 #if (HAVE_AIO) |
21 #include <ngx_aio_module.h> | 21 #include <ngx_aio_module.h> |
22 #endif | 22 #endif |
23 | 23 |
24 static int ngx_event_init_module(ngx_cycle_t *cycle); | |
25 static int ngx_event_init_child(ngx_cycle_t *cycle); | |
26 static int ngx_event_init(ngx_cycle_t *cycle); | |
24 | 27 |
25 static char *ngx_events_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); | 28 static char *ngx_events_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); |
26 static char *ngx_event_use(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); | 29 static char *ngx_event_use(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); |
27 static void *ngx_event_create_conf(ngx_pool_t *pool); | 30 static void *ngx_event_create_conf(ngx_pool_t *pool); |
28 static char *ngx_event_init_conf(ngx_pool_t *pool, void *conf); | 31 static char *ngx_event_init_conf(ngx_pool_t *pool, void *conf); |
29 | 32 |
30 | 33 |
31 int ngx_event_flags; | 34 int ngx_event_flags; |
32 ngx_event_actions_t ngx_event_actions; | 35 ngx_event_actions_t ngx_event_actions; |
33 | 36 |
37 int ngx_max_connections; | |
34 ngx_connection_t *ngx_connections; | 38 ngx_connection_t *ngx_connections; |
35 ngx_event_t *ngx_read_events, *ngx_write_events; | 39 ngx_event_t *ngx_read_events, *ngx_write_events; |
36 | 40 |
37 | 41 |
38 static int ngx_event_max_module; | 42 static int ngx_event_max_module; |
39 | 43 |
40 | |
41 static int ngx_event_connections; | |
42 | 44 |
43 | 45 |
44 static ngx_str_t events_name = ngx_string("events"); | 46 static ngx_str_t events_name = ngx_string("events"); |
45 | 47 |
46 static ngx_command_t ngx_events_commands[] = { | 48 static ngx_command_t ngx_events_commands[] = { |
59 ngx_module_t ngx_events_module = { | 61 ngx_module_t ngx_events_module = { |
60 NGX_MODULE, | 62 NGX_MODULE, |
61 &events_name, /* module context */ | 63 &events_name, /* module context */ |
62 ngx_events_commands, /* module directives */ | 64 ngx_events_commands, /* module directives */ |
63 NGX_CORE_MODULE, /* module type */ | 65 NGX_CORE_MODULE, /* module type */ |
64 NULL /* init module */ | 66 NULL, /* init module */ |
67 NULL /* init child */ | |
65 }; | 68 }; |
66 | 69 |
67 | 70 |
68 static ngx_str_t event_core_name = ngx_string("event_core"); | 71 static ngx_str_t event_core_name = ngx_string("event_core"); |
69 | 72 |
107 NGX_MODULE, | 110 NGX_MODULE, |
108 &ngx_event_core_module_ctx, /* module context */ | 111 &ngx_event_core_module_ctx, /* module context */ |
109 ngx_event_core_commands, /* module directives */ | 112 ngx_event_core_commands, /* module directives */ |
110 NGX_EVENT_MODULE, /* module type */ | 113 NGX_EVENT_MODULE, /* module type */ |
111 ngx_event_init_module, /* init module */ | 114 ngx_event_init_module, /* init module */ |
112 ngx_event_commit, /* commit module */ | |
113 ngx_event_rollback, /* rollback module */ | |
114 ngx_event_init_child /* init child */ | 115 ngx_event_init_child /* init child */ |
115 }; | 116 }; |
116 | 117 |
117 | 118 |
118 | 119 |
119 static int ngx_event_init_module(ngx_cycle_t *cycle, ngx_log_t *log) | 120 static int ngx_event_init_module(ngx_cycle_t *cycle) |
120 { | 121 { |
121 if (cycle->one_process) { | 122 if (cycle->one_process) { |
122 return ngx_event_init(cycle, log); | 123 return ngx_event_init(cycle); |
123 } | 124 } |
124 | 125 |
125 return NGX_OK; | 126 return NGX_OK; |
126 } | 127 } |
127 | 128 |
128 | 129 |
129 static int ngx_event_init_child(ngx_cycle_t *cycle) | 130 static int ngx_event_init_child(ngx_cycle_t *cycle) |
130 { | 131 { |
131 if (!cycle->one_process) { | 132 if (cycle->one_process) { |
132 if (ngx_event_init(cycle, cycle->log) == NGX_ERROR) { | 133 return NGX_OK; |
133 return NGX_ERROR; | 134 } |
134 } | 135 |
135 ngx_event_commit(cycle, cycle->log); | 136 return ngx_event_init(cycle); |
136 } | 137 } |
137 | 138 |
138 return NGX_OK; | 139 |
139 } | 140 static int ngx_event_init(ngx_cycle_t *cycle) |
140 | |
141 | |
142 static int ngx_event_init(ngx_cycle_t *cycle, ngx_log_t *log) | |
143 { | 141 { |
144 int m, i, fd; | 142 int m, i, fd; |
145 ngx_event_t *rev, *wev; | 143 ngx_event_t *rev, *wev; |
146 ngx_listening_t *s; | 144 ngx_listening_t *s; |
147 ngx_connection_t *c; | 145 ngx_connection_t *c; |
151 ngx_iocp_conf_t *iocpcf; | 149 ngx_iocp_conf_t *iocpcf; |
152 #endif | 150 #endif |
153 | 151 |
154 ecf = ngx_event_get_conf(cycle->conf_ctx, ngx_event_core_module); | 152 ecf = ngx_event_get_conf(cycle->conf_ctx, ngx_event_core_module); |
155 | 153 |
156 ngx_log_debug(log, "CONN: %d" _ ecf->connections); | 154 ngx_log_debug(cycle->log, "CONN: %d" _ ecf->connections); |
157 ngx_log_debug(log, "TYPE: %d" _ ecf->use); | 155 ngx_log_debug(cycle->log, "TYPE: %d" _ ecf->use); |
158 | 156 |
159 for (m = 0; ngx_modules[m]; m++) { | 157 for (m = 0; ngx_modules[m]; m++) { |
160 if (ngx_modules[m]->type != NGX_EVENT_MODULE) { | 158 if (ngx_modules[m]->type != NGX_EVENT_MODULE) { |
161 continue; | 159 continue; |
162 } | 160 } |
163 | 161 |
164 if (ngx_modules[m]->ctx_index == ecf->use) { | 162 if (ngx_modules[m]->ctx_index == ecf->use) { |
165 module = ngx_modules[m]->ctx; | 163 module = ngx_modules[m]->ctx; |
166 if (module->actions.init(log) == NGX_ERROR) { | 164 if (module->actions.init(cycle) == NGX_ERROR) { |
167 return NGX_ERROR; | 165 return NGX_ERROR; |
168 } | 166 } |
169 break; | 167 break; |
170 } | 168 } |
171 } | 169 } |
172 | 170 |
173 if (ecf->connections) { | 171 if (ngx_max_connections && ngx_max_connections < ecf->connections) { |
174 } | 172 /* TODO: push into delayed array and temporary pool */ |
173 ngx_log_error(NGX_LOG_ALERT, cycle->log, 0, "NOT READY"); | |
174 exit(1); | |
175 } | |
176 | |
177 ngx_max_connections = ecf->connections; | |
175 | 178 |
176 ngx_test_null(ngx_connections, | 179 ngx_test_null(ngx_connections, |
177 ngx_alloc(sizeof(ngx_connection_t) * ecf->connections, log), | 180 ngx_alloc(sizeof(ngx_connection_t) * ecf->connections, |
181 cycle->log), | |
178 NGX_ERROR); | 182 NGX_ERROR); |
179 | 183 |
180 ngx_test_null(ngx_read_events, | 184 ngx_test_null(ngx_read_events, |
181 ngx_alloc(sizeof(ngx_event_t) * ecf->connections, log), | 185 ngx_alloc(sizeof(ngx_event_t) * ecf->connections, cycle->log), |
182 NGX_ERROR); | 186 NGX_ERROR); |
183 | 187 |
184 ngx_test_null(ngx_write_events, | 188 ngx_test_null(ngx_write_events, |
185 ngx_alloc(sizeof(ngx_event_t) * ecf->connections, log), | 189 ngx_alloc(sizeof(ngx_event_t) * ecf->connections, cycle->log), |
186 NGX_ERROR); | 190 NGX_ERROR); |
187 | 191 |
188 /* for each listening socket */ | 192 /* for each listening socket */ |
189 | 193 |
190 for (s = ls->elts, i = 0; i < ls->nelts; i++) { | 194 for (s = cycle->listening.elts, i = 0; i < cycle->listening.nelts; i++) { |
191 | 195 |
192 fd = s[i].fd; | 196 fd = s[i].fd; |
193 | 197 |
194 #if (WIN32) | 198 #if (WIN32) |
195 /* | 199 /* |
214 | 218 |
215 c->ctx = s[i].ctx; | 219 c->ctx = s[i].ctx; |
216 c->servers = s[i].servers; | 220 c->servers = s[i].servers; |
217 c->log = s[i].log; | 221 c->log = s[i].log; |
218 | 222 |
219 ngx_test_null(rev->log, ngx_palloc(pool, sizeof(ngx_log_t)), NGX_ERROR); | 223 ngx_test_null(rev->log, ngx_palloc(cycle->pool, sizeof(ngx_log_t)), |
224 NGX_ERROR); | |
220 | 225 |
221 ngx_memcpy(rev->log, c->log, sizeof(ngx_log_t)); | 226 ngx_memcpy(rev->log, c->log, sizeof(ngx_log_t)); |
222 c->read = rev; | 227 c->read = rev; |
223 c->write = wev; | 228 c->write = wev; |
224 rev->data = c; | 229 rev->data = c; |
262 | 267 |
263 return NGX_OK; | 268 return NGX_OK; |
264 } | 269 } |
265 | 270 |
266 | 271 |
267 static void ngx_event_commit(ngx_cycle_t *cycle, ngx_log_t *log) | |
268 { | |
269 } | |
270 | |
271 | |
272 static void ngx_event_rollback(ngx_cycle_t *cycle, ngx_log_t *log) | |
273 { | |
274 } | |
275 | |
276 | |
277 void ngx_worker(ngx_cycle_t *cycle) | |
278 { | |
279 for ( ;; ) { | |
280 ngx_log_debug(cycle->log, "ngx_worker cycle"); | |
281 | |
282 ngx_process_events(cycle->log); | |
283 } | |
284 } | |
285 | |
286 | |
287 static char *ngx_events_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | 272 static char *ngx_events_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
288 { | 273 { |
289 int m; | 274 int m; |
290 char *rv; | 275 char *rv; |
291 void ***ctx; | 276 void ***ctx; |
405 { | 390 { |
406 ngx_event_conf_t *ecf = conf; | 391 ngx_event_conf_t *ecf = conf; |
407 | 392 |
408 #if (HAVE_KQUEUE) | 393 #if (HAVE_KQUEUE) |
409 | 394 |
410 ngx_conf_init_value(ecf->connections, DEF_CONNECTIONS); | 395 ngx_conf_init_value(ecf->connections, DEFAULT_CONNECTIONS); |
411 ngx_conf_init_value(ecf->use, ngx_kqueue_module.ctx_index); | 396 ngx_conf_init_value(ecf->use, ngx_kqueue_module.ctx_index); |
412 | 397 |
413 #elif (HAVE_DEVPOLL) | 398 #elif (HAVE_DEVPOLL) |
414 | 399 |
415 ngx_conf_init_value(ecf->connections, DEF_CONNECTIONS); | 400 ngx_conf_init_value(ecf->connections, DEFAULT_CONNECTIONS); |
416 ngx_conf_init_value(ecf->use, ngx_devpoll_module.ctx_index); | 401 ngx_conf_init_value(ecf->use, ngx_devpoll_module.ctx_index); |
417 | 402 |
418 #else /* HAVE_SELECT */ | 403 #else /* HAVE_SELECT */ |
419 | 404 |
420 ngx_conf_init_value(ecf->connections, | 405 ngx_conf_init_value(ecf->connections, |
421 FD_SETSIZE < DEF_CONNECTIONS ? FD_SETSIZE : DEF_CONNECTIONS); | 406 FD_SETSIZE < DEFAULT_CONNECTIONS ? FD_SETSIZE : DEFAULT_CONNECTIONS); |
422 | 407 |
423 ngx_conf_init_value(ecf->use, ngx_select_module.ctx_index); | 408 ngx_conf_init_value(ecf->use, ngx_select_module.ctx_index); |
424 | 409 |
425 #endif | 410 #endif |
426 | 411 |