Yes,it help me understand the code more clearly<br><br><div class="gmail_quote">在 2010年12月31日 下午7:18,eagle sbc <span dir="ltr">&lt;<a href="mailto:sbc19861004@gmail.com">sbc19861004@gmail.com</a>&gt;</span>写道:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
hi, nn hust:<div>&nbsp;&nbsp; First, the &#39;cf-&gt;ctx&#39; is a context variable. When in the DIRECT_CONF or MAIN_CONF context, it point to &#39;void*[MAX_MODULE]&#39; &nbsp;array, while in the HTTP context, it point to a &#39;ngx_http_conf_ctx_t&#39;, which is a structure with there pointers each point to a &#39;void *[MAX_HTTP_MODULE]&#39; array. Other CORE module act the same as HTTP.&nbsp;</div>

<div>&nbsp;&nbsp; I draw a diagram to make seems more clear :</div><div><img src="?ui=2&amp;ik=cef46da814&amp;view=att&amp;th=12d3c3f2fcd7206c&amp;attid=0.0.1&amp;disp=emb&amp;realattid=ii_12d3c1aca19fa422&amp;zw" alt="cf.jpg" title="cf.jpg" width="420" height="317"><br>
</div><div><br></div><div>Every module structure has a &#39;index&#39; member and &#39;ctx_index&#39; member. &#39;index&#39; &nbsp;indicate its own data position in the glocal &#39;void *&#39; array, while &#39;ctx_index&#39; 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: &nbsp;DIRECT means the memory is already allocated, and the cmd&#39;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&#39;s &#39;conf&#39; member indicate which context it will store its data. As in HTTP, we can choose MAIN, SRV, LOC. &nbsp;</div><div><br>And I think the code is now easy to understand.<br><div class="gmail_quote">
<div><div></div><div class="h5">
On Fri, Dec 31, 2010 at 4:46 PM, nn hust <span dir="ltr">&lt;<a href="mailto:nzjemail@gmail.com" target="_blank">nzjemail@gmail.com</a>&gt;</span> wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div><div></div><div class="h5">
I am confused by the multi dimensions pointer of the module configure structure<div><br></div><div><div>if (cmd-&gt;type &amp; NGX_DIRECT_CONF) {</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;conf = ((void **) cf-&gt;ctx)[ngx_modules[i]-&gt;index];</div>


<div><br></div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;} else if (cmd-&gt;type &amp; NGX_MAIN_CONF) {</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;conf = &amp;(((void **) cf-&gt;ctx)[ngx_modules[i]-&gt;index]);</div><div><br></div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;} else if (cf-&gt;ctx) {</div>


<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;confp = *(void **) ((char *) cf-&gt;ctx + cmd-&gt;conf);</div><div><br></div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (confp) {</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;conf = confp[ngx_modules[i]-&gt;ctx_index];</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}</div>


<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}</div><div><br></div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;rv = cmd-&gt;set(cf, cmd, conf);</div></div><div><br></div><div><br></div><div><br></div>
<br></div></div>_______________________________________________<br>
nginx-devel mailing list<br>
<a href="mailto:nginx-devel@nginx.org" target="_blank">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="&#39;comic sans ms&#39;, sans-serif">自由是我生命之基石,尊重是我行为之准绳</font></font><div><font color="#333333"><font face="&#39;comic sans ms&#39;, sans-serif">也许我以千百种方式生活在这世上,但我坚守我人生之信仰</font></font></div>

<div><font color="#333333"><font face="&#39;comic sans ms&#39;, sans-serif">所以,我的朋友</font></font></div><div><font color="#333333"><font face="&#39;comic sans ms&#39;, sans-serif">请平视的看着我,</font></font><span style="color:rgb(51, 51, 51)"><font face="&#39;comic sans ms&#39;, sans-serif">带着你的微笑</font></span></div>

<div><font color="#333333"><br></font></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>