From 965aa3eabc3dcf8695247c1237ab23d50eae4561 Mon Sep 17 00:00:00 2001 From: Dave Watson Date: Thu, 2 Apr 2015 11:48:01 -0700 Subject: [PATCH] UDP bind via port or address 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 | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/folly/wangle/bootstrap/ServerSocketFactory.h b/folly/wangle/bootstrap/ServerSocketFactory.h index 1e05ec8b..fad602db 100644 --- a/folly/wangle/bootstrap/ServerSocketFactory.h +++ b/folly/wangle/bootstrap/ServerSocketFactory.h @@ -89,8 +89,12 @@ class AsyncUDPServerSocketFactory : public ServerSocketFactory { auto socket = std::make_shared( 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; -- 2.34.1