ngx_conf_handler

eagle sbc sbc19861004 at gmail.com
Fri Dec 31 14:18:33 MSK 2010


hi, nn hust:
   First, the 'cf->ctx' is a context variable. When in the DIRECT_CONF or
MAIN_CONF context, it point to 'void*[MAX_MODULE]'  array, while in the HTTP
context, it point to a 'ngx_http_conf_ctx_t', which is a structure with
there pointers each point to a 'void *[MAX_HTTP_MODULE]' array. Other CORE
module act the same as HTTP.
   I draw a diagram to make seems more clear :
[image: cf.jpg]

Every module structure has a 'index' member and 'ctx_index' member. 'index'
 indicate its own data position in the glocal 'void *' array, while
'ctx_index' indicate the context related. (According to what I understand,
The module type already choose which kind of array it will use, so the two
index is not necessary)

The different between DIRECT and MAIN is:  DIRECT means the memory is
already allocated, and the cmd's set function can directly use it, so pass
the pointer to the allocated memory; MAIN means the memory to be allocated
depend on the module, so pass the pointer to the pointer in the array.

cmd's 'conf' member indicate which context it will store its data. As in
HTTP, we can choose MAIN, SRV, LOC.

And I think the code is now easy to understand.
On Fri, Dec 31, 2010 at 4:46 PM, nn hust <nzjemail at gmail.com> wrote:

> I am confused by the multi dimensions pointer of the module configure
> structure
>
> if (cmd->type & NGX_DIRECT_CONF) {
>                 conf = ((void **) cf->ctx)[ngx_modules[i]->index];
>
>             } else if (cmd->type & NGX_MAIN_CONF) {
>                 conf = &(((void **) cf->ctx)[ngx_modules[i]->index]);
>
>             } else if (cf->ctx) {
>                 confp = *(void **) ((char *) cf->ctx + cmd->conf);
>
>                 if (confp) {
>                     conf = confp[ngx_modules[i]->ctx_index];
>                 }
>             }
>
>             rv = cmd->set(cf, cmd, conf);
>
>
>
>
> _______________________________________________
> nginx-devel mailing list
> nginx-devel at nginx.org
> http://nginx.org/mailman/listinfo/nginx-devel
>
>


-- 
自由是我生命之基石,尊重是我行为之准绳
也许我以千百种方式生活在这世上,但我坚守我人生之信仰
所以,我的朋友
请平视的看着我,带着你的微笑
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://nginx.org/pipermail/nginx-devel/attachments/20101231/5e528868/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: image/jpeg
Size: 42505 bytes
Desc: not available
URL: <http://nginx.org/pipermail/nginx-devel/attachments/20101231/5e528868/attachment-0001.jpe>


More information about the nginx-devel mailing list