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,代表 成功

相关推荐
Peace6 小时前
【Nginx】
linux·运维·nginx
爱吃土豆的马铃薯ㅤㅤㅤㅤㅤㅤㅤㅤㅤ10 小时前
【无标题】
nginx
Aipollo12 小时前
从Nginx到AI网关:网关技术的演进之路
运维·人工智能·nginx
薛定谔的猫喵喵16 小时前
【从 HTTP 到 HTTPS】Flask 多项目迁移到 Nginx 子路径完整实战
python·nginx·http·https·flask·ssl
cvcode_study17 小时前
Nginx 基础
运维·nginx
福大大架构师每日一题18 小时前
nginx 1.31.1 发布:一次安全修复驱动的主线升级,涉及 Rewrite、HTTP/2、Mail、MP4 与工作流修正
nginx·安全·http
Shawn Dev18 小时前
使用 Certbot 为 Nginx 自动申请 HTTPS 证书并配置自动续签
运维·nginx·https
爱吃土豆的马铃薯ㅤㅤㅤㅤㅤㅤㅤㅤㅤ18 小时前
docker重新加载docer-compose.yml文件(nginx配置)
nginx·docker·eureka
Yana.nice19 小时前
nginx+tomcat环境下,nginx对后端Tomcat实例的健康检查机制
运维·nginx·tomcat
難釋懷19 小时前
Nginx动静分离
运维·nginx·firefox