nginx重要的数据结构

struct ngx_module_s { 
    //ctx_index是分类的模块计数器,nginx的模块可以分为四种:core、event、http和 
    //mail,每一种的模块又会各自计数一下,这个ctx_index就是每个模块在其所属类组的计数值 
 
    ngx_uint_t            ctx_index;     
 
    //index是一个模块计数器,按照每个模块在ngx_modules[]数组中的声明顺序 
    //(见objs/ngx_modules.c),从0开始依次给每个模块进行编号 
    ngx_uint_t            index;  
 
    /*...*/ 
    ngx_uint_t            version; 
 
    //ctx是模块的上下文,不同种类的模块有不同的上下文,四类模块就有四种模块上下文,实现为四个不同的结构体,所以ctx是void * 
    void                 *ctx;  
 
    //commands 是模块的指令集,nginx的每个模块都可以实现一些自定义的指令,这些指令 
    //写在配置文件的适当配置项中,每一个指令在源码中对应着一个 ngx_command_t结构的 
    //变量,nginx会从配置文件中把模块的指令读取出来放到模块的commands指令数组中, 
    //这些指令一般是把配置项的 参数值赋给一些程序中的变量或者是在不同的变量之间合并或 
    //转换数据(例如include指令),指令可以带参数也可以不带参数,你可以把这些指令想象 
    //为 unix的命令行或者是一种模板语言的指令。 
    ngx_command_t        *commands; 
 
    //type就是模块的种类,前面已经说过,nginx模块分为core、event、http和mail四类,type用宏定义标识四个分类。  
    ngx_uint_t            type;  
 
    //init_master、 init_module、init_process、init_thread、exit_thread、 
    //exit_process、 exit_master是函数指针,指向模块实现的自定义回调函数, 
    //这些回调函数分别在初始化master、初始化模块、初始化工作进程、初始化线程、 
    //退出线程、退出工作进程和退出master的时候被调用,如果模块需要在这些时机做处理, 
    //就可以实现对应的函数,并把它赋值给对应的函数指针来注册一个回调 函数接口 
    ngx_int_t           (*init_master)(ngx_log_t *log); 
    ngx_int_t           (*init_module)(ngx_cycle_t *cycle); 
    ngx_int_t           (*init_process)(ngx_cycle_t *cycle); 
    ngx_int_t           (*init_thread)(ngx_cycle_t *cycle); 
    void                (*exit_thread)(ngx_cycle_t *cycle); 
    void                (*exit_process)(ngx_cycle_t *cycle); 
    void                (*exit_master)(ngx_cycle_t *cycle); 
 
    /*...*/ 
 
};




struct ngx_cycle_s { 
   void                  ****conf_ctx;  //配置上下文数组(含所有模块) 
   ngx_pool_t               *pool;      //内存池 
 
    ngx_log_t                *log;       //日志 
    ngx_log_t                 new_log; 
 
    ngx_connection_t        **files;     //连接文件 
    ngx_connection_t         *free_connections;  //空闲连接 
    ngx_uint_t                free_connection_n; //空闲连接个数 
 
    ngx_queue_t               reusable_connections_queue;  //再利用连接队列 
 
    ngx_array_t               listening;     //监听数组 
    ngx_array_t               pathes;        //路径数组 
    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;     //old cycle指针 
 
    ngx_str_t                 conf_file;     //配置文件 
    ngx_str_t                 conf_param;    //配置参数 
    ngx_str_t                 conf_prefix;   //配置前缀 
    ngx_str_t                 prefix;        //前缀 
    ngx_str_t                 lock_file;     //锁文件 
    ngx_str_t                 hostname;      //主机名 
}; 


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值