accept4 should be used in nginx( linux platform)
BoBo
simohayha.bobo at gmail.com
Sun Nov 7 19:33:04 MSK 2010
this patch suit for nginx-0.8.53, and i test in my arch linux. Thanks.
diff -Naur nginx-0.8.53/auto/os/features
nginx-0.8.53_accpet4/auto/os/features
--- nginx-0.8.53/auto/os/features 2010-07-05 21:49:16.000000000 +0800
+++ nginx-0.8.53_accpet4/auto/os/features 2010-11-08 00:20:28.126666705
+0800
@@ -352,3 +352,12 @@
fi
fi
fi
+
+ngx_feature="accept4()"
+ngx_feature_name="NGX_HAVE_ACCEPT4"
+ngx_feature_run=no
+ngx_feature_incs="#include <sys/socket.h>"
+ngx_feature_path=
+ngx_feature_libs=
+ngx_feature_test="accept4(0, NULL, NULL, SOCK_NONBLOCK)"
+. auto/feature
diff -Naur nginx-0.8.53/src/event/ngx_event_accept.c
nginx-0.8.53_accpet4/src/event/ngx_event_accept.c
--- nginx-0.8.53/src/event/ngx_event_accept.c 2009-11-02 03:29:49.000000000
+0800
+++ nginx-0.8.53_accpet4/src/event/ngx_event_accept.c 2010-11-08
00:27:21.630000043 +0800
@@ -45,8 +45,12 @@
do {
socklen = NGX_SOCKADDRLEN;
-
+
+#if (NGX_HAVE_ACCEPT4)
+ s = accept4(lc->fd, (struct sockaddr *) sa, &socklen,
SOCK_NONBLOCK);
+#else
s = accept(lc->fd, (struct sockaddr *) sa, &socklen);
+#endif
if (s == -1) {
err = ngx_socket_errno;
@@ -115,9 +119,9 @@
ngx_close_accepted_connection(c);
return;
}
-
+
+#ifndef NGX_HAVE_ACCEPT4
/* set a blocking mode for aio and non-blocking mode for others */
-
if (ngx_inherited_nonblocking) {
if (ngx_event_flags & NGX_USE_AIO_EVENT) {
if (ngx_blocking(s) == -1) {
@@ -138,7 +142,8 @@
}
}
}
-
+#endif
+
*log = ls->log;
c->recv = ngx_recv;
On Sun, Nov 7, 2010 at 11:12 PM, Maxim Dounin <mdounin at mdounin.ru> wrote:
> Hello!
>
> On Sun, Nov 07, 2010 at 10:30:41PM +0800, BoBo wrote:
>
> > The accept4() system call is available starting with Linux 2.6.28;
> support
> > in glibc is available starting with version 2.10. It can transport the
> > O_NONBLOCK flags in accept, and in nginx( in linux) after accept fd,
> > call fcntl(twice) set fd to O_NONBLOCK.
> >
> > And so if use accept4, this will be to save twice systemcall,
> > therefore i suggest
> > nginx(in linux platform) should use accept4.
>
> Yes, this make sense for Linux as it has no inheritance for
> O_NONBLOCK from listening socket. Care to provide patch?
>
> Just random implementation thoughs: probably emulating
> NGX_HAVE_INHERITED_NONBLOCK via accept4() is a right way to go.
>
> Maxim Dounin
>
> _______________________________________________
> nginx mailing list
> nginx at nginx.org
> http://nginx.org/mailman/listinfo/nginx
>
--
博观约取
豆瓣:www.douban.com/people/mustang/
blog: www.pagefault.info
twitter: www.twitter.com/minibobo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://nginx.org/pipermail/nginx/attachments/20101108/9659b92a/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: accept4.patch
Type: text/x-patch
Size: 1609 bytes
Desc: not available
URL: <http://nginx.org/pipermail/nginx/attachments/20101108/9659b92a/attachment.bin>
More information about the nginx
mailing list