Mercurial > hg > nginx
comparison src/event/ngx_event.c @ 96:a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Tue, 27 May 2003 12:18:54 +0000 |
parents | 738fe44c70d5 |
children | 70d2345a903f |
comparison
equal
deleted
inserted
replaced
95:b48066122884 | 96:a23d010f356d |
---|---|
10 | 10 |
11 | 11 |
12 extern ngx_event_module_t ngx_select_module_ctx; | 12 extern ngx_event_module_t ngx_select_module_ctx; |
13 | 13 |
14 #if (HAVE_KQUEUE) | 14 #if (HAVE_KQUEUE) |
15 extern ngx_event_module_t ngx_kqueue_module_ctx; | |
16 #include <ngx_kqueue_module.h> | 15 #include <ngx_kqueue_module.h> |
17 #endif | 16 #endif |
18 | 17 |
19 #if (HAVE_DEVPOLL) | 18 #if (HAVE_DEVPOLL) |
20 extern ngx_event_module_t ngx_devpoll_module_ctx; | 19 extern ngx_module_t ngx_devpoll_module; |
21 #endif | 20 #endif |
22 | 21 |
23 #if (HAVE_AIO) | 22 #if (HAVE_AIO) |
24 #include <ngx_aio_module.h> | 23 #include <ngx_aio_module.h> |
25 #endif | 24 #endif |
28 #include <ngx_event_acceptex.h> | 27 #include <ngx_event_acceptex.h> |
29 #include <ngx_iocp_module.h> | 28 #include <ngx_iocp_module.h> |
30 #endif | 29 #endif |
31 | 30 |
32 | 31 |
33 static char *ngx_events_block(ngx_conf_t *cf, ngx_command_t *cmd, char *dummy); | 32 static char *ngx_events_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); |
34 static char *ngx_event_use(ngx_conf_t *cf, ngx_command_t *cmd, char *conf); | 33 static char *ngx_event_use(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); |
35 static void *ngx_event_create_conf(ngx_pool_t *pool); | 34 static void *ngx_event_create_conf(ngx_pool_t *pool); |
36 static char *ngx_event_init_conf(ngx_pool_t *pool, void *conf); | 35 static char *ngx_event_init_conf(ngx_pool_t *pool, void *conf); |
37 | 36 |
38 | 37 |
39 int ngx_event_flags; | 38 int ngx_event_flags; |
59 ngx_events_block, | 58 ngx_events_block, |
60 0, | 59 0, |
61 0, | 60 0, |
62 NULL}, | 61 NULL}, |
63 | 62 |
64 {ngx_string(""), 0, NULL, 0, 0, NULL} | 63 ngx_null_command |
65 }; | 64 }; |
66 | 65 |
67 | 66 |
68 ngx_module_t ngx_events_module = { | 67 ngx_module_t ngx_events_module = { |
68 NGX_MODULE, | |
69 &events_name, /* module context */ | 69 &events_name, /* module context */ |
70 0, /* module index */ | |
71 ngx_events_commands, /* module directives */ | 70 ngx_events_commands, /* module directives */ |
72 NGX_CORE_MODULE_TYPE, /* module type */ | 71 NGX_CORE_MODULE, /* module type */ |
73 NULL /* init module */ | 72 NULL /* init module */ |
74 }; | 73 }; |
75 | 74 |
76 | 75 |
77 | 76 |
96 ngx_conf_set_num_slot, | 95 ngx_conf_set_num_slot, |
97 0, | 96 0, |
98 offsetof(ngx_event_conf_t, timer_queues), | 97 offsetof(ngx_event_conf_t, timer_queues), |
99 NULL}, | 98 NULL}, |
100 | 99 |
101 {ngx_string(""), 0, NULL, 0, 0, NULL} | 100 ngx_null_command |
102 }; | 101 }; |
103 | 102 |
104 | 103 |
105 ngx_event_module_t ngx_event_module_ctx = { | 104 ngx_event_module_t ngx_event_module_ctx = { |
106 NGX_EVENT_MODULE, | |
107 &event_name, | 105 &event_name, |
108 ngx_event_create_conf, /* create configuration */ | 106 ngx_event_create_conf, /* create configuration */ |
109 ngx_event_init_conf, /* init configuration */ | 107 ngx_event_init_conf, /* init configuration */ |
110 | 108 |
111 { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL } | 109 { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL } |
112 }; | 110 }; |
113 | 111 |
114 | 112 |
115 ngx_module_t ngx_event_module = { | 113 ngx_module_t ngx_event_module = { |
114 NGX_MODULE, | |
116 &ngx_event_module_ctx, /* module context */ | 115 &ngx_event_module_ctx, /* module context */ |
117 0, /* module index */ | |
118 ngx_event_commands, /* module directives */ | 116 ngx_event_commands, /* module directives */ |
119 NGX_EVENT_MODULE_TYPE, /* module type */ | 117 NGX_EVENT_MODULE, /* module type */ |
120 NULL /* init module */ | 118 NULL /* init module */ |
121 }; | 119 }; |
122 | 120 |
123 | 121 |
124 | 122 |
130 ngx_event_t *ev; | 128 ngx_event_t *ev; |
131 ngx_connection_t *c; | 129 ngx_connection_t *c; |
132 ngx_event_conf_t *ecf; | 130 ngx_event_conf_t *ecf; |
133 ngx_event_module_t *module; | 131 ngx_event_module_t *module; |
134 | 132 |
135 ecf = ngx_event_get_conf(ngx_event_module_ctx); | 133 ecf = ngx_event_get_conf(ngx_event_module); |
136 | 134 |
137 ngx_log_debug(log, "CONN: %d" _ ecf->connections); | 135 ngx_log_debug(log, "CONN: %d" _ ecf->connections); |
138 ngx_log_debug(log, "TYPE: %d" _ ecf->use); | 136 ngx_log_debug(log, "TYPE: %d" _ ecf->use); |
139 | 137 |
140 for (m = 0; ngx_modules[m]; m++) { | 138 for (m = 0; ngx_modules[m]; m++) { |
141 if (ngx_modules[m]->type != NGX_EVENT_MODULE_TYPE) { | 139 if (ngx_modules[m]->type != NGX_EVENT_MODULE) { |
142 continue; | 140 continue; |
143 } | 141 } |
144 | 142 |
145 module = ngx_modules[m]->ctx; | 143 if (ngx_modules[m]->ctx_index == ecf->use) { |
146 if (module->index == ecf->use) { | 144 module = ngx_modules[m]->ctx; |
147 if (module->actions.init(log) == NGX_ERROR) { | 145 if (module->actions.init(log) == NGX_ERROR) { |
148 return NGX_ERROR; | 146 return NGX_ERROR; |
149 } | 147 } |
150 break; | 148 break; |
151 } | 149 } |
245 ngx_process_events(log); | 243 ngx_process_events(log); |
246 } | 244 } |
247 } | 245 } |
248 | 246 |
249 | 247 |
250 static char *ngx_events_block(ngx_conf_t *cf, ngx_command_t *cmd, char *conf) | 248 static char *ngx_events_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
251 { | 249 { |
252 int m; | 250 int m; |
253 char *rv; | 251 char *rv; |
254 void ***ctx; | 252 void ***ctx; |
255 ngx_conf_t pcf; | 253 ngx_conf_t pcf; |
257 | 255 |
258 /* count the number of the event modules and set up their indices */ | 256 /* count the number of the event modules and set up their indices */ |
259 | 257 |
260 ngx_event_max_module = 0; | 258 ngx_event_max_module = 0; |
261 for (m = 0; ngx_modules[m]; m++) { | 259 for (m = 0; ngx_modules[m]; m++) { |
262 if (ngx_modules[m]->type != NGX_EVENT_MODULE_TYPE) { | 260 if (ngx_modules[m]->type != NGX_EVENT_MODULE) { |
263 continue; | 261 continue; |
264 } | 262 } |
265 | 263 |
266 module = ngx_modules[m]->ctx; | 264 ngx_modules[m]->ctx_index = ngx_event_max_module++; |
267 module->index = ngx_event_max_module++; | |
268 } | 265 } |
269 | 266 |
270 ngx_test_null(ctx, ngx_pcalloc(cf->pool, sizeof(void *)), NGX_CONF_ERROR); | 267 ngx_test_null(ctx, ngx_pcalloc(cf->pool, sizeof(void *)), NGX_CONF_ERROR); |
271 | 268 |
272 ngx_test_null(*ctx, | 269 ngx_test_null(*ctx, |
274 NGX_CONF_ERROR); | 271 NGX_CONF_ERROR); |
275 | 272 |
276 *(void **) conf = ctx; | 273 *(void **) conf = ctx; |
277 | 274 |
278 for (m = 0; ngx_modules[m]; m++) { | 275 for (m = 0; ngx_modules[m]; m++) { |
279 if (ngx_modules[m]->type != NGX_EVENT_MODULE_TYPE) { | 276 if (ngx_modules[m]->type != NGX_EVENT_MODULE) { |
280 continue; | 277 continue; |
281 } | 278 } |
282 | 279 |
283 module = ngx_modules[m]->ctx; | 280 module = ngx_modules[m]->ctx; |
284 | 281 |
285 if (module->create_conf) { | 282 if (module->create_conf) { |
286 ngx_test_null((*ctx)[module->index], module->create_conf(cf->pool), | 283 ngx_test_null((*ctx)[ngx_modules[m]->ctx_index], |
284 module->create_conf(cf->pool), | |
287 NGX_CONF_ERROR); | 285 NGX_CONF_ERROR); |
288 } | 286 } |
289 } | 287 } |
290 | 288 |
291 pcf = *cf; | 289 pcf = *cf; |
292 cf->ctx = ctx; | 290 cf->ctx = ctx; |
293 cf->module_type = NGX_EVENT_MODULE_TYPE; | 291 cf->module_type = NGX_EVENT_MODULE; |
294 cf->cmd_type = NGX_EVENT_CONF; | 292 cf->cmd_type = NGX_EVENT_CONF; |
295 rv = ngx_conf_parse(cf, NULL); | 293 rv = ngx_conf_parse(cf, NULL); |
296 *cf = pcf; | 294 *cf = pcf; |
297 | 295 |
298 if (rv != NGX_CONF_OK) | 296 if (rv != NGX_CONF_OK) |
299 return rv; | 297 return rv; |
300 | 298 |
301 for (m = 0; ngx_modules[m]; m++) { | 299 for (m = 0; ngx_modules[m]; m++) { |
302 if (ngx_modules[m]->type != NGX_EVENT_MODULE_TYPE) { | 300 if (ngx_modules[m]->type != NGX_EVENT_MODULE) { |
303 continue; | 301 continue; |
304 } | 302 } |
305 | 303 |
306 module = ngx_modules[m]->ctx; | 304 module = ngx_modules[m]->ctx; |
307 | 305 |
308 if (module->init_conf) { | 306 if (module->init_conf) { |
309 rv = module->init_conf(cf->pool, (*ctx)[module->index]); | 307 rv = module->init_conf(cf->pool, (*ctx)[ngx_modules[m]->ctx_index]); |
310 if (rv != NGX_CONF_OK) { | 308 if (rv != NGX_CONF_OK) { |
311 return rv; | 309 return rv; |
312 } | 310 } |
313 } | 311 } |
314 } | 312 } |
315 | 313 |
316 return NGX_CONF_OK; | 314 return NGX_CONF_OK; |
317 } | 315 } |
318 | 316 |
319 | 317 |
320 static char *ngx_event_use(ngx_conf_t *cf, ngx_command_t *cmd, char *conf) | 318 static char *ngx_event_use(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
321 { | 319 { |
322 ngx_event_conf_t *ecf = (ngx_event_conf_t *) conf; | 320 ngx_event_conf_t *ecf = conf; |
323 | 321 |
324 int m; | 322 int m; |
325 ngx_str_t *args; | 323 ngx_str_t *args; |
326 ngx_event_module_t *module; | 324 ngx_event_module_t *module; |
327 | 325 |
330 } | 328 } |
331 | 329 |
332 args = cf->args->elts; | 330 args = cf->args->elts; |
333 | 331 |
334 for (m = 0; ngx_modules[m]; m++) { | 332 for (m = 0; ngx_modules[m]; m++) { |
335 if (ngx_modules[m]->type != NGX_EVENT_MODULE_TYPE) { | 333 if (ngx_modules[m]->type != NGX_EVENT_MODULE) { |
336 continue; | 334 continue; |
337 } | 335 } |
338 | 336 |
339 module = ngx_modules[m]->ctx; | 337 module = ngx_modules[m]->ctx; |
340 if (module->name->len == args[1].len) { | 338 if (module->name->len == args[1].len) { |
341 if (ngx_strcmp(module->name->data, args[1].data) == 0) { | 339 if (ngx_strcmp(module->name->data, args[1].data) == 0) { |
342 ecf->use = module->index; | 340 ecf->use = ngx_modules[m]->ctx_index; |
343 return NGX_CONF_OK; | 341 return NGX_CONF_OK; |
344 } | 342 } |
345 } | 343 } |
346 } | 344 } |
347 | 345 |
378 } else if (ecf->connections > ngx_max_connections) { | 376 } else if (ecf->connections > ngx_max_connections) { |
379 } | 377 } |
380 #endif | 378 #endif |
381 | 379 |
382 ngx_conf_init_value(ecf->connections, DEF_CONNECTIONS); | 380 ngx_conf_init_value(ecf->connections, DEF_CONNECTIONS); |
383 ngx_conf_init_value(ecf->use, ngx_kqueue_module_ctx.index); | 381 ngx_conf_init_value(ecf->use, ngx_kqueue_module.ctx_index); |
384 | 382 |
385 #elif (HAVE_DEVPOLL) | 383 #elif (HAVE_DEVPOLL) |
386 | 384 |
387 ngx_conf_init_value(ecf->connections, DEF_CONNECTIONS); | 385 ngx_conf_init_value(ecf->connections, DEF_CONNECTIONS); |
388 ngx_conf_init_value(ecf->use, ngx_devpoll_module_ctx.index); | 386 ngx_conf_init_value(ecf->use, ngx_devpoll_module.ctx_index); |
389 | 387 |
390 #else /* HAVE_SELECT */ | 388 #else /* HAVE_SELECT */ |
391 | 389 |
392 ngx_conf_init_value(ecf->connections, | 390 ngx_conf_init_value(ecf->connections, |
393 FD_SETSIZE < DEF_CONNECTIONS ? FD_SETSIZE : DEF_CONNECTIONS); | 391 FD_SETSIZE < DEF_CONNECTIONS ? FD_SETSIZE : DEF_CONNECTIONS); |
394 | 392 |
395 ngx_conf_init_value(ecf->use, ngx_select_module_ctx.index); | 393 ngx_conf_init_value(ecf->use, ngx_select_module.ctx_index); |
396 | 394 |
397 #endif | 395 #endif |
398 | 396 |
399 ngx_conf_init_value(ecf->timer_queues, 10); | 397 ngx_conf_init_value(ecf->timer_queues, 10); |
400 | 398 |