Commit 3e3afca6 authored by Dave Watson's avatar Dave Watson Committed by afrind

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
parent 77c9cc67
......@@ -86,9 +86,14 @@ class AsyncUDPServerSocket : private AsyncUDPSocket::ReadCallback
CHECK(!socket_);
socket_ = folly::make_unique<AsyncUDPSocket>(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
......@@ -88,7 +88,7 @@ class AsyncUDPServerSocketFactory : public ServerSocketFactory {
auto socket = std::make_shared<AsyncUDPServerSocket>(
EventBaseManager::get()->getEventBase());
//socket->setReusePortEnabled(reuse);
socket->setReusePort(reuse);
SocketAddress addressr("::1", port);
socket->bind(addressr);
socket->listen();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment