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

相关推荐
fuyongliang12317 分钟前
nginx反向代理,负载均衡,tomcat的数据流向图篇解析
nginx·tomcat·负载均衡
tuokuac1 小时前
nginx配置前端请求转发到指定的后端ip
前端·tcp/ip·nginx
苹果醋35 小时前
数据库索引设计:在 MongoDB 中创建高效索引的策略
java·运维·spring boot·mysql·nginx
✎﹏赤子·墨筱晗♪6 小时前
从反向代理到负载均衡:Nginx + Tomcat 构建高可用Web服务架构
nginx·tomcat·负载均衡
叶绪2587 小时前
Nginx 反向代理 + Tomcat 集群:负载均衡配置步骤与核心原理
nginx·tomcat·负载均衡
杏花春雨江南10 小时前
腾讯云 CLB (Cloud Load Balancer) 为例,详细讲解如何配置 Nginx 集群
nginx·云计算·腾讯云
牛奶咖啡1311 小时前
Nginx+Tomcat集群Redis共享session方案
redis·nginx·tomcat·redisson·分布式session共享方案·分布式session实现·jdk1.8环境安装
荣光波比13 小时前
Nginx 实战系列(四)—— Nginx反向代理与负载均衡实战指南
运维·nginx·云计算·负载均衡
岚天start14 小时前
K8s Ingress Annotations参数使用指南
nginx·kubernetes·k8s·ingress·ingress控制器
Mr. Cao code14 小时前
探索OpenResty:高性能Web开发利器
linux·运维·服务器·前端·nginx·ubuntu·openresty