detail/RangeSse42.h \
detail/Sleeper.h \
detail/SlowFingerprint.h \
+ detail/SocketFastOpen.h \
detail/SpinLockImpl.h \
detail/StaticSingletonManager.h \
detail/Stats.h \
io/async/ssl/SSLErrors.cpp \
json.cpp \
detail/MemoryIdler.cpp \
+ detail/SocketFastOpen.cpp \
MacAddress.cpp \
MemoryMapping.cpp \
portability/Dirent.cpp \
--- /dev/null
+/*
+ * 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
+}
+}
--- /dev/null
+/*
+ * 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
+}
+}
#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>
}
#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);
}
#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.
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
*/
bool keepAliveEnabled_;
bool reusePortEnabled_{false};
bool closeOnExec_;
+ bool tfo_{false};
+ uint32_t tfoMaxQueueSize_{0};
ShutdownSocketSet* shutdownSocketSet_;
ConnectionEventCallback* connectionEventCallback_{nullptr};
};