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

相关推荐
冬夜戏雪7 小时前
nginx改配置文件还是会访问默认nginx欢迎页面排查 + 域名访问
css·nginx·css3
星辰云-11 小时前
Nginx笔记
运维·笔记·nginx
亲爱的非洲野猪1 天前
Nginx vs Spring Cloud Gateway:限流功能深度对比与实践指南
运维·nginx
石小千1 天前
Nginx服务做负载均衡网关
运维·nginx·负载均衡
叁金Coder2 天前
业务系统跳转Nacos免登录方案实践
前端·javascript·nginx·nacos
William一直在路上3 天前
深度解析:Nginx的卓越性能
运维·nginx
小十十3 天前
K8s+Nginx-ingress+Websocket基础知识理解
websocket·nginx·kubernetes
hzsnone3 天前
公网服务器上Nginx或者Openresty如何屏蔽IP直接扫描
服务器·nginx·openresty
PanYu——BJ3 天前
CentOS Nginx 1.13.9 部署文档
linux·nginx·centos
MX_93594 天前
使用Nginx部署前端项目
运维·前端·nginx