change: use ngx_int_t replace int.<br><br>Index: src/http/ngx_http_request_body.c<br>===================================================================<br>--- src/http/ngx_http_request_body.c (revision 4146)<br>+++ src/http/ngx_http_request_body.c (working copy)<br>
@@ -438,6 +438,7 @@<br> ngx_http_discard_request_body(ngx_http_request_t *r)<br> {<br> ssize_t size;<br>+ ngx_int_t rc;<br> ngx_event_t *rev;<br> <br> if (r != r->main || r->discard_body) {<br>
@@ -476,11 +477,13 @@<br> <br> r->read_event_handler = ngx_http_discarded_request_body_handler;<br> <br>- if (ngx_handle_read_event(rev, 0) != NGX_OK) {<br>- return NGX_HTTP_INTERNAL_SERVER_ERROR;<br>+ rc = ngx_http_read_discarded_request_body(r);<br>
+<br>+ if (rc == NGX_ERROR) {<br>+ return NGX_HTTP_CLIENT_CLOSED_REQUEST;<br> }<br> <br>- if (ngx_http_read_discarded_request_body(r) == NGX_OK) {<br>+ if (rc == NGX_OK) {<br> r->lingering_close = 0;<br>
<br> } else {<br>@@ -488,6 +491,10 @@<br> r->discard_body = 1;<br> }<br> <br>+ if (ngx_handle_read_event(rev, 0) != NGX_OK) {<br>+ return NGX_HTTP_INTERNAL_SERVER_ERROR;<br>+ }<br>+<br> return NGX_OK;<br>
}<br> <br>@@ -527,6 +534,11 @@<br> <br> rc = ngx_http_read_discarded_request_body(r);<br> <br>+ if (rc == NGX_ERROR) {<br>+ ngx_http_finalize_request(r, NGX_HTTP_CLIENT_CLOSED_REQUEST);<br>+ return;<br>
+ }<br>+<br> if (rc == NGX_OK) {<br> r->discard_body = 0;<br> r->lingering_close = 0;<br>@@ -583,19 +595,15 @@<br> <br> n = r->connection->recv(r->connection, buffer, size);<br>
<br>- if (n == NGX_ERROR) {<br>+ if (n == 0 || n == NGX_ERROR) {<br> r->connection->error = 1;<br>- return NGX_OK;<br>+ return NGX_ERROR;<br> }<br> <br> if (n == NGX_AGAIN) {<br>
return NGX_AGAIN;<br> }<br> <br>- if (n == 0) {<br>- return NGX_OK;<br>- }<br>-<br> r->headers_in.content_length_n -= n;<br> }<br> }<br><br><br><div class="gmail_quote">
On Tue, Sep 27, 2011 at 2:42 PM, Simon Liu <span dir="ltr"><<a href="mailto:simohayha.bobo@gmail.com">simohayha.bobo@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Sorry, I have mistake.<br><br>This is correct patch:<div class="im"><br><br>Index: src/http/ngx_http_request_body.c<br>===================================================================<br>--- src/http/ngx_http_request_body.c (revision 4146)<br>
+++ src/http/ngx_http_request_body.c (working copy)<br></div>@@ -437,6 +437,7 @@<br> ngx_int_t<br> ngx_http_discard_request_body(ngx_http_request_t *r)<br> {<br>+ int rc;<br> ssize_t size;<br> ngx_event_t *rev;<br>
<br>@@ -476,11 +477,13 @@<div class="im"><br> <br> r->read_event_handler = ngx_http_discarded_request_body_handler;<br> <br>- if (ngx_handle_read_event(rev, 0) != NGX_OK) {<br>- return NGX_HTTP_INTERNAL_SERVER_ERROR;<br>
+ rc = ngx_http_read_discarded_request_body(r);<br>+<br>+ if (rc == NGX_ERROR) {<br>+ return NGX_HTTP_CLIENT_CLOSED_REQUEST;<br> }<br> <br>- if (ngx_http_read_discarded_request_body(r) == NGX_OK) {<br>
+ if (rc == NGX_OK) {<br> r->lingering_close = 0;<br> <br> } else {<br></div>@@ -488,6 +491,10 @@<div class="im"><br> r->discard_body = 1;<br> }<br> <br>+ if (ngx_handle_read_event(rev, 0) != NGX_OK) {<br>
+ return NGX_HTTP_INTERNAL_SERVER_ERROR;<br>
+ }<br>+<br> return NGX_OK;<br> }<br> <br></div>@@ -527,6 +534,11 @@<div class="im"><br> <br> rc = ngx_http_read_discarded_request_body(r);<br> <br>+ if (rc == NGX_ERROR) {<br>+ ngx_http_finalize_request(r, NGX_HTTP_CLIENT_CLOSED_REQUEST);<br>
+ return;<br>+ }<br>+<br> if (rc == NGX_OK) {<br> r->discard_body = 0;<br> r->lingering_close = 0;<br></div>@@ -583,19 +595,15 @@<div class="im"><br> <br> n = r->connection->recv(r->connection, buffer, size);<br>
<br>- if (n == NGX_ERROR) {<br>+ if (n == 0 || n == NGX_ERROR) {<br> r->connection->error = 1;<br>- return NGX_OK;<br>+ return NGX_ERROR;<br> }<br> <br> if (n == NGX_AGAIN) {<br>
return NGX_AGAIN;<br> }<br> <br>- if (n == 0) {<br>- return NGX_OK;<br>- }<br>-<br> r->headers_in.content_length_n -= n;<br> }<br> }<br><br><br><br></div><div>
<div></div><div class="h5"><div class="gmail_quote">
On Tue, Sep 27, 2011 at 2:33 PM, Simon Liu <span dir="ltr"><<a href="mailto:simohayha.bobo@gmail.com" target="_blank">simohayha.bobo@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Thanks Maxim.<br><br>This is new patch, I think this may be better.<br><br>I think ngx_handle_read_event can't be avoid(in ngx_http_discard_request_body), because it doesn't known <span style="color:rgb(0, 0, 0);font-family:'Microsoft YaHei';font-size:13px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:-webkit-auto;text-indent:0px;text-transform:none;white-space:nowrap;word-spacing:0px">whether or not need to add read event</span> in ngx_http_discard_request_body. So there need ngx_handle_read_event to <span style="color:rgb(0, 0, 0);font-family:'Microsoft YaHei';font-size:13px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:-webkit-auto;text-indent:0px;text-transform:none;white-space:nowrap;word-spacing:0px">judge</span>.<div>
<br>
<br>Index: src/http/ngx_http_request_body.c<br>===================================================================<br>--- src/http/ngx_http_request_body.c (revision 4146)<br>+++ src/http/ngx_http_request_body.c (working copy)<br>
</div>
@@ -476,11 +476,13 @@<div><br> <br> r->read_event_handler = ngx_http_discarded_request_body_handler;<br> <br>- if (ngx_handle_read_event(rev, 0) != NGX_OK) {<br>- return NGX_HTTP_INTERNAL_SERVER_ERROR;<br>
</div>+ rc = ngx_http_read_discarded_request_body(r);<br>
+<br>+ if (rc == NGX_ERROR) {<br>+ return NGX_HTTP_CLIENT_CLOSED_REQUEST;<br> }<br> <br>- if (ngx_http_read_discarded_request_body(r) == NGX_OK) {<br>+ if (rc == NGX_OK) {<br> r->lingering_close = 0;<br>
<br> } else {<br>@@ -488,6 +490,10 @@<div><br> r->discard_body = 1;<br> }<br> <br>+ if (ngx_handle_read_event(rev, 0) != NGX_OK) {<br>+ return NGX_HTTP_INTERNAL_SERVER_ERROR;<br>+ }<br>
+<br> return NGX_OK;<br>
}<br> <br></div>@@ -527,6 +533,11 @@<br> <br> rc = ngx_http_read_discarded_request_body(r);<br> <br>+ if (rc == NGX_ERROR) {<br>+ ngx_http_finalize_request(r, NGX_HTTP_CLIENT_CLOSED_REQUEST);<br>+ return;<br>
+ }<br>+<br> if (rc == NGX_OK) {<br> r->discard_body = 0;<br> r->lingering_close = 0;<br>@@ -583,19 +594,15 @@<br> <br> n = r->connection->recv(r->connection, buffer, size);<br>
<br>- if (n == NGX_ERROR) {<br>+ if (n == 0 || n == NGX_ERROR) {<br> r->connection->error = 1;<br>- return NGX_OK;<br>+ return NGX_ERROR;<br> }<br> <br> if (n == NGX_AGAIN) {<br>
return NGX_AGAIN;<br> }<br> <br>- if (n == 0) {<br>- return NGX_OK;<br>- }<br>-<br> r->headers_in.content_length_n -= n;<div><div></div><div><br> }<br>
}<br><br><br><div class="gmail_quote">
On Mon, Sep 26, 2011 at 11:50 PM, Maxim Dounin <span dir="ltr"><<a href="mailto:mdounin@mdounin.ru" target="_blank">mdounin@mdounin.ru</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hello!<br>
<div><br>
On Mon, Sep 26, 2011 at 11:34:42PM +0800, Simon Liu wrote:<br>
<br>
> Thanks .<br>
><br>
> This is patch:<br>
><br>
> Index: src/http/ngx_http_request_body.c<br>
> ===================================================================<br>
> --- src/http/ngx_http_request_body.c (revision 4146)<br>
> +++ src/http/ngx_http_request_body.c (working copy)<br>
> @@ -476,10 +476,6 @@<br>
><br>
> r->read_event_handler = ngx_http_discarded_request_body_handler;<br>
><br>
> - if (ngx_handle_read_event(rev, 0) != NGX_OK) {<br>
> - return NGX_HTTP_INTERNAL_SERVER_ERROR;<br>
> - }<br>
> -<br>
> if (ngx_http_read_discarded_request_body(r) == NGX_OK) {<br>
> r->lingering_close = 0;<br>
><br>
> @@ -488,6 +484,10 @@<br>
> r->discard_body = 1;<br>
> }<br>
><br>
> + if (ngx_handle_read_event(rev, 0) != NGX_OK) {<br>
> + return NGX_HTTP_INTERNAL_SERVER_ERROR;<br>
> + }<br>
> +<br>
> return NGX_OK;<br>
> }<br>
<br>
</div>It's better to avoid ngx_handle_read_event() altogether in<br>
case ngx_http_read_discarded_request_body() returns NGX_OK (i.e.<br>
everything is read, no futher actions required).<br>
<br>
It would be a bit more readable and slightly more optimal.<br>
<font color="#888888"><br>
Maxim Dounin<br>
</font><div><div></div><div><br>
><br>
><br>
> On Mon, Sep 26, 2011 at 11:08 PM, Maxim Dounin <<a href="mailto:mdounin@mdounin.ru" target="_blank">mdounin@mdounin.ru</a>> wrote:<br>
><br>
> > Hello!<br>
> ><br>
> > On Mon, Sep 26, 2011 at 10:42:20PM +0800, Simon Liu wrote:<br>
> ><br>
> > > Hi all.<br>
> > ><br>
> > > My nginx version is svn trunk.<br>
> > ><br>
> > > Nginx will call ngx_handle_read_event, and then<br>
> > > call ngx_http_read_discarded_request_body In<br>
> > ngx_http_discard_request_body .<br>
> > > So this will cause client's body read incomplete data , because<br>
> > > ngx_handle_read_event<br>
> > > may delete read event when use level event.<br>
> > ><br>
> > > ngx_handle_read_event:<br>
> > ><br>
> > > else if (ngx_event_flags & NGX_USE_LEVEL_EVENT) {<br>
> > ><br>
> > > /* select, poll, /dev/poll */<br>
> > > .................................................................<br>
> > ><br>
> > > if (rev->active && (rev->ready || (flags & NGX_CLOSE_EVENT))) {<br>
> > > if (ngx_del_event(rev, NGX_READ_EVENT, NGX_LEVEL_EVENT |<br>
> > flags)<br>
> > > == NGX_ERROR)<br>
> > > {<br>
> > > return NGX_ERROR;<br>
> > > }<br>
> > ><br>
> > > return NGX_OK;<br>
> > > }<br>
> > ><br>
> > ><br>
> > > ngx_http_discard_request_body:<br>
> > ><br>
> > > r->read_event_handler = ngx_http_discarded_request_body_handler;<br>
> > ><br>
> > > if (ngx_handle_read_event(rev, 0) != NGX_OK) {<br>
> > > return NGX_HTTP_INTERNAL_SERVER_ERROR;<br>
> > > }<br>
> > ><br>
> > > if (ngx_http_read_discarded_request_body(r) == NGX_OK) {<br>
> > > r->lingering_close = 0;<br>
> > ><br>
> > ><br>
> > > thanks!<br>
> ><br>
> > Ack, ngx_handle_read_event() should be after<br>
> > ngx_http_read_discarded_request_body() call, like it's done in<br>
> > ngx_http_discarded_request_body_handler().<br>
> ><br>
> > Care to provide patch?<br>
> ><br>
> > Maxim Dounin<br>
> ><br>
> > _______________________________________________<br>
> > nginx-devel mailing list<br>
> > <a href="mailto:nginx-devel@nginx.org" target="_blank">nginx-devel@nginx.org</a><br>
> > <a href="http://mailman.nginx.org/mailman/listinfo/nginx-devel" target="_blank">http://mailman.nginx.org/mailman/listinfo/nginx-devel</a><br>
> ><br>
<br>
> Index: src/http/ngx_http_request_body.c<br>
> ===================================================================<br>
> --- src/http/ngx_http_request_body.c (revision 4146)<br>
> +++ src/http/ngx_http_request_body.c (working copy)<br>
> @@ -476,10 +476,6 @@<br>
><br>
> r->read_event_handler = ngx_http_discarded_request_body_handler;<br>
><br>
> - if (ngx_handle_read_event(rev, 0) != NGX_OK) {<br>
> - return NGX_HTTP_INTERNAL_SERVER_ERROR;<br>
> - }<br>
> -<br>
> if (ngx_http_read_discarded_request_body(r) == NGX_OK) {<br>
> r->lingering_close = 0;<br>
><br>
> @@ -488,6 +484,10 @@<br>
> r->discard_body = 1;<br>
> }<br>
><br>
> + if (ngx_handle_read_event(rev, 0) != NGX_OK) {<br>
> + return NGX_HTTP_INTERNAL_SERVER_ERROR;<br>
> + }<br>
> +<br>
> return NGX_OK;<br>
> }<br>
><br>
<br>
> _______________________________________________<br>
> nginx-devel mailing list<br>
> <a href="mailto:nginx-devel@nginx.org" target="_blank">nginx-devel@nginx.org</a><br>
> <a href="http://mailman.nginx.org/mailman/listinfo/nginx-devel" target="_blank">http://mailman.nginx.org/mailman/listinfo/nginx-devel</a><br>
<br>
_______________________________________________<br>
nginx-devel mailing list<br>
<a href="mailto:nginx-devel@nginx.org" target="_blank">nginx-devel@nginx.org</a><br>
<a href="http://mailman.nginx.org/mailman/listinfo/nginx-devel" target="_blank">http://mailman.nginx.org/mailman/listinfo/nginx-devel</a><br>
</div></div></blockquote></div><br><br clear="all"><br></div></div>-- <br>douban:<a href="http://www.douban.com/people/mustang/" target="_blank">www.douban.com/people/mustang/</a><div><br><br>blog: <a href="http://www.pagefault.info" target="_blank">www.pagefault.info</a><br>
<br>twitter: <a href="http://www.twitter.com/minibobo" target="_blank">www.twitter.com/minibobo</a><br><br></div>weibo: <a href="http://www.weibo.com/diaoliang" target="_blank">www.weibo.com/diaoliang</a><br><br>
</blockquote></div><br><br clear="all"><br></div></div><font color="#888888">-- <br>博观约取<br><br>豆瓣:<a href="http://www.douban.com/people/mustang/" target="_blank">www.douban.com/people/mustang/</a></font><div class="im">
<br><br>blog: <a href="http://www.pagefault.info" target="_blank">www.pagefault.info</a><br>
<br>twitter: <a href="http://www.twitter.com/minibobo" target="_blank">www.twitter.com/minibobo</a><br><br></div><div><div></div><div class="h5">sina 微博: <a href="http://www.weibo.com/diaoliang" target="_blank">www.weibo.com/diaoliang</a><br>
<br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br><br>douban:<a href="http://www.douban.com/people/mustang/" target="_blank">www.douban.com/people/mustang/</a><br><br>blog: <a href="http://www.pagefault.info" target="_blank">www.pagefault.info</a><br>
<br>twitter: <a href="http://www.twitter.com/minibobo" target="_blank">www.twitter.com/minibobo</a><br><br>sina: <a href="http://www.weibo.com/diaoliang" target="_blank">www.weibo.com/diaoliang</a><br><br>