@@ -217,9 +217,8 @@ void AsyncIoUringSocket::connect(
217217 const folly::SocketAddress& address,
218218 std::chrono::milliseconds timeout,
219219 SocketOptionMap const & options,
220- const folly::SocketAddress& bindAddr,
221- const std::string& ifName,
222- NetworkSocket boundFd) noexcept {
220+ const BindOptions& bindOptions,
221+ const std::string& ifName) noexcept {
223222 VLOG (4 ) << " AsyncIoUringSocket::connect() this=" << this << " to=" << address
224223 << " fastopen=" << enableTFO_;
225224 evb_->dcheckIsInEventBaseThread ();
@@ -230,33 +229,37 @@ void AsyncIoUringSocket::connect(
230229 connectSqe_ = std::make_unique<ConnectSqe>(this );
231230 }
232231 if (connectSqe_->inFlight ()) {
233- fileops::close (boundFd.toFd ());
232+ if (auto * fd = std::get_if<NetworkSocket>(&bindOptions)) {
233+ fileops::close (fd->toFd ());
234+ }
234235 callback->connectErr (AsyncSocketException (
235236 AsyncSocketException::NOT_OPEN , " connection in flight" , -1 ));
236237 return ;
237238 }
238239 if (fd_ != NetworkSocket{}) {
239- fileops::close (boundFd.toFd ());
240+ if (auto * fd = std::get_if<NetworkSocket>(&bindOptions)) {
241+ fileops::close (fd->toFd ());
242+ }
240243 callback->connectErr (AsyncSocketException (
241244 AsyncSocketException::NOT_OPEN , " connection is connected" , -1 ));
242245 return ;
243246 }
244247 connectCallback_ = callback;
245248 peerAddress_ = address;
246249
247- if (boundFd != NetworkSocket{} ) {
250+ if (auto * boundFd = std::get_if< NetworkSocket>(&bindOptions) ) {
248251 struct sockaddr_storage peerAddr{};
249252 socklen_t peerLen = sizeof (peerAddr);
250253 if (::getpeername (
251- boundFd. toFd (),
254+ boundFd-> toFd (),
252255 reinterpret_cast <struct sockaddr *>(&peerAddr),
253256 &peerLen) == 0 ) {
254- fileops::close (boundFd. toFd ());
257+ fileops::close (boundFd-> toFd ());
255258 callback->connectErr (AsyncSocketException (
256259 AsyncSocketException::INVALID_STATE , " boundFd is already connected" ));
257260 return ;
258261 }
259- setFd (boundFd);
262+ setFd (* boundFd);
260263 } else {
261264 setFd (makeConnectSocket (address));
262265 }
@@ -285,8 +288,9 @@ void AsyncIoUringSocket::connect(
285288 return ;
286289 }
287290
288- // bind the socket, unless already provided
289- if (bindAddr != anyAddress () && boundFd == NetworkSocket ()) {
291+ // bind the socket
292+ if (auto * bindAddr = std::get_if<folly::SocketAddress>(&bindOptions);
293+ bindAddr && *bindAddr != anyAddress ()) {
290294 sockaddr_storage addrStorage;
291295 auto saddr = reinterpret_cast <sockaddr*>(&addrStorage);
292296
@@ -299,14 +303,14 @@ void AsyncIoUringSocket::connect(
299303 // ports. Using the IP_BIND_ADDRESS_NO_PORT delays assigning a port until
300304 // connect expanding the available port range, unless
301305 // setBindAddressNoPort() is called.
302- if (bindAddr. getPort () == 0 ) {
306+ if (bindAddr-> getPort () == 0 ) {
303307 if (bindAddressNoPort_ &&
304308 setSockOpt (IPPROTO_IP , IP_BIND_ADDRESS_NO_PORT , &one, sizeof (one))) {
305309 auto errnoCopy = errno;
306310 callback->connectErr (AsyncSocketException (
307311 AsyncSocketException::NOT_OPEN ,
308312 " failed to setsockopt IP_BIND_ADDRESS_NO_PORT prior to bind on " +
309- bindAddr. describe (),
313+ bindAddr-> describe (),
310314 errnoCopy));
311315 return ;
312316 }
@@ -319,19 +323,19 @@ void AsyncIoUringSocket::connect(
319323 callback->connectErr (AsyncSocketException (
320324 AsyncSocketException::NOT_OPEN ,
321325 " failed to setsockopt SO_REUSEADDR prior to bind on " +
322- bindAddr. describe (),
326+ bindAddr-> describe (),
323327 errnoCopy));
324328 return ;
325329 }
326330 }
327331
328- bindAddr. getAddress (&addrStorage);
332+ bindAddr-> getAddress (&addrStorage);
329333
330- if (::bind (fd_.toFd (), saddr, bindAddr. getActualSize ()) != 0 ) {
334+ if (::bind (fd_.toFd (), saddr, bindAddr-> getActualSize ()) != 0 ) {
331335 auto errnoCopy = errno;
332336 callback->connectErr (AsyncSocketException (
333337 AsyncSocketException::NOT_OPEN ,
334- " failed to bind to async io_uring socket: " + bindAddr. describe (),
338+ " failed to bind to async io_uring socket: " + bindAddr-> describe (),
335339 errnoCopy));
336340 return ;
337341 }
0 commit comments