accept4 should be used in nginx( linux platform)
Maxim Dounin
mdounin at mdounin.ru
Sun Nov 7 21:07:02 MSK 2010
Hello!
On Mon, Nov 08, 2010 at 01:55:31AM +0800, Simon Liu wrote:
[...]
> > > +#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
Yes. And the suggestion is to emulate NGX_HAVE_INHERITED_NONBLOCK
with accept4(): inherited nonblock means that socket returned by
accept() already has O_NONBLOCK set, so we don't need to set it
(but may want to clear if we need blocking socket for some reason,
e.g. for socket AIO). With accept4() we basically get the same
situation.
Maxim Dounin
More information about the nginx
mailing list