关于nginx 源码的问题:

73 views
Skip to first unread message

maeleven

unread,
Mar 7, 2013, 3:39:37 AM3/7/13
to open...@googlegroups.com
#if defined nginx_version && nginx_version >= 8011
    r->main->count++;
#endif
这句话中  r->main->count++;有什么作用?具体是如何实现的呢?求教,希望能举例说明,谢谢大家了

smallfish

unread,
Mar 7, 2013, 3:52:52 AM3/7/13
to open...@googlegroups.com
增加请求时候的引用计数,在释放资源(函数:ngx_http_finalize_request)时候使用。
ngx_http_finalize_request 函数位于 src/http/ngx_http_request.c:1937。
在好多模块里都会有这样的调用示例哦,比如:ngx_lua、drizzle-module等等。
--


2013/3/7 maeleven <maxia...@tydtech.com>
--
--
邮件自: 列表“openresty”,专用于技术讨论!
发言: 请发邮件到 open...@googlegroups.com
退订: 请发邮件至 openresty+...@googlegroups.com
详情: http://groups.google.com/group/openresty
官网: http://openresty.org/
仓库: https://github.com/agentzh/ngx_openresty
建议: 提问的智慧 http://wiki.woodpecker.org.cn/moin/AskForHelp
教程: http://agentzh.org/misc/nginx/agentzh-nginx-tutorials-zhcn.html
 
---
您收到此邮件是因为您订阅了 Google 网上论坛的“openresty”论坛。
要退订此论坛并停止接收此论坛的电子邮件,请发送电子邮件到 openresty+...@googlegroups.com
要查看更多选项,请访问 https://groups.google.com/groups/opt_out。
 
 

smallfish

unread,
Mar 7, 2013, 3:54:08 AM3/7/13
to open...@googlegroups.com
哦,说错了不是释放资源。是在结束请求或者连接时候用。可以看到有很多类似这样的调用:
ngx_http_finalize_request(r, NGX_HTTP_REQUEST_TIME_OUT);
--


2013/3/7 smallfish <smallf...@gmail.com>

马晓童

unread,
Mar 7, 2013, 4:11:33 AM3/7/13
to open...@googlegroups.com

那这种引用计数对于释放资源有 什么好处呢?可以提点一下吗?谢谢

 

发件人: open...@googlegroups.com [mailto:open...@googlegroups.com] 代表 smallfish
发送时间: 201337 16:53
收件人: open...@googlegroups.com
主题: Re: [openresty] 关于nginx 源码的问题:

您收到此邮件是因为您订阅了 Google 网上论坛“openresty”中的主题。
要退订此主题,请访问 https://groups.google.com/d/topic/openresty/1ZdZRk7Ycc8/unsubscribe?hl=zh-CN
要退订此论坛及其所有主题,请发送电子邮件到 openresty+...@googlegroups.com
要查看更多选项,请访问 https://groups.google.com/groups/opt_out
 
 

pengqi

unread,
Mar 7, 2013, 4:12:09 AM3/7/13
to openresty
恩,简单的说count就是请求的引用计数,某些情况一下需要hold住请求时就将其count加1。

理解它的话需要看一下请求的处理过程,ngx_http_core_run_phases->phase-handler->ngx_http_finalize_request->ngx_http_finalize_connection->ngx_http_close_request,一般在某个phase-handler如果需求hold住请求(比如需要等待某个事件发生),一般可以将count加1,并返回合适的返回值,进入ngx_http_finalize_request,然后会调用ngx_http_close_request,此函数会将count--,并检查如果count等于0则释放该请求及连接,如果大于0则说明该请求还为处理完,则直接返回,等到下一次事件处理。


2013/3/7 smallfish <smallf...@gmail.com>



--
Jinglong
Software Engineer
Server Platforms Team at Taobao

马晓童

unread,
Mar 7, 2013, 4:14:00 AM3/7/13
to open...@googlegroups.com

它是如何操作的呢?可以给简单介绍下吗?

 

发件人: open...@googlegroups.com [mailto:open...@googlegroups.com] 代表 smallfish

发送时间: 201337 16:54

收件人: open...@googlegroups.com
主题: Re: [openresty] 关于nginx 源码的问题:

 

哦,说错了不是释放资源。是在结束请求或者连接时候用。可以看到有很多类似这样的调用:

您收到此邮件是因为您订阅了 Google 网上论坛“openresty”中的主题。
要退订此主题,请访问 https://groups.google.com/d/topic/openresty/1ZdZRk7Ycc8/unsubscribe?hl=zh-CN

要退订此论坛及其所有主题,请发送电子邮件到 openresty+...@googlegroups.com
要查看更多选项,请访问 https://groups.google.com/groups/opt_out
 
 

马晓童

unread,
Mar 7, 2013, 5:07:29 AM3/7/13
to open...@googlegroups.com

嗯,了解了,我再去调查看看,十分感谢~

 

发件人: open...@googlegroups.com [mailto:open...@googlegroups.com] 代表 pengqi
发送时间: 201337 17:12
收件人: openresty

主题: Re: [openresty] 关于nginx 源码的问题:

 

恩,简单的说count就是请求的引用计数,某些情况一下需要hold住请求时就将其count1

您收到此邮件是因为您订阅了 Google 网上论坛“openresty”中的主题。
要退订此主题,请访问 https://groups.google.com/d/topic/openresty/1ZdZRk7Ycc8/unsubscribe?hl=zh-CN

要退订此论坛及其所有主题,请发送电子邮件到 openresty+...@googlegroups.com
要查看更多选项,请访问 https://groups.google.com/groups/opt_out
 
 

马晓童

unread,
Mar 8, 2013, 4:11:43 AM3/8/13
to open...@googlegroups.com

谁能给我解释一下nginx 处理post请求的具体过程,最好是关键简单代码加解释的那种的,比如以upload模块或者其他模块代码为例。
谢谢

 

发件人: open...@googlegroups.com [mailto:open...@googlegroups.com] 代表 马晓童
发送时间: 201337 18:07
收件人: open...@googlegroups.com
主题: 答复: [openresty] 关于nginx 源码的问题:

pengqi

unread,
Mar 8, 2013, 4:16:16 AM3/8/13
to openresty
hi,

可以看一下我之前写的,nginx读取请求体 (http://tengine.taobao.org/book/chapter_12.html#id5
Reply all
Reply to author
Forward
0 new messages