nghttpx: Use accept if accept4 is not available

This commit is contained in:
Tatsuhiro Tsujikawa 2015-01-05 16:04:28 +09:00
parent fcf0ceeac6
commit 7dba426db4
1 changed files with 9 additions and 0 deletions

View File

@ -57,8 +57,12 @@ void AcceptHandler::accept_connection() {
sockaddr_union sockaddr; sockaddr_union sockaddr;
socklen_t addrlen = sizeof(sockaddr); socklen_t addrlen = sizeof(sockaddr);
#ifdef HAVE_ACCEPT4
auto cfd = auto cfd =
accept4(fd_, &sockaddr.sa, &addrlen, SOCK_NONBLOCK | SOCK_CLOEXEC); accept4(fd_, &sockaddr.sa, &addrlen, SOCK_NONBLOCK | SOCK_CLOEXEC);
#else // !HAVE_ACCEPT4
auto cfd = accept(fd_, &sockaddr.sa, &addrlen);
#endif // !HAVE_ACCEPT4
if (cfd == -1) { if (cfd == -1) {
switch (errno) { switch (errno) {
@ -79,6 +83,11 @@ void AcceptHandler::accept_connection() {
return; return;
} }
#ifndef HAVE_ACCEPT4
util::make_socket_nonblocking(cfd);
util::make_socket_closeonexec(cfd);
#endif // !HAVE_ACCEPT4
util::make_socket_nodelay(cfd); util::make_socket_nodelay(cfd);
conn_hnr_->handle_connection(cfd, &sockaddr.sa, addrlen); conn_hnr_->handle_connection(cfd, &sockaddr.sa, addrlen);