nginx中ngx_cycle_s的conf_ctx初始化
admin
2024-05-11 19:50:12
0

ngx_cycle_t

是结构体ngx_cycle_s的别名

typedef struct ngx_cycle_s           ngx_cycle_t;

结构体ngx_cycle_s的定义

struct ngx_cycle_s {void                  ****conf_ctx;ngx_pool_t               *pool;ngx_log_t                *log;ngx_log_t                 new_log;ngx_uint_t                log_use_stderr;  /* unsigned  log_use_stderr:1; */ngx_connection_t        **files;ngx_connection_t         *free_connections;ngx_uint_t                free_connection_n;ngx_module_t            **modules;ngx_uint_t                modules_n;ngx_uint_t                modules_used;    /* unsigned  modules_used:1; */ngx_queue_t               reusable_connections_queue;ngx_uint_t                reusable_connections_n;time_t                    connections_reuse_time;ngx_array_t               listening;ngx_array_t               paths;ngx_array_t               config_dump;ngx_rbtree_t              config_dump_rbtree;ngx_rbtree_node_t         config_dump_sentinel;ngx_list_t                open_files;ngx_list_t                shared_memory;ngx_uint_t                connection_n;ngx_uint_t                files_n;ngx_connection_t         *connections;ngx_event_t              *read_events;ngx_event_t              *write_events;ngx_cycle_t              *old_cycle;ngx_str_t                 conf_file;ngx_str_t                 conf_param;ngx_str_t                 conf_prefix;ngx_str_t                 prefix;ngx_str_t                 error_log;ngx_str_t                 lock_file;ngx_str_t                 hostname;
};

conf_ctx

创建

在ngx_init_cycle中创建conf_ctx,分配内存。创建ngx_max_module个void* 内存块

cycle->conf_ctx = ngx_pcalloc(pool, ngx_max_module * sizeof(void *));if (cycle->conf_ctx == NULL) {ngx_destroy_pool(pool);return NULL;}

第一次赋值

模块类型为CORE_MODULE,调用核心模块的create_conf方法来分配内存

for (i = 0; cycle->modules[i]; i++) {if (cycle->modules[i]->type != NGX_CORE_MODULE) {continue;}module = cycle->modules[i]->ctx;if (module->create_conf) {rv = module->create_conf(cycle);if (rv == NULL) {ngx_destroy_pool(pool);return NULL;}cycle->conf_ctx[cycle->modules[i]->index] = rv;}}

核心模块中有create_conf的模块有

模块

create_conf方法

ngx_core_module

ngx_core_module_create_conf

ngx_openssl_module

ngx_openssl_create_conf

ngx_google_perftools_module

ngx_google_perftools_create_conf

ngx_regex_module

ngx_regex_create_conf

ngx_thread_pool_module

ngx_thread_pool_create_conf

解析模块类型为CORE_MODULE且命令类型为NGX_MAIN_CONF

模块

命令名

命令处理

ngx_core_module

daemon

ngx_conf_set_flag_slot

master_process

ngx_conf_set_flag_slot

timer_resolution

ngx_conf_set_msec_slot

pid

ngx_conf_set_str_slot

lock_file

ngx_conf_set_str_slot

worker_processes

ngx_set_worker_processes

debug_points

ngx_conf_set_enum_slot

user

ngx_set_user

worker_priority

ngx_set_priority

worker_cpu_affinity

ngx_set_cpu_affinity

worker_rlimit_nofile

ngx_conf_set_num_slot

worker_rlimit_core

ngx_conf_set_off_slot

worker_shutdown_timeout

ngx_conf_set_msec_slot

working_directory

ngx_conf_set_str_slot

env

ngx_set_env

load_module

ngx_load_module

ngx_events_module

events

ngx_events_block

ngx_openssl_module

ssl_engine

ngx_openssl_engine

ngx_google_perftools_module

google_perftools_profiles

ngx_conf_set_str_slot

ngx_http_module

http

ngx_http_block

ngx_errlog_module

error_log

ngx_error_log

ngx_mail_module

mail

ngx_mail_block

ngx_regex_module

pcre_jit

ngx_conf_set_flag_slot

ngx_stream_module

stream

ngx_stream_block

ngx_thread_pool_module

thread_pool

ngx_thread_pool

第二次赋值

是在ngx_conf_handler中的判断命令类型是否是NGX_MAIN_CONF,此时(((void **) cf->ctx)[cf->cycle->modules[i]->index])是对应模块的配置信息的地址,其存的值是NULL。

通过命令接口的set方法来设置conf

ngx_conf_handler

if (cmd->type & NGX_DIRECT_CONF) {conf = ((void **) cf->ctx)[cf->cycle->modules[i]->index];} else if (cmd->type & NGX_MAIN_CONF) {conf = &(((void **) cf->ctx)[cf->cycle->modules[i]->index]);} else if (cf->ctx) {confp = *(void **) ((char *) cf->ctx + cmd->conf);if (confp) {conf = confp[cf->cycle->modules[i]->ctx_index];}}rv = cmd->set(cf, cmd, conf);

根据命令类型是否是NGX_DIRECT_CONF还是NGX_MAIN_CONF,模块中有命令类型是NGX_DIRECT_CONF则其子接口中都有create_conf方法。

ngx_core_module核心模块中的命令都是NGX_DIRECT_CONF类型

相关内容

热门资讯

linux入门---制作进度条 了解缓冲区 我们首先来看看下面的操作: 我们首先创建了一个文件并在这个文件里面添加了...
C++ 机房预约系统(六):学... 8、 学生模块 8.1 学生子菜单、登录和注销 实现步骤: 在Student.cpp的...
JAVA多线程知识整理 Java多线程基础 线程的创建和启动 继承Thread类来创建并启动 自定义Thread类的子类&#...
【洛谷 P1090】[NOIP... [NOIP2004 提高组] 合并果子 / [USACO06NOV] Fence Repair G ...
国民技术LPUART介绍 低功耗通用异步接收器(LPUART) 简介 低功耗通用异步收发器...
城乡供水一体化平台-助力乡村振... 城乡供水一体化管理系统建设方案 城乡供水一体化管理系统是运用云计算、大数据等信息化手段࿰...
程序的循环结构和random库...   第三个参数就是步长     引入文件时记得指明字符格式,否则读入不了 ...
中国版ChatGPT在哪些方面... 目录 一、中国巨大的市场需求 二、中国企业加速创新 三、中国的人工智能发展 四、企业愿景的推进 五、...
报名开启 | 共赴一场 Flu... 2023 年 1 月 25 日,Flutter Forward 大会在肯尼亚首都内罗毕...
汇编00-MASM 和 Vis... Qt源码解析 索引 汇编逆向--- MASM 和 Visual Studio入门 前提知识ÿ...
【简陋Web应用3】实现人脸比... 文章目录🍉 前情提要🌷 效果演示🥝 实现过程1. u...
前缀和与对数器与二分法 1. 前缀和 假设有一个数组,我们想大量频繁的去访问L到R这个区间的和,...
windows安装JDK步骤 一、 下载JDK安装包 下载地址:https://www.oracle.com/jav...
分治法实现合并排序(归并排序)... 🎊【数据结构与算法】专题正在持续更新中,各种数据结构的创建原理与运用✨...
在linux上安装配置node... 目录前言1,关于nodejs2,配置环境变量3,总结 前言...
Linux学习之端口、网络协议... 端口:设备与外界通讯交流的出口 网络协议:   网络协议是指计算机通信网...
Linux内核进程管理并发同步... 并发同步并发 是指在某一时间段内能够处理多个任务的能力,而 并行 是指同一时间能够处理...
opencv学习-HOG LO... 目录1. HOG(Histogram of Oriented Gradients,方向梯度直方图)1...
EEG微状态的功能意义 导读大脑的瞬时全局功能状态反映在其电场结构上。聚类分析方法一致地提取了四种头表面脑电场结构ÿ...
【Unity 手写PBR】Bu... 写在前面 前期积累: GAMES101作业7提高-实现微表面模型你需要了解的知识 【技...