Commit bd52f502 authored by Subodh Iyengar's avatar Subodh Iyengar Committed by Facebook Github Bot 8

wangle support for TFO

Summary: Add server support for TFO to wangle.

Reviewed By: Orvid

Differential Revision: D3275427

fbshipit-source-id: 466baa342e2e0c4751e9c96d1e660cffb90e0634
parent b3c4aa79
......@@ -70,6 +70,7 @@ nobase_follyinclude_HEADERS = \
detail/RangeSse42.h \
detail/Sleeper.h \
detail/SlowFingerprint.h \
detail/SocketFastOpen.h \
detail/SpinLockImpl.h \
detail/StaticSingletonManager.h \
detail/Stats.h \
......@@ -427,6 +428,7 @@ libfolly_la_SOURCES = \
io/async/ssl/SSLErrors.cpp \
json.cpp \
detail/MemoryIdler.cpp \
detail/SocketFastOpen.cpp \
MacAddress.cpp \
MemoryMapping.cpp \
portability/Dirent.cpp \
......
/*
* Copyright 2016 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <folly/detail/SocketFastOpen.h>
namespace folly {
namespace detail {
#if FOLLY_ALLOW_TFO
ssize_t tfo_sendto(
int sockfd,
const void* buf,
size_t len,
int flags,
const struct sockaddr* dest_addr,
socklen_t addrlen) {
flags |= MSG_FASTOPEN;
return sendto(sockfd, buf, len, flags, dest_addr, addrlen);
}
int tfo_enable(int sockfd, size_t max_queue_size) {
return setsockopt(
sockfd, SOL_TCP, TCP_FASTOPEN, &max_queue_size, sizeof(max_queue_size));
}
#endif
}
}
/*
* Copyright 2016 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include <sys/socket.h>
#include <sys/types.h>
#if !defined(FOLLY_ALLOW_TFO) && defined(TCP_FASTOPEN) && defined(MSG_FASTOPEN)
#define FOLLY_ALLOW_TFO 1
#endif
namespace folly {
namespace detail {
#if FOLLY_ALLOW_TFO
/**
* tfo_sendto has the same semantics as sendto, but is used to
* send with TFO data.
*/
ssize_t tfo_sendto(
int sockfd,
const void* buf,
size_t len,
int flags,
const struct sockaddr* dest_addr,
socklen_t addlen);
/**
* Enable TFO on a listening socket.
*/
int tfo_enable(int sockfd, size_t max_queue_size);
#endif
}
}
......@@ -22,6 +22,7 @@
#include <folly/FileUtil.h>
#include <folly/SocketAddress.h>
#include <folly/detail/SocketFastOpen.h>
#include <folly/io/async/EventBase.h>
#include <folly/io/async/NotificationQueue.h>
......@@ -701,6 +702,14 @@ void AsyncServerSocket::setupSocket(int fd, int family) {
}
#endif
#if FOLLY_ALLOW_TFO
if (tfo_ && detail::tfo_enable(fd, tfoMaxQueueSize_) != 0) {
// This isn't a fatal error; just log an error message and continue
LOG(WARNING) << "failed to set TCP_FASTOPEN on async server socket: "
<< folly::errnoStr(errno);
}
#endif
if (shutdownSocketSet_) {
shutdownSocketSet_->add(fd);
}
......
......@@ -16,21 +16,20 @@
#pragma once
#include <folly/SocketAddress.h>
#include <folly/io/ShutdownSocketSet.h>
#include <folly/io/async/AsyncSocketBase.h>
#include <folly/io/async/AsyncTimeout.h>
#include <folly/io/async/DelayedDestruction.h>
#include <folly/io/async/EventHandler.h>
#include <folly/io/async/EventBase.h>
#include <folly/io/async/EventHandler.h>
#include <folly/io/async/NotificationQueue.h>
#include <folly/io/async/AsyncTimeout.h>
#include <folly/io/async/AsyncSocketBase.h>
#include <folly/io/ShutdownSocketSet.h>
#include <folly/SocketAddress.h>
#include <memory>
#include <exception>
#include <vector>
#include <limits.h>
#include <stddef.h>
#include <sys/socket.h>
#include <exception>
#include <memory>
#include <vector>
// Due to the way kernel headers are included, this may or may not be defined.
// Number pulled from 3.10 kernel headers.
......@@ -659,6 +658,14 @@ class AsyncServerSocket : public DelayedDestruction
return closeOnExec_;
}
/**
* Tries to enable TFO if the machine supports it.
*/
void setTFOEnabled(bool enabled, uint32_t maxTFOQueueSize) {
tfo_ = enabled;
tfoMaxQueueSize_ = maxTFOQueueSize;
}
/**
* Get whether or not the socket is accepting new connections
*/
......@@ -837,6 +844,8 @@ class AsyncServerSocket : public DelayedDestruction
bool keepAliveEnabled_;
bool reusePortEnabled_{false};
bool closeOnExec_;
bool tfo_{false};
uint32_t tfoMaxQueueSize_{0};
ShutdownSocketSet* shutdownSocketSet_;
ConnectionEventCallback* connectionEventCallback_{nullptr};
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment