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

相关推荐
2601_962128266 小时前
Nginx目录结构
运维·nginx
2601_9621229710 小时前
nginx 部署前端vue项目
前端·vue.js·nginx
2601_9621282615 小时前
Nginx知识详解(理论+实战更易懂)
运维·nginx
2601_9622035118 小时前
Nginx 安装配置
运维·nginx
牧码岛2 天前
阿里云服务器新端口上线SOP(Windows+Nginx+HTTPS)
服务器·nginx·阿里云
xixingzhe22 天前
nginx无网络升级
服务器·nginx
你住过的屋檐3 天前
【Nginx】linux上安装nginx
linux·运维·nginx
liangshanbo12153 天前
Nginx 进程管理命令深度面试题解析
java·nginx·面试
weixin_511255213 天前
NGINX常用配置
linux·服务器·nginx
痕迹运维4 天前
Nginx Docker容器化安装
nginx