Skip to content

Commit faac4b4

Browse files
jlhe97meta-codesync[bot]
authored andcommitted
c++|zcrx| add support for src port binding for the fizz client
Summary: **WHAT** adding support for the src port binding calculation before connecting the socket for the fizz client. **WHY** necessary for zcrx which fizz clients also want. Reviewed By: spikeh Differential Revision: D94591933 fbshipit-source-id: 2ab69583b985ec067df4ee32c45e54edd5e19810
1 parent 5b4faa1 commit faac4b4

3 files changed

Lines changed: 13 additions & 7 deletions

File tree

third-party/fizz/src/fizz/client/AsyncFizzClient-inl.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ void AsyncFizzClientT<SM>::connect(
117117
std::chrono::milliseconds totalTimeout,
118118
std::chrono::milliseconds socketTimeout,
119119
const folly::SocketOptionMap& options,
120-
const folly::SocketAddress& bindAddr) {
120+
const folly::AsyncSocketTransport::BindOptions& bindOptions) {
121121
DelayedDestruction::DestructorGuard dg(this);
122122

123123
// shouldn't attempt to connect a second time
@@ -141,8 +141,11 @@ void AsyncFizzClientT<SM>::connect(
141141
connectAddr,
142142
static_cast<int>(socketTimeout.count()),
143143
options,
144-
bindAddr);
144+
bindOptions);
145145
} else {
146+
if (auto* fd = std::get_if<folly::NetworkSocket>(&bindOptions)) {
147+
folly::netops::close(*fd);
148+
}
146149
folly::AsyncSocketException ase(
147150
folly::AsyncSocketException::BAD_ARGS,
148151
"could not find underlying socket");

third-party/fizz/src/fizz/client/AsyncFizzClient.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ class AsyncFizzClientT : public AsyncFizzBase,
8787
std::chrono::milliseconds totalTimeout = std::chrono::milliseconds(0),
8888
std::chrono::milliseconds socketTimeout = std::chrono::milliseconds(0),
8989
const folly::SocketOptionMap& options = folly::emptySocketOptionMap,
90-
const folly::SocketAddress& bindAddr = folly::AsyncSocket::anyAddress());
90+
const folly::AsyncSocketTransport::BindOptions& bindOptions =
91+
folly::AsyncSocketTransport::anyAddress());
9192

9293
/**
9394
* Variant of the TLS handshake connect() API above that uses the default

third-party/thrift/src/thrift/conformance/stresstest/client/ClientFactory.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -344,10 +344,11 @@ folly::AsyncTransport::UniquePtr createIOUringTLS(
344344
folly::AsyncTransport::UniquePtr createIOUringFizz(
345345
folly::EventBase* evb, const ClientConnectionConfig& cfg) {
346346
auto sock = new folly::AsyncIoUringSocket(evb, getIoUringSocketOptions(cfg));
347+
folly::AsyncSocketTransport::BindOptions bindOptions =
348+
folly::AsyncSocket::anyAddress();
347349
if (cfg.ioUringZcrx && cfg.ioUringZcrxSocketBind) {
348-
// TODO: Fizz connect() does not support a boundFd parameter, so ZC-RX
349-
// source port binding is not supported for the Fizz transport yet.
350-
LOG(WARNING) << "io_zcrx_socket_bind is not supported with Fizz transport";
350+
bindOptions = folly::AsyncIoUringSocketFactory::createBoundSocketForZcRx(
351+
evb, cfg.serverHost.getIPAddress(), cfg.serverHost.getPort());
351352
}
352353
auto fizzClient = fizz::client::AsyncFizzClient::UniquePtr(
353354
new fizz::client::AsyncFizzClient(
@@ -360,7 +361,8 @@ folly::AsyncTransport::UniquePtr createIOUringFizz(
360361
{},
361362
std::chrono::milliseconds(0),
362363
std::chrono::milliseconds(0),
363-
getSocketOptions(cfg));
364+
getSocketOptions(cfg),
365+
bindOptions);
364366
return fizzClient;
365367
}
366368
#endif

0 commit comments

Comments
 (0)