From: Dave Watson Date: Thu, 2 Apr 2015 18:48:01 +0000 (-0700) Subject: UDP bind via port or address X-Git-Tag: v0.33.0~1 X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=965aa3eabc3dcf8695247c1237ab23d50eae4561;p=folly.git 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 --- 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;