From 263c2efd960057f1cfafd40fce338605c39b0ad4 Mon Sep 17 00:00:00 2001 From: Daniel Vassdal Date: Wed, 22 May 2013 12:48:58 -0700 Subject: Added option for using TCP_DEFER_ACCEPT. Prevents the connection from being handed over to the daemon before data is ready from the client. --- src/listensocket.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src') diff --git a/src/listensocket.cpp b/src/listensocket.cpp index 466b91c8b..f875bc646 100644 --- a/src/listensocket.cpp +++ b/src/listensocket.cpp @@ -22,6 +22,10 @@ #include "socket.h" #include "socketengine.h" +#ifdef USE_TCP_DEFER_ACCEPT +#include +#endif + ListenSocket::ListenSocket(ConfigTag* tag, const irc::sockets::sockaddrs& bind_to) : bind_tag(tag) { @@ -38,6 +42,19 @@ ListenSocket::ListenSocket(ConfigTag* tag, const irc::sockets::sockaddrs& bind_t if (rv >= 0) rv = ServerInstance->SE->Listen(this->fd, ServerInstance->Config->MaxConn); + int timeout = tag->getInt("defer", 0); + if (timeout && !rv) + { +#ifdef USE_TCP_DEFER_ACCEPT + setsockopt(fd, IPPROTO_TCP, TCP_DEFER_ACCEPT, &timeout, sizeof(timeout)); +#elif defined USE_SO_ACCEPTFILTER + struct accept_filter_arg afa; + memset(&afa, 0, sizeof(afa)); + strcpy(afa.af_name, "dataready"); + setsockopt(fd, SOL_SOCKET, SO_ACCEPTFILTER, &afa, sizeof(afa)); +#endif + } + #ifdef IPV6_V6ONLY /* This OS supports IPv6 sockets that can also listen for IPv4 * connections. If our address is "*" or empty, enable both v4 and v6 to -- cgit v1.2.3