Commit 8f54229a authored by Dave Watson's avatar Dave Watson Committed by Alecs King

Use folly's async udp socket

Summary: They are functionaly equivalent, no need to have more than one

Test Plan: fbconfig -r realtime/voip; fbmake runtests

Reviewed By: naizhi@fb.com

Subscribers: trunkagent, doug, ps, bmatheny, folly-diffs@, yfeldblum

FB internal diff: D1828044

Tasks: 6154007

Signature: t1:1828044:1423165354:f71d2fd28ca76a8f67a597c747f8578d2909823c
parent 5d1db31b
......@@ -22,6 +22,12 @@
#include <unistd.h>
#include <fcntl.h>
// Due to the way kernel headers are included, this may or may not be defined.
// Number pulled from 3.10 kernel headers.
#ifndef SO_REUSEPORT
#define SO_REUSEPORT 15
#endif
namespace folly {
AsyncUDPSocket::AsyncUDPSocket(EventBase* evb)
......@@ -68,6 +74,22 @@ void AsyncUDPSocket::bind(const folly::SocketAddress& address) {
errno);
}
if (reusePort_) {
// put the socket in port reuse mode
int value = 1;
if (setsockopt(socket,
SOL_SOCKET,
SO_REUSEPORT,
&value,
sizeof(value)) != 0) {
::close(socket);
throw AsyncSocketException(AsyncSocketException::NOT_OPEN,
"failed to put socket in reuse_port mode",
errno);
}
}
// bind to the address
sockaddr_storage addrStorage;
address.getAddress(&addrStorage);
......
......@@ -136,6 +136,13 @@ class AsyncUDPSocket : public EventHandler {
CHECK_NE(-1, fd_) << "Need to bind before getting FD out";
return fd_;
}
/**
* Set reuse port mode to call bind() on the same address multiple times
*/
void setReusePort(bool reusePort) {
reusePort_ = reusePort;
}
private:
AsyncUDPSocket(const AsyncUDPSocket&) = delete;
AsyncUDPSocket& operator=(const AsyncUDPSocket&) = delete;
......@@ -157,6 +164,8 @@ class AsyncUDPSocket : public EventHandler {
// Non-null only when we are reading
ReadCallback* readCallback_;
bool reusePort_{false};
};
} // Namespace
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