this  patch suit for nginx-0.8.53, and i test in my arch linux. Thanks.<div><br></div><div><div>diff -Naur nginx-0.8.53/auto/os/features nginx-0.8.53_accpet4/auto/os/features</div><div>--- nginx-0.8.53/auto/os/features<span class="Apple-tab-span" style="white-space:pre"> </span>2010-07-05 21:49:16.000000000 +0800</div>
<div>+++ nginx-0.8.53_accpet4/auto/os/features<span class="Apple-tab-span" style="white-space:pre"> </span>2010-11-08 00:20:28.126666705 +0800</div><div>@@ -352,3 +352,12 @@</div><div>Â Â Â Â Â fi</div><div>Â Â Â fi</div><div>
 fi</div><div>+</div><div>+ngx_feature="accept4()"</div><div>+ngx_feature_name="NGX_HAVE_ACCEPT4"</div><div>+ngx_feature_run=no</div><div>+ngx_feature_incs="#include <sys/socket.h>"</div>
<div>+ngx_feature_path=</div><div>+ngx_feature_libs=</div><div>+ngx_feature_test="accept4(0, NULL, NULL, SOCK_NONBLOCK)"</div><div>+. auto/feature</div><div>diff -Naur nginx-0.8.53/src/event/ngx_event_accept.c nginx-0.8.53_accpet4/src/event/ngx_event_accept.c</div>
<div>--- nginx-0.8.53/src/event/ngx_event_accept.c<span class="Apple-tab-span" style="white-space:pre"> </span>2009-11-02 03:29:49.000000000 +0800</div><div>+++ nginx-0.8.53_accpet4/src/event/ngx_event_accept.c<span class="Apple-tab-span" style="white-space:pre"> </span>2010-11-08 00:27:21.630000043 +0800</div>
<div>@@ -45,8 +45,12 @@</div><div>Â </div><div>Â Â Â do {</div><div>Â Â Â Â Â socklen = NGX_SOCKADDRLEN;</div><div>-</div><div>+ Â Â Â Â </div><div>+#if (NGX_HAVE_ACCEPT4)</div><div>+ Â Â Â Â s = accept4(lc->fd, (struct sockaddr *) sa, &socklen, SOCK_NONBLOCK);</div>
<div>+#else</div><div>Â Â Â Â Â s = accept(lc->fd, (struct sockaddr *) sa, &socklen);</div><div>+#endif</div><div>Â </div><div>Â Â Â Â Â if (s == -1) {</div><div>Â Â Â Â Â Â Â err = ngx_socket_errno;</div><div>@@ -115,9 +119,9 @@</div>
<div>Â Â Â Â Â Â Â ngx_close_accepted_connection(c);</div><div>Â Â Â Â Â Â Â return;</div><div>Â Â Â Â Â }</div><div>-</div><div>+ Â Â Â Â </div><div>+#ifndef NGX_HAVE_ACCEPT4</div><div>Â Â Â Â Â /* set a blocking mode for aio and non-blocking mode for others */</div>
<div>-</div><div>Â Â Â Â Â if (ngx_inherited_nonblocking) {</div><div>Â Â Â Â Â Â Â if (ngx_event_flags & NGX_USE_AIO_EVENT) {</div><div>Â Â Â Â Â Â Â Â Â if (ngx_blocking(s) == -1) {</div><div>@@ -138,7 +142,8 @@</div>
<div>
         }</div><div>       }</div><div>     }</div><div>-</div><div>+#endif</div><div>+     </div><div>     *log = ls->log;</div><div> </div><div>     c->recv = ngx_recv;</div><div><br>
</div><br><div class="gmail_quote">On Sun, Nov 7, 2010 at 11:12 PM, Maxim Dounin <span dir="ltr"><<a href="mailto:mdounin@mdounin.ru">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 class="im"><br>
On Sun, Nov 07, 2010 at 10:30:41PM +0800, BoBo wrote:<br>
<br>
> The accept4() system call is available starting with Linux 2.6.28; support<br>
> in glibc is available starting with version 2.10. Â It can transport the<br>
> O_NONBLOCK flags in accept, and in nginx( in linux) after accept fd,<br>
> call fcntl(twice) set fd to O_NONBLOCK.<br>
><br>
> And so if use accept4, this will be to save twice systemcall,<br>
> therefore i suggest<br>
> nginx(in  linux platform) should use accept4.<br>
<br>
</div>Yes, this make sense for Linux as it has no inheritance for<br>
O_NONBLOCK from listening socket. Â Care to provide patch?<br>
<br>
Just random implementation thoughs: probably emulating<br>
NGX_HAVE_INHERITED_NONBLOCK via accept4() is a right way to go.<br>
<br>
Maxim Dounin<br>
<br>
_______________________________________________<br>
nginx mailing list<br>
<a href="mailto:nginx@nginx.org">nginx@nginx.org</a><br>
<a href="http://nginx.org/mailman/listinfo/nginx" target="_blank">http://nginx.org/mailman/listinfo/nginx</a><br>
</blockquote></div><br><br clear="all"><br>-- <br>åšè§‚约å–<br><br>豆瓣:<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>
</div>