fallback to accept() if accept4() is not implemented,

the issue has been introduced in r3787
This commit is contained in:
Igor Sysoev 2010-12-02 10:05:41 +00:00
parent ae32ef647d
commit c14dd25380

View file

@ -26,6 +26,9 @@ ngx_event_accept(ngx_event_t *ev)
ngx_connection_t *c, *lc;
ngx_event_conf_t *ecf;
u_char sa[NGX_SOCKADDRLEN];
#if (NGX_HAVE_ACCEPT4)
static ngx_uint_t use_accept4 = 1;
#endif
ecf = ngx_event_get_conf(ngx_cycle->conf_ctx, ngx_event_core_module);
@ -47,7 +50,12 @@ ngx_event_accept(ngx_event_t *ev)
socklen = NGX_SOCKADDRLEN;
#if (NGX_HAVE_ACCEPT4)
s = accept4(lc->fd, (struct sockaddr *) sa, &socklen, SOCK_NONBLOCK);
if (use_accept4) {
s = accept4(lc->fd, (struct sockaddr *) sa, &socklen,
SOCK_NONBLOCK);
} else {
s = accept(lc->fd, (struct sockaddr *) sa, &socklen);
}
#else
s = accept(lc->fd, (struct sockaddr *) sa, &socklen);
#endif
@ -63,7 +71,18 @@ ngx_event_accept(ngx_event_t *ev)
ngx_log_error((ngx_uint_t) ((err == NGX_ECONNABORTED) ?
NGX_LOG_ERR : NGX_LOG_ALERT),
ev->log, err, "accept() failed");
ev->log, err,
#if !(NGX_HAVE_ACCEPT4)
"accept() failed");
#else
use_accept4 ? "accept4() failed" : "accept() failed");
if (use_accept4 && err == NGX_ENOSYS) {
use_accept4 = 0;
ngx_inherited_nonblocking = 0;
continue;
}
#endif
if (err == NGX_ECONNABORTED) {
if (ngx_event_flags & NGX_USE_KQUEUE_EVENT) {