summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUladzimir Makouski <uladzimir.makouski@mongodb.com>2022-08-29 12:07:41 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-08-29 16:07:29 +0000
commit0fbba9495da3c621deddbee47cff3fda00b07bec (patch)
tree2669456a532b690092e299be2649986fe500a9b7
parent53aa9bec47e34bd010b5dc6b751474c74c3a1797 (diff)
downloadmongo-0fbba9495da3c621deddbee47cff3fda00b07bec.tar.gz
Revert "SERVER-69175 transport::SocketOption class template"
This reverts commit a52ef30f9b84fa7b77a85e8bd14f6e54721b9085.
-rw-r--r--src/mongo/transport/asio_utils.h67
-rw-r--r--src/mongo/transport/transport_layer_asio.cpp35
2 files changed, 10 insertions, 92 deletions
diff --git a/src/mongo/transport/asio_utils.h b/src/mongo/transport/asio_utils.h
index 7590c3ddfd6..e786d9f7eb9 100644
--- a/src/mongo/transport/asio_utils.h
+++ b/src/mongo/transport/asio_utils.h
@@ -51,73 +51,6 @@
namespace mongo::transport {
-/**
- * Generic wrapper for making an ASIO socket get_option or set_option call
- * having a payload of type `T`, which is usually just `int` so it's the default.
- * Can be value-initializd with a `T`. A reference to the payload is available
- * using the dereferencing operators.
- *
- * Models Asio GettableSocketOption and SettableSocketOption.
- * https://www.boost.org/doc/libs/1_80_0/doc/html/boost_asio/reference/GettableSocketOption.html
- * https://www.boost.org/doc/libs/1_80_0/doc/html/boost_asio/reference/SettableSocketOption.html
- *
- * The Asio-required accessors must accept a `Protocol` argument, which we ignore.
- * The kinds of options we use don't need it.
- * https://www.boost.org/doc/libs/1_80_0/doc/html/boost_asio/reference/Protocol.html
- *
- * Example:
- * using TcpInfoOption = SocketOption<IPPROTO_TCP, TCP_INFO, tcp_info>;
- * ...
- * TcpInfoOption tcpiOption;
- * socket.get_option(tcpiOption);
- * tcp_info& infoOut = *tcpiOption;
- */
-template <int optLevel, int optName, typename T = int>
-class SocketOption {
-public:
- SocketOption() = default;
- explicit SocketOption(T d) : _data{std::move(d)} {}
- template <typename Protocol>
- int level(const Protocol&) const {
- return optLevel;
- }
- template <typename Protocol>
- int name(const Protocol&) const {
- return optName;
- }
- template <typename Protocol>
- T* data(const Protocol&) {
- return &**this;
- }
- template <typename Protocol>
- const T* data(const Protocol&) const {
- return &**this;
- }
- template <typename Protocol>
- size_t size(const Protocol&) const {
- return sizeof(_data);
- }
- template <typename Protocol>
- void resize(const Protocol&, size_t) const {}
-
- T& operator*() {
- return _data;
- }
- const T& operator*() const {
- return _data;
- }
-
- T* operator->() {
- return &**this;
- }
- const T* operator->() const {
- return &**this;
- }
-
-private:
- T _data{};
-};
-
inline SockAddr endpointToSockAddr(const asio::generic::stream_protocol::endpoint& endPoint) {
SockAddr wrappedAddr(endPoint.data(), endPoint.size());
return wrappedAddr;
diff --git a/src/mongo/transport/transport_layer_asio.cpp b/src/mongo/transport/transport_layer_asio.cpp
index 5ce72dd2342..59bdb1380ec 100644
--- a/src/mongo/transport/transport_layer_asio.cpp
+++ b/src/mongo/transport/transport_layer_asio.cpp
@@ -35,10 +35,6 @@
#include <fmt/format.h>
#include <fstream>
-#ifdef __linux__
-#include <netinet/tcp.h>
-#endif
-
#include <asio.hpp>
#include <asio/system_timer.hpp>
#include <boost/algorithm/string.hpp>
@@ -85,18 +81,8 @@ namespace mongo {
namespace transport {
namespace {
-
-using TcpKeepaliveOption = SocketOption<SOL_SOCKET, SO_KEEPALIVE>;
-#ifdef __linux__
-using TcpInfoOption = SocketOption<IPPROTO_TCP, TCP_INFO, tcp_info>;
-using TcpKeepaliveCountOption = SocketOption<IPPROTO_TCP, TCP_KEEPCNT>;
-using TcpKeepaliveIdleSecsOption = SocketOption<IPPROTO_TCP, TCP_KEEPIDLE>;
-using TcpKeepaliveIntervalSecsOption = SocketOption<IPPROTO_TCP, TCP_KEEPINTVL>;
-using TcpUserTimeoutMillisOption = SocketOption<IPPROTO_TCP, TCP_USER_TIMEOUT, unsigned>;
-#endif // __linux__
-
#ifdef TCP_FASTOPEN
-using TcpFastOpenOption = SocketOption<IPPROTO_TCP, TCP_FASTOPEN>;
+using TCPFastOpen = asio::detail::socket_option::integer<IPPROTO_TCP, TCP_FASTOPEN>;
#endif
/**
* On systems with TCP_FASTOPEN_CONNECT (linux >= 4.11),
@@ -106,7 +92,7 @@ using TcpFastOpenOption = SocketOption<IPPROTO_TCP, TCP_FASTOPEN>;
* https://github.com/torvalds/linux/commit/19f6d3f3c8422d65b5e3d2162e30ef07c6e21ea2
*/
#ifdef TCP_FASTOPEN_CONNECT
-using TcpFastOpenConnectOption = SocketOption<IPPROTO_TCP, TCP_FASTOPEN_CONNECT>;
+using TCPFastOpenConnect = asio::detail::socket_option::boolean<IPPROTO_TCP, TCP_FASTOPEN_CONNECT>;
#endif
/**
@@ -696,7 +682,7 @@ StatusWith<TransportLayerASIO::ASIOSessionHandle> TransportLayerASIO::_doSyncCon
const auto family = protocol.family();
if ((family == AF_INET) || (family == AF_INET6)) {
setSocketOption(sock,
- TcpFastOpenConnectOption(gTCPFastOpenClient),
+ TCPFastOpenConnect(gTCPFastOpenClient),
"connect (sync) TCP fast open",
logv2::LogSeverity::Info(),
ec);
@@ -882,7 +868,7 @@ Future<SessionHandle> TransportLayerASIO::asyncConnect(
#ifdef TCP_FASTOPEN_CONNECT
std::error_code ec;
setSocketOption(connector->socket,
- TcpFastOpenConnectOption(gTCPFastOpenClient),
+ TCPFastOpenConnect(gTCPFastOpenClient),
"connect (async) TCP fast open",
logv2::LogSeverity::Info(),
ec);
@@ -1222,7 +1208,7 @@ Status TransportLayerASIO::setup() {
#ifdef TCP_FASTOPEN
if (gTCPFastOpenServer && ((addr.family() == AF_INET) || (addr.family() == AF_INET6))) {
setSocketOption(acceptor,
- TcpFastOpenOption(gTCPFastOpenQueueSize),
+ TCPFastOpen(gTCPFastOpenQueueSize),
"acceptor TCP fast open",
logv2::LogSeverity::Info(),
ec);
@@ -1447,12 +1433,11 @@ void TransportLayerASIO::_acceptConnection(GenericAcceptor& acceptor) {
}
#ifdef TCPI_OPT_SYN_DATA
- try {
- TcpInfoOption tcpi{};
- peerSocket.get_option(tcpi);
- if (tcpi->tcpi_options & TCPI_OPT_SYN_DATA)
- networkCounter.acceptedTFOIngress();
- } catch (const asio::system_error&) {
+ struct tcp_info info;
+ socklen_t info_len = sizeof(info);
+ if (!getsockopt(peerSocket.native_handle(), IPPROTO_TCP, TCP_INFO, &info, &info_len) &&
+ (info.tcpi_options & TCPI_OPT_SYN_DATA)) {
+ networkCounter.acceptedTFOIngress();
}
#endif