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

相关推荐
阵雨会停.3 小时前
Linux 使用Nginx搭建简易网站模块
运维·nginx
小厂永远得不到的男人4 小时前
一个自学菜鸟的Nginx打怪之路:原来反向代理这么香!
nginx
小厂永远得不到的男人4 小时前
深入剖析Nginx反向代理:从理论到实战的架构进化之路
nginx
ak啊11 小时前
Nginx 性能优化指南
nginx
betazhou1 天前
基于Windows通过nginx代理访问Oracle数据库
数据库·nginx·oracle·代理
zkmall2 天前
ZKmall开源商城静态资源管理:Nginx 配置与优化
运维·nginx·开源
泉城老铁2 天前
nginx配置负载均衡一文解决
nginx
zuozewei2 天前
干货 | 高性能 Nginx 优化配置总结
运维·nginx
YY_Ylx_XX2 天前
Nginx用途以及好处:
运维·nginx
wyk123_0463 天前
Windows 部署项目 apache + mod_wsgi,nginx + waitress
windows·nginx