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

相关推荐
Harvy_没救了9 小时前
【网络部署】 Win11 + VMware CentOS8 + Nginx 文件共享服务 Wiki
运维·网络·nginx
遇见火星14 小时前
Nginx限流配置:防止接口被刷,服务器稳如泰山
运维·服务器·nginx
Jinkxs1 天前
LoadBalancer- 主流负载均衡工具盘点:Nginx / Haproxy / Keepalived 基础介绍
运维·nginx·负载均衡
ReaF_star1 天前
【安全】SSL证书更新操作手册(Nginx+Cloudflare+acme.sh)
nginx·安全·ssl
云动课堂1 天前
【运维实战】Nginx 高性能Web服务 · 一键自动化部署方案 (适配银河麒麟 V10 / openEuler / CentOS 7/8)
运维·前端·nginx
2601_949817922 天前
nginx 代理 redis
运维·redis·nginx
java1234_小锋2 天前
解释一下NGINX的反向代理和正向代理的区别?
运维·nginx
techdashen2 天前
Cloudflare 为何抛弃 NGINX,用 Rust 自研了一个代理
运维·nginx·rust
人生匆匆3 天前
通过nginx解决跨域问题
运维·nginx
子木HAPPY阳VIP3 天前
信创UOS,Docker 完整操作部署(Dockerfile部署方式)&排错整合
linux·运维·redis·nginx·docker·容器·tomcat