accept4 should be used in nginx( linux platform)

Simon Liu simohayha.bobo at gmail.com
Sun Nov 7 20:55:31 MSK 2010


thank you!

On Mon, Nov 8, 2010 at 1:34 AM, Maxim Dounin <mdounin at mdounin.ru> wrote:

> Hello!
>
> On Mon, Nov 08, 2010 at 12:33:04AM +0800, BoBo wrote:
>
> > 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
>
> What happens when host has new glibc but old kernel?  I assume
> this test would succeed, but accept4() call will fail with ENOSYS.
>
> Another question to consider is what to do with packages built on
> host with accept4() but used on hosts without.  Probably some
> runtime fallback to usual accept() is needed.
>

thank you,I will test this situation.


> > 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;
> >          }
> > -
> > +
>
> Stray -/+ probably indicate some unrelated whitespace changes
> (though patch seems to be corrupted by MUA anyway).
>

this is my mistake.


> > +#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
>
> This part is wrong: with socket AIO sockets should be set to
> blocking mode.  The same code path as with
> ngx_inherited_nonblocking should be followed.
>
>
in linux platform , NGX_HAVE_INHERITED_NONBLOCK is 0, and in ngx_os_init:

#if (NGX_HAVE_INHERITED_NONBLOCK)
    ngx_inherited_nonblocking = 1;
#else
    ngx_inherited_nonblocking = 0;
#endif





-- 
博观约取

豆瓣: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/a0bf7512/attachment.html>


More information about the nginx mailing list