s.setNonBlocking();
ComboAddress local = pdns::getQueryLocalAddress(ip.sin4.sin_family, 0);
+ if (SyncRes::s_tcp_fast_open > 0) {
+ s.setFastOpen(SyncRes::s_tcp_fast_open);
+ }
s.bind(local);
-
+
s.connect(ip);
-
+
uint16_t tlen=htons(vpacket.size());
char *lenP=(char*)&tlen;
const char *msgP=(const char*)&*vpacket.begin();
if (ret != LWResult::Result::Success) {
return ret;
}
-
+
packet.clear();
ret = arecvtcp(packet, 2, &s, false);
if (ret != LWResult::Result::Success) {
#endif
}
- if (::arg().asNum("tcp-fast-open") > 0) {
+ if (SyncRes::s_tcp_fast_open > 0) {
#ifdef TCP_FASTOPEN
- int fastOpenQueueSize = ::arg().asNum("tcp-fast-open");
- if (setsockopt(fd, IPPROTO_TCP, TCP_FASTOPEN, &fastOpenQueueSize, sizeof fastOpenQueueSize) < 0) {
+ if (setsockopt(fd, IPPROTO_TCP, TCP_FASTOPEN, &SyncRes::tcp_fast_open, sizeof SyncRes::tcp_fast_open) < 0) {
int err = errno;
g_log<<Logger::Error<<"Failed to enable TCP Fast Open for listening socket: "<<strerror(err)<<endl;
}
static void handleTCPClientWritable(int fd, FDMultiplexer::funcparam_t& var)
{
- PacketID* pid=boost::any_cast<PacketID>(&var);
- ssize_t ret=send(fd, pid->outMSG.c_str() + pid->outPos, pid->outMSG.size() - pid->outPos,0);
- if(ret > 0) {
- pid->outPos+=(ssize_t)ret;
- if(pid->outPos==pid->outMSG.size()) {
+ PacketID* pid = boost::any_cast<PacketID>(&var);
+ ssize_t ret = send(fd, pid->outMSG.c_str() + pid->outPos, pid->outMSG.size() - pid->outPos,0);
+ if (ret > 0) {
+ pid->outPos += (ssize_t)ret;
+ if (pid->outPos == pid->outMSG.size()) {
PacketID tmp=*pid;
t_fdm->removeWriteFD(fd);
MT->sendEvent(tmp, &tmp.outMSG); // send back what we sent to convey everything is ok
SyncRes::s_maxdepth=::arg().asNum("max-recursion-depth");
SyncRes::s_rootNXTrust = ::arg().mustDo( "root-nx-trust");
SyncRes::s_refresh_ttlperc = ::arg().asNum("refresh-on-ttl-perc");
+ SyncRes::s_tcp_fast_open = ::arg().asNum("tcp-fast-open");
RecursorPacketCache::s_refresh_ttlperc = SyncRes::s_refresh_ttlperc;
if(SyncRes::s_serverID.empty()) {
}
}
+ void setFastOpen(int fastOpenQueueSize)
+ {
+#ifdef TCP_FASTOPEN_CONNECT
+ setsockopt(d_socket, IPPROTO_TCP, TCP_FASTOPEN_CONNECT, &fastOpenQueueSize, sizeof fastOpenQueueSize);
+#endif
+ }
+
//! Bind the socket to a specified endpoint
void bind(const ComboAddress &local, bool reuseaddr=true)
{
static bool s_qnameminimization;
static HardenNXD s_hardenNXD;
static unsigned int s_refresh_ttlperc;
+ static int s_tcp_fast_open;
std::unordered_map<std::string,bool> d_discardedPolicies;
DNSFilterEngine::Policy d_appliedPolicy;