diff options
Diffstat (limited to '')
-rw-r--r-- | src/nxt_listen_socket.c | 8 | ||||
-rw-r--r-- | src/nxt_router.c | 7 | ||||
-rw-r--r-- | src/nxt_socket.c | 21 | ||||
-rw-r--r-- | src/nxt_socket.h | 2 |
4 files changed, 25 insertions, 13 deletions
diff --git a/src/nxt_listen_socket.c b/src/nxt_listen_socket.c index 041c5384..6fb265ea 100644 --- a/src/nxt_listen_socket.c +++ b/src/nxt_listen_socket.c @@ -78,16 +78,10 @@ nxt_listen_socket_create(nxt_task_t *task, nxt_listen_socket_t *ls, #endif -#ifdef TCP_DEFER_ACCEPT - if (ls->read_after_accept) { - /* Defer accept() maximum at 1 second. */ - /* Ignore possible error. TODO: why? */ - (void) nxt_socket_setsockopt(task, s, IPPROTO_TCP, TCP_DEFER_ACCEPT, 1); + nxt_socket_defer_accept(task, s, sa); } -#endif - switch (nxt_socket_bind(task, s, sa, bind_test)) { case NXT_OK: diff --git a/src/nxt_router.c b/src/nxt_router.c index 8ddddb46..eadc3498 100644 --- a/src/nxt_router.c +++ b/src/nxt_router.c @@ -1053,12 +1053,7 @@ nxt_router_listen_socket_ready(nxt_task_t *task, nxt_port_recv_msg_t *msg, goto fail; } -#ifdef TCP_DEFER_ACCEPT - - /* Defer Linux accept() up to for 1 second. */ - (void) nxt_socket_setsockopt(task, s, IPPROTO_TCP, TCP_DEFER_ACCEPT, 1); - -#endif + nxt_socket_defer_accept(task, s, rpc->socket_conf->sockaddr); ret = nxt_listen_socket(task, s, NXT_LISTEN_BACKLOG); if (nxt_slow_path(ret != NXT_OK)) { diff --git a/src/nxt_socket.c b/src/nxt_socket.c index c174081c..b9bbac46 100644 --- a/src/nxt_socket.c +++ b/src/nxt_socket.c @@ -63,6 +63,27 @@ nxt_socket_close(nxt_task_t *task, nxt_socket_t s) } +void +nxt_socket_defer_accept(nxt_task_t *task, nxt_socket_t s, nxt_sockaddr_t *sa) +{ +#if (NXT_HAVE_UNIX_DOMAIN) + + if (sa->u.sockaddr.sa_family == AF_UNIX) { + /* Deferred accept() is not supported on AF_UNIX sockets. */ + return; + } + +#endif + +#ifdef TCP_DEFER_ACCEPT + + /* Defer Linux accept() up to for 1 second. */ + (void) nxt_socket_setsockopt(task, s, IPPROTO_TCP, TCP_DEFER_ACCEPT, 1); + +#endif +} + + nxt_int_t nxt_socket_getsockopt(nxt_task_t *task, nxt_socket_t s, nxt_uint_t level, nxt_uint_t sockopt) diff --git a/src/nxt_socket.h b/src/nxt_socket.h index ec9d058c..42ef6c53 100644 --- a/src/nxt_socket.h +++ b/src/nxt_socket.h @@ -94,6 +94,8 @@ typedef union { NXT_EXPORT nxt_socket_t nxt_socket_create(nxt_task_t *task, nxt_uint_t family, nxt_uint_t type, nxt_uint_t protocol, nxt_uint_t flags); NXT_EXPORT void nxt_socket_close(nxt_task_t *task, nxt_socket_t s); +NXT_EXPORT void nxt_socket_defer_accept(nxt_task_t *task, nxt_socket_t s, + nxt_sockaddr_t *sa); NXT_EXPORT nxt_int_t nxt_socket_getsockopt(nxt_task_t *task, nxt_socket_t s, nxt_uint_t level, nxt_uint_t sockopt); NXT_EXPORT nxt_int_t nxt_socket_setsockopt(nxt_task_t *task, nxt_socket_t s, |