From 292de17c27f805ce961678b007e307e0d4ca7eb9 Mon Sep 17 00:00:00 2001 From: Satadru Pan Date: Fri, 16 Jan 2015 12:05:10 -0800 Subject: [PATCH] apply all sockopts to listening sockets Summary: We want all socket options to be applied to the listen sockets too. The old code here that only applied SO_KEEPALIVE is a bit superstitious. Not all options will be inherited by accept()ed sockets, but that's fine. We set them again post-accept(). Applying all these options to the listening sockets will fix at least one long standing bug, which is that QoS is not set correctly for the first few packets in a flow. This also will let us do the right thing when we gain the ability to set TCP_MAXSEG in D1741753. Test Plan: fbmake runtests & canary in prod Reviewed By: afrind@fb.com, davejwatson@fb.com Subscribers: jsedgwick, satadru, trunkagent, fugalh, exa, folly-diffs@, agartrell FB internal diff: D1745182 Tasks: 2911597 Signature: t1:1745182:1418860157:045680a91b153482bcd4a014894fb28059955d06 --- folly/wangle/acceptor/Acceptor.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/folly/wangle/acceptor/Acceptor.cpp b/folly/wangle/acceptor/Acceptor.cpp index 15807809..2d31e719 100644 --- a/folly/wangle/acceptor/Acceptor.cpp +++ b/folly/wangle/acceptor/Acceptor.cpp @@ -190,13 +190,13 @@ Acceptor::init(AsyncServerSocket* serverSocket, if (serverSocket) { serverSocket->addAcceptCallback(this, eventBase); - // SO_KEEPALIVE is the only setting that is inherited by accepted - // connections so only apply this setting - for (const auto& option: socketOptions_) { - if (option.first.level == SOL_SOCKET && - option.first.optname == SO_KEEPALIVE && option.second == 1) { - serverSocket->setKeepAliveEnabled(true); - break; + + for (auto& fd : serverSocket->getSockets()) { + if (fd < 0) { + continue; + } + for (const auto& opt: socketOptions_) { + opt.first.apply(fd, opt.second); } } } -- 2.34.1