Nginx事件模块init

首先在nginx里面最重的是下述三个模块

ngx_events_module,
ngx_event_core_module,
ngx_epoll_module,
ngx_events_module

这个模块属于core_module在程序起来的时候就init, 它的commands成员只有一个,也就是说只关注配置文件中events这一标签。

static ngx_command_t  ngx_events_commands[] = {
      { ngx_string("events"),
      NGX_MAIN_CONF|NGX_CONF_BLOCK|NGX_CONF_NOARGS,
      ngx_events_block,
      0,
      0,
      NULL },

      ngx_null_command
};

nginx在关注了这一标签之后会执行ngx_events_block函数的代码设置,ngx_events_block主要的工作有

ngx_event_max_module = ngx_count_modules(cf->cycle, NGX_EVENT_MODULE);
//遍历nginx里面的全局数组modules,如果类型为NGX_EVENT_MODULE,则设置ctx_index, 
//计算出当前有多 少个event module

下面分别调用event module的create conf和init conf
值得注意的是(*ctx)[x] 指向的是具体的模块

    void               ***ctx;
    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 *));
    if (*ctx == NULL) {
        return NGX_CONF_ERROR;
    }

  *(void **) conf = ctx;
    for (i = 0; cf->cycle->modules[i]; i++) {
        if (cf->cycle->modules[i]->type != NGX_EVENT_MODULE) {
            continue;
        }

        m = cf->cycle->modules[i]->ctx;

        if (m->create_conf) {
            (*ctx)[cf->cycle->modules[i]->ctx_index] =
                                                     m->create_conf(cf->cycle);
            if ((*ctx)[cf->cycle->modules[i]->ctx_index] == NULL) {
                return NGX_CONF_ERROR;
            }
        }
    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值