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

相关推荐
WGS.3 小时前
Ubuntu 更改 Nginx 版本
nginx
莱茵不哈哈3 小时前
OpenResty 深度解析:构建高性能 Web 服务的终极方案
nginx·lua·kong·openresty·conf
SHUIPING_YANG6 小时前
Nginx 返回 504 状态码表示 网关超时(Gateway Timeout)原因排查
运维·nginx·gateway
〆、风神9 小时前
面试真题 - 高并发场景下Nginx如何优化
java·nginx·面试
noravinsc19 小时前
国产化中间件 替换 nginx
运维·nginx·中间件
ZHOU_WUYI21 小时前
使用 Docker 部署 React + Nginx 应用教程
nginx·react.js·docker
梦在深巷、1 天前
nginx配置之负载均衡
运维·nginx·负载均衡
iRayCheung1 天前
Kind方式部署k8s单节点集群并创建nginx服务对外访问
nginx·kubernetes·kind
影龙帝皖2 天前
Linux服务之lvs+keepalived nginx+keepalived负载均衡实例解析
linux·nginx·lvs
nangonghen2 天前
Nginx stream模块是连接级别的负载均衡
nginx·负载均衡