hi, nn hust:<div> 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. </div>
<div> I draw a diagram to make seems more clear :</div><div><img src="cid:ii_12d3c1aca19fa422" alt="cf.jpg" title="cf.jpg" width="420" height="317"><br></div><div><br></div><div>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)</div>
<div><br></div><div>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.</div>
<div><br></div><div>cmd's 'conf' member indicate which context it will store its data. As in HTTP, we can choose MAIN, SRV, LOC. </div><div><br>And I think the code is now easy to understand.<br><div class="gmail_quote">
On Fri, Dec 31, 2010 at 4:46 PM, nn hust <span dir="ltr"><<a href="mailto:nzjemail@gmail.com">nzjemail@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
I am confused by the multi dimensions pointer of the module configure structure<div><br></div><div><div>if (cmd->type & NGX_DIRECT_CONF) {</div><div> conf = ((void **) cf->ctx)[ngx_modules[i]->index];</div>
<div><br></div><div> } else if (cmd->type & NGX_MAIN_CONF) {</div><div> conf = &(((void **) cf->ctx)[ngx_modules[i]->index]);</div><div><br></div><div> } else if (cf->ctx) {</div>
<div> confp = *(void **) ((char *) cf->ctx + cmd->conf);</div><div><br></div><div> if (confp) {</div><div> conf = confp[ngx_modules[i]->ctx_index];</div><div> }</div>
<div> }</div><div><br></div><div> rv = cmd->set(cf, cmd, conf);</div></div><div><br></div><div><br></div><div><br></div>
<br>_______________________________________________<br>
nginx-devel mailing list<br>
<a href="mailto:nginx-devel@nginx.org">nginx-devel@nginx.org</a><br>
<a href="http://nginx.org/mailman/listinfo/nginx-devel" target="_blank">http://nginx.org/mailman/listinfo/nginx-devel</a><br>
<br></blockquote></div><br><br clear="all"><br>-- <br><font color="#333333"><font face="'comic sans ms', sans-serif">自由是我生命之基石,尊重是我行为之准绳</font></font><div><font color="#333333"><font face="'comic sans ms', sans-serif">也许我以千百种方式生活在这世上,但我坚守我人生之信仰</font></font></div>
<div><font color="#333333"><font face="'comic sans ms', sans-serif">所以,我的朋友</font></font></div><div><font color="#333333"><font face="'comic sans ms', sans-serif">请平视的看着我,</font></font><span style="color:rgb(51, 51, 51)"><font face="'comic sans ms', sans-serif">带着你的微笑</font></span></div>
<div><font color="#333333"><br></font></div><br>
</div>