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
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();
// Temporary buffer for data
folly::IOBufQueue buf_;
+
+ bool reusePort_{false};
};
} // Namespace
auto socket = std::make_shared<AsyncUDPServerSocket>(
EventBaseManager::get()->getEventBase());
- //socket->setReusePortEnabled(reuse);
+ socket->setReusePort(reuse);
SocketAddress addressr("::1", port);
socket->bind(addressr);
socket->listen();