diff options
author | Daniel Vassdal <shutter@canternet.org> | 2013-05-22 12:48:58 -0700 |
---|---|---|
committer | attilamolnar <attilamolnar@hush.com> | 2013-06-03 18:45:46 +0200 |
commit | 263c2efd960057f1cfafd40fce338605c39b0ad4 (patch) | |
tree | bd953e551f1f184b3725da2cf9656a4bb302983b /src | |
parent | ca4c4a67988419b9eb479ffcf82238dc1648b0ad (diff) |
Added option for using TCP_DEFER_ACCEPT. Prevents the connection from being handed over to the daemon before data is ready from the client.
Diffstat (limited to 'src')
-rw-r--r-- | src/listensocket.cpp | 17 |
1 files changed, 17 insertions, 0 deletions
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 <netinet/tcp.h> +#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 |