ngx_cycle_modules

Ubuntu 下 nginx-1.24.0 源码分析 - ngx_cycle_modules-CSDN博客


定义 在 src/core/ngx_module.c
复制代码
ngx_int_t
ngx_cycle_modules(ngx_cycle_t *cycle)
{
    /*
     * create a list of modules to be used for this cycle,
     * copy static modules to it
     */

    cycle->modules = ngx_pcalloc(cycle->pool, (ngx_max_module + 1)
                                              * sizeof(ngx_module_t *));
    if (cycle->modules == NULL) {
        return NGX_ERROR;
    }

    ngx_memcpy(cycle->modules, ngx_modules,
               ngx_modules_n * sizeof(ngx_module_t *));

    cycle->modules_n = ngx_modules_n;

    return NGX_OK;
}

复制代码
    cycle->modules = ngx_pcalloc(cycle->pool, (ngx_max_module + 1)
                                              * sizeof(ngx_module_t *));
    if (cycle->modules == NULL) {
        return NGX_ERROR;
    }
在 cycle 的内存池中分配内存,存储模块指针数组

ngx_max_module + 1:ngx_max_module 是最大模块数,+1 用于预留终止标记( NULL)


复制代码
    ngx_memcpy(cycle->modules, ngx_modules,
               ngx_modules_n * sizeof(ngx_module_t *));

将全局模块数组 ngx_modules 拷贝到 cycle->modules


复制代码
cycle->modules_n = ngx_modules_n;
将全局模块数量 ngx_modules_n 赋值给 cycle->modules_n

复制代码
return NGX_OK;

返回 NGX_OK,代表 成功

相关推荐
Joy T12 小时前
从 Nginx 到 Gateway 再到微服务:一次 AI 请求的完整链路
nginx·微服务·gateway·controller·路由转发·ai service·接口错误排查
小匠石钧知12 小时前
07_在k8s集群中安装ingress-nginx
nginx·容器·kubernetes·ingress
百度一下吧1 天前
Nginx 使用手册:从安装配置到实战部署
运维·nginx
JAVA面经实录9171 天前
Java高级后端 · 全套面试通关手册(Nginx)
java·nginx·面试
lpfasd1233 天前
WinSW在Win7上失败真相-实测与修复
windows·nginx
lpfasd1233 天前
nginx服务化五套方案原理解剖与选型
运维·nginx
ue星空3 天前
ALS V4 中文拆解手册
运维·nginx
吴声子夜歌4 天前
Nginx应用与运维——Nginx集群负载与配置管理(二)
运维·nginx
cpolar技术支持4 天前
外网测试机的异常传不回内网?自托管 Sentry,用 cpolar 打通错误上报链路
python·nginx·docker·cpolar·sentry
吴声子夜歌5 天前
Nginx应用与运维——Nginx在Kubernetes中的应用(一)
运维·nginx·kubernetes