nginx基本数据结构ngx_module_t,ngx_module_s
ngx_module_t是nginx的模塊化架構(gòu)最基本的數(shù)據(jù)結(jié)構(gòu)。?
其結(jié)構(gòu)定義如下,其中的注釋為功能說明:?
struct ngx_module_s {
??? ngx_uint_t??????????? ctx_index;???
???????? /*分類的模塊計(jì)數(shù)器
???????? nginx模塊可以分為四種:core、event、http和mail
???????? 每個(gè)模塊都會各自計(jì)數(shù),ctx_index就是每個(gè)模塊在其所屬類組的計(jì)數(shù)*/
????????
??? ngx_uint_t??????????? index;??????????????
???????? /*一個(gè)模塊計(jì)數(shù)器,按照每個(gè)模塊在ngx_modules[]數(shù)組中的聲明順序,從0開始依次給每個(gè)模塊賦值*/
?
??? ngx_uint_t??????????? spare0;
??? ngx_uint_t??????????? spare1;
??? ngx_uint_t??????????? spare2;
??? ngx_uint_t??????????? spare3;
?
??? ngx_uint_t??????????? version;?????????? //nginx模塊版本
?
??? void???????????????? *ctx;??????????????????????????
???????? /*模塊的上下文,不同種類的模塊有不同的上下文,因此實(shí)現(xiàn)了四種結(jié)構(gòu)體*/
????????
??? ngx_command_t??????? *commands;
???????? /*命令定義地址
???????? 模塊的指令集
???????? 每一個(gè)指令在源碼中對應(yīng)著一個(gè)ngx_command_t結(jié)構(gòu)變量*/
????????
??? ngx_uint_t??????????? type;????????????????????????? //模塊類型,用于區(qū)分core eventhttp和mail
?
??? ngx_int_t?????????? (*init_master)(ngx_log_t *log);??????????????????????????? //初始化master時(shí)執(zhí)行
?
??? ngx_int_t?????????? (*init_module)(ngx_cycle_t *cycle);?????????? //初始化module時(shí)執(zhí)行
?
??? ngx_int_t?????????? (*init_process)(ngx_cycle_t *cycle); //初始化process時(shí)執(zhí)行
??? ngx_int_t?????????? (*init_thread)(ngx_cycle_t *cycle);???????????? //初始化thread時(shí)執(zhí)行
??? void??????????????? (*exit_thread)(ngx_cycle_t*cycle);????????? //退出thread時(shí)執(zhí)行
??? void??????????????? (*exit_process)(ngx_cycle_t*cycle);??????? //退出process時(shí)執(zhí)行
?
??? void??????????????? (*exit_master)(ngx_cycle_t*cycle);???????? ???????? //退出master時(shí)執(zhí)行
?
//以下功能不明
??? uintptr_t???????????? spare_hook0;
??? uintptr_t???????????? spare_hook1;
??? uintptr_t???????????? spare_hook2;
??? uintptr_t???????????? spare_hook3;
??? uintptr_t???????????? spare_hook4;
??? uintptr_t???????????? spare_hook5;
??? uintptr_t???????????? spare_hook6;
??? uintptr_t???????????? spare_hook7;
};
?
typedef struct ngx_module_s????? ngx_module_t;
nginx定義了很多模塊,每個(gè)模塊都有自己所屬的類型,可以定義一些屬于自己的操作函數(shù),通過把這些函數(shù)賦值為對應(yīng)類型結(jié)構(gòu)體中的函數(shù)指針,就可以注冊了不同的回調(diào)函數(shù)接口,以此實(shí)現(xiàn)不同的功能,有點(diǎn)c++多態(tài)的感覺!
總結(jié)
以上是生活随笔為你收集整理的nginx基本数据结构ngx_module_t,ngx_module_s的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: FLV封装格式分析器
- 下一篇: 创建标签