accept4 should be used in nginx( linux platform)

BoBo simohayha.bobo at gmail.com
Sun Nov 7 17:30:41 MSK 2010


Hi igor.

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.

void
ngx_event_accept(ngx_event_t *ev)
{
.....................................................................
/*     replace by s = accept4(lc->fd, (struct sockaddr *) sa, &socklen,
O_NONBLOCK); */
        s = accept(lc->fd, (struct sockaddr *) sa, &socklen);
..............................................................................................
            if (!(ngx_event_flags &
(NGX_USE_AIO_EVENT|NGX_USE_RTSIG_EVENT))) {
//if use accept4,this will removed.
                if (ngx_nonblocking(s) == -1) {
                    ngx_log_error(NGX_LOG_ALERT, ev->log, ngx_socket_errno,
                                  ngx_nonblocking_n " failed");
                    ngx_close_accepted_connection(c);
                    return;
                }
            }

thanks!



-- 
博观约取

豆瓣: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/20101107/88aff1c5/attachment.html>


More information about the nginx mailing list