From: Dave Watson Date: Mon, 30 Mar 2015 17:17:12 +0000 (-0700) Subject: asyncudpserversocket reuse port X-Git-Tag: v0.33.0~19 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=3e3afca6d0979b6ff45aa18b04b2d803e8f2d258;p=folly.git asyncudpserversocket reuse port Summary: AsyncUDPSocket supports reuse port, also make it available in AsyncUDPServerSocket. Has to happen before bind Test Plan: ?? it builds? Mutliple binds already work with reuseaddr, but load balancing doesn't work as well. See http://lwn.net/Articles/542629/ for details Reviewed By: naizhi@fb.com Subscribers: doug, fugalh, folly-diffs@, jsedgwick, yfeldblum, chalfant FB internal diff: D1948932 Signature: t1:1948932:1427473013:8c114458a0746bb2b6957db33c1834179d860c00 --- diff --git a/folly/io/async/AsyncUDPServerSocket.h b/folly/io/async/AsyncUDPServerSocket.h index 485f18b0..04682297 100644 --- a/folly/io/async/AsyncUDPServerSocket.h +++ b/folly/io/async/AsyncUDPServerSocket.h @@ -86,9 +86,14 @@ class AsyncUDPServerSocket : private AsyncUDPSocket::ReadCallback CHECK(!socket_); socket_ = folly::make_unique(evb_); + socket_->setReusePort(reusePort_); socket_->bind(addy); } + void setReusePort(bool reusePort) { + reusePort_ = reusePort; + } + folly::SocketAddress address() const { CHECK(socket_); return socket_->address(); @@ -202,6 +207,8 @@ class AsyncUDPServerSocket : private AsyncUDPSocket::ReadCallback // Temporary buffer for data folly::IOBufQueue buf_; + + bool reusePort_{false}; }; } // Namespace diff --git a/folly/wangle/bootstrap/ServerSocketFactory.h b/folly/wangle/bootstrap/ServerSocketFactory.h index ca99c2ee..1e05ec8b 100644 --- a/folly/wangle/bootstrap/ServerSocketFactory.h +++ b/folly/wangle/bootstrap/ServerSocketFactory.h @@ -88,7 +88,7 @@ class AsyncUDPServerSocketFactory : public ServerSocketFactory { auto socket = std::make_shared( EventBaseManager::get()->getEventBase()); - //socket->setReusePortEnabled(reuse); + socket->setReusePort(reuse); SocketAddress addressr("::1", port); socket->bind(addressr); socket->listen();