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

相关推荐
stark张宇8 小时前
超越 Hello World:深入小程序 Hybrid 初衷、安全配置与上线全链路
nginx·微信小程序·php
希晨er11 小时前
Nginx从入门到实践:安装、配置与应用
nginx
jc062012 小时前
4.5-中间件之Nginx
运维·服务器·nginx
青鱼入云19 小时前
对比nginx、kong、apisix、zuul、gateway网关
nginx·gateway·kong
程序员勾践2 天前
安装nginx
linux·nginx·centos
fxshy2 天前
CentOS 7上安装并配置Nginx监听81端口的完整指南
linux·nginx·centos
比特森林探险记2 天前
Nginx+Lua动态加载黑名单
nginx·junit·lua
惘嘫、冋渞3 天前
CentOS 7 下 Nginx 编译后热重启方案
chrome·nginx·centos
码农-小林3 天前
使用leaflet库加载服务器离线地图瓦片(这边以本地nginx服务器为例)
运维·服务器·nginx
阑梦清川4 天前
docker入门教程--部署nginx和tomcat
nginx·docker·tomcat