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

相关推荐
chehaoman9 小时前
Failed to restart nginx.service Unit nginx.service not found
运维·nginx
今晚务必早点睡11 小时前
Nginx 从入门到精通:一篇讲透原理、功能、配置与实战场景
运维·nginx·负载均衡
givemeacar11 小时前
Nginx如何实现 TCP和UDP代理?
tcp/ip·nginx·udp
xuefeiniao12 小时前
Docker 部署宝塔面板 Nginx 反向代理 502 踩坑实录
nginx·docker·容器
yaaakaaang14 小时前
(一)前端,如此简单!---下载Nginx
前端·nginx
jessecyj20 小时前
Nginx中$http_host、$host、$proxy_host的区别
运维·nginx·http
skiy20 小时前
Nginx搭建负载均衡
运维·nginx·负载均衡
明天…ling20 小时前
Redhat 10 部署Nginx实现多IP/多端口/HTTPS访问(避坑实操+问题全解决)
tcp/ip·nginx·https
sunwenjian88621 小时前
Nginx 的 proxy_pass 使用简介
运维·nginx
xiaohe0721 小时前
nginx 代理 redis
运维·redis·nginx