nghttpx: Use TCP_DEFER_ACCEPT if available

This commit is contained in:
Tatsuhiro Tsujikawa 2015-01-29 21:14:44 +09:00
parent d1a4002b22
commit 00555dc7bb
1 changed files with 10 additions and 0 deletions

View File

@ -31,6 +31,7 @@
#include <netdb.h> #include <netdb.h>
#include <signal.h> #include <signal.h>
#include <netinet/in.h> #include <netinet/in.h>
#include <netinet/tcp.h>
#include <arpa/inet.h> #include <arpa/inet.h>
#include <unistd.h> #include <unistd.h>
#include <getopt.h> #include <getopt.h>
@ -218,6 +219,15 @@ std::unique_ptr<AcceptHandler> create_acceptor(ConnectionHandler *handler,
} }
} }
#endif // IPV6_V6ONLY #endif // IPV6_V6ONLY
#ifdef TCP_DEFER_ACCEPT
val = 3;
if (setsockopt(fd, IPPROTO_TCP, TCP_DEFER_ACCEPT, &val,
static_cast<socklen_t>(sizeof(val))) == -1) {
LOG(WARN) << "Failed to set TCP_DEFER_ACCEPT option to listener socket";
}
#endif // TCP_DEFER_ACCEPT
if (bind(fd, rp->ai_addr, rp->ai_addrlen) == 0 && if (bind(fd, rp->ai_addr, rp->ai_addrlen) == 0 &&
listen(fd, get_config()->backlog) == 0) { listen(fd, get_config()->backlog) == 0) {
break; break;