ngx_conf_set_str_slot函数解析
2015-11-16 09:46
573 查看
文章来自:http://blog.chinaunix.net/uid-22400280-id-3218765.html
ngx_command_t
static ngx_command_t ngx_http_get_method_commands[]={
{
ngx_string("test"),
NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
getMethodset,
NGX_HTTP_LOC_CONF_OFFSET,
0,
NULL,
},
ngx_null_command
};
ngx_command_s
ngx_array_s
ngx_command_t中的set函数调用时间是,配置文件解析中ngx_conf_t获取指令和指令参数,解析函数查找模块与模块注册的指令,找到正确的指令,则调用该指令set函数执行。
ngx_command_t
static ngx_command_t ngx_http_get_method_commands[]={
{
ngx_string("test"),
NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
getMethodset,
NGX_HTTP_LOC_CONF_OFFSET,
0,
NULL,
},
ngx_null_command
};
ngx_command_s
struct ngx_command_s { ngx_str_t name; ngx_uint_t type; char *(*set)(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); ngx_uint_t conf; ngx_uint_t offset; void *post; };
char * ngx_conf_set_str_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) { char *p = conf; //获取当前配置结构体信息ngx_http__ _conf_t ngx_str_t *field, *value; ngx_conf_post_t *post; field = (ngx_str_t *) (p + cmd->offset); //ngx_command_t的offset作为p的偏移量 /*ngx_command_t的 ngx_uint_t conf指明offset的位置是在哪个配置结构体信息中(main\server\loc)在ngx_http_config.h中定义了conf的三个取值,如下 #define NGX_HTTP_MAIN_CONF_OFFSET offsetof(ngx_http_conf_ctx_t, main_conf) #define NGX_HTTP_SRV_CONF_OFFSET offsetof(ngx_http_conf_ctx_t, srv_conf) #define NGX_HTTP_LOC_CONF_OFFSET offsetof(ngx_http_conf_ctx_t, loc_conf) typedef struct { void **main_conf; void **srv_conf; void **loc_conf; } ngx_http_conf_ctx_t; 获取到保存指令参数的配置结构体conf中,offset指的是在结构体重偏移位置 ngx_conf_t *cf是获取当前环境中的读取配置文件的配置信息包含指令名称指令参数 */ if (field->data) { return "is duplicate"; } value = cf->args->elts; //获取指令数组 *field = value[1]; //获取第一个参数 if (cmd->post) { post = cmd->post; return post->post_handler(cf, post, field); } return NGX_CONF_OK; }
ngx_array_s
struct ngx_array_s { void *elts; //数组数据区起始位置 ngx_uint_t nelts; //实际存放的元素个数 size_t size; //每个元素大小 ngx_uint_t nalloc; //数组所含空间个数,即实际分配的小空间的个数 ngx_pool_t *pool; //该数组在此内存池中分配 };
ngx_command_t中的set函数调用时间是,配置文件解析中ngx_conf_t获取指令和指令参数,解析函数查找模块与模块注册的指令,找到正确的指令,则调用该指令set函数执行。
相关文章推荐
- nginx加载ngx_pagespeed
- nginx使用lua基于url参数分发不同文件对比测试
- ngx lua模块之ngx.location.capture子请求学习
- Nginx 之 http配置段介绍
- nginx下后端realserver健康检测模块ngx_http_upstream_check_module
- Ngx_http_gzip_module
- 或许是_2017年_最新的_ngx_pagespeed_安装姿势
- nginx限制客户端请求数+iptables限制TCP连接和频率来防止DDOS
- Nginx添加ngx-fancyindex模块的方法
- Angular2中如何使用ngx-translate进行国际化
- Angular2+国际化方案(ngx-translate)的示例代码
- Nginx开启ngx_pagespeed模块
- 编程开发的一点学习心得
- Ubuntu 14.10安装显卡驱动
- oracle json 解析函数
- 关于华为x1 7.0无法从eclipse发布的更新as发布的apk
- 跟我学习javascript的浮点数精度
- R性能优化
- 带谷歌搜索功能的搜索镜像地址集
- SQL中的cast()函数