处理events
其中符合NGX_EVENT_MODULE有两个模块分别是ngx_event_core_module、ngx_epoll_module
核心代码
ngx_modules[i]->ctx_index = ngx_event_max_module++;//设置模块内部索引
}
ctx = ngx_pcalloc(cf->pool, sizeof(void *));
if (ctx == NULL) {
return NGX_CONF_ERROR;
}
*ctx = ngx_pcalloc(cf->pool, ngx_event_max_module * sizeof(void *));//ctx指向数组
if (*ctx == NULL) {
return NGX_CONF_ERROR;
}
*(void **) conf = ctx;
for (i = 0; ngx_modules[i]; i++) {
if (ngx_modules[i]->type != NGX_EVENT_MODULE) {
continue;
}
m = ngx_modules[i]->ctx;
if (m->create_conf) {//如果NGX_EVENT_MODULE类型模块存在create_conf函数那么就调用该模块的create_conf函数,挂载到event上下文中
(*ctx)[ngx_modules[i]->ctx_index] = m->create_conf(cf->cycle);//创建相应上下文
if ((*ctx)[ngx_modules[i]->ctx_index] == NULL) {
return NGX_CONF_ERROR;
}
}
}
pcf = *cf;
cf->ctx = ctx;
cf->module_type = NGX_EVENT_MODULE;//设置模块环境
cf->cmd_type = NGX_EVENT_CONF; //设置命令类型
rv = ngx_conf_parse(cf, NULL);
然后解析worker_connections1024,该命令在ngx_event_core_module中,调用ngx_event_connections函数,设置connect值为1024,结构如下: