UDP bind via port or address
authorDave Watson <davejwatson@fb.com>
Thu, 2 Apr 2015 18:48:01 +0000 (11:48 -0700)
committerafrind <afrind@fb.com>
Thu, 2 Apr 2015 19:02:58 +0000 (12:02 -0700)
Summary: Bind via port or address, similar to tcp

Test Plan: I wrote a unittest that tested v4 vs v6 binding - can't check it in because we have v6 only clusters though.  Not sure how eles to write a unittest without picking specific ports

Reviewed By: hans@fb.com

Subscribers: doug, fugalh, folly-diffs@, jsedgwick, yfeldblum, chalfant

FB internal diff: D1948938

Signature: t1:1948938:1427841721:621031320981bf366a8252a0ea1d4491b694ea24

folly/wangle/bootstrap/ServerSocketFactory.h

index 1e05ec8b135e06bafc5ca10c7f52d7e2deee453b..fad602db6466c5698f738eca7c73a54bc9210b09 100644 (file)
@@ -89,8 +89,12 @@ class AsyncUDPServerSocketFactory : public ServerSocketFactory {
     auto socket = std::make_shared<AsyncUDPServerSocket>(
       EventBaseManager::get()->getEventBase());
     socket->setReusePort(reuse);
-    SocketAddress addressr("::1", port);
-    socket->bind(addressr);
+    if (port >= 0) {
+      SocketAddress addressr("::1", port);
+      socket->bind(addressr);
+    } else {
+      socket->bind(address);
+    }
     socket->listen();
 
     return socket;