Home  >  Article  >  Backend Development  >  [nginx source code analysis] Configuration analysis (event scope)

[nginx source code analysis] Configuration analysis (event scope)

WBOY
WBOYOriginal
2016-08-08 09:24:451015browse

Processing events


There are two modules that conform to NGX_EVENT_MODULE, namely ngx_event_core_module and ngx_epoll_module

Core code

  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);

Then parse worker_connections1024, this command is in ngx_event_core_module, call ngx_even t_connections function, set the connect value to 1024, the structure is as follows :


The above introduces [nginx source code analysis] configuration analysis (event scope), including the content. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn