static ngx_int_t
ngx_conf_handler(ngx_conf_t *cf, ngx_int_t last)
{char *rv;void *conf, **confp;ngx_uint_t i, found;ngx_str_t *name;ngx_command_t *cmd;name = cf->args->elts;found = 0;
此时
name->data=worker_connections
worker_connections
是 Nginx 中用于控制每个 工作进程(worker process) 能同时处理的最大连接数的配置参数
设置 worker_connections 1024;
,则每个工作进程最多可同时处理 1024 个连接
for (i = 0; cf->cycle->modules[i]; i++) {cmd = cf->cycle->modules[i]->commands;if (cmd == NULL) {continue;}for ( /* void */ ; cmd->name.len; cmd++) {if (name->len != cmd->name.len) {continue;}if (ngx_strcmp(name->data, cmd->name.data) != 0) {continue;}found = 1;
查找 worker_connections 指令
此时
在
cf->cycle->modules[6]->name=ngx_event_core_module
中 找到了 worker_connections 指令
if (cf->cycle->modules[i]->type != NGX_CONF_MODULE&& cf->cycle->modules[i]->type != cf->module_type){continue;}/* is the directive's location right ? */if (!(cmd->type & cf->cmd_type)) {continue;}if (!(cmd->type & NGX_CONF_BLOCK) && last != NGX_OK) {ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,"directive \"%s\" is not terminated by \";\"",name->data);return NGX_ERROR;}if ((cmd->type & NGX_CONF_BLOCK) && last != NGX_CONF_BLOCK_START) {ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,"directive \"%s\" has no opening \"{\"",name->data);return NGX_ERROR;}/* is the directive's argument count right ? */if (!(cmd->type & NGX_CONF_ANY)) {if (cmd->type & NGX_CONF_FLAG) {if (cf->args->nelts != 2) {goto invalid;}} else if (cmd->type & NGX_CONF_1MORE) {if (cf->args->nelts < 2) {goto invalid;}} else if (cmd->type & NGX_CONF_2MORE) {if (cf->args->nelts < 3) {goto invalid;}} else if (cf->args->nelts > NGX_CONF_MAX_ARGS) {goto invalid;} else if (!(cmd->type & argument_number[cf->args->nelts - 1])){goto invalid;}}
通过语法校验
/* set up the directive's configuration context */conf = NULL;if (cmd->type & NGX_DIRECT_CONF) {conf = ((void **) cf->ctx)[cf->cycle->modules[i]->index];} else if (cmd->type & NGX_MAIN_CONF) {conf = &(((void **) cf->ctx)[cf->cycle->modules[i]->index]);} else if (cf->ctx) {confp = *(void **) ((char *) cf->ctx + cmd->conf);if (confp) {conf = confp[cf->cycle->modules[i]->ctx_index];}}
此时
} else if (cf->ctx) {confp = *(void **) ((char *) cf->ctx + cmd->conf);
成立
cmd->conf=0
confp 指向一个数组,数组的每一个元素是一个指针,每一个指针指向一个 配置结构,这些配置结构是属于不同的 event 类型模块的
rv = cmd->set(cf, cmd, conf);
worker_connections 指令 的 set 函数
worker_connections 指令 的 set 函数-CSDN博客
if (rv == NGX_CONF_OK) {return NGX_OK;}
返回 NGX_OK 代表 指令处理成功