Commit 61a8ac33 authored by Orvid King's avatar Orvid King Committed by Facebook Github Bot

Add functions to get the NetworkSockets out of various types of sockets

Summary: As interim steps to codemod to.

Reviewed By: yfeldblum

Differential Revision: D13568657

fbshipit-source-id: b143b5bab0a64c196892358a30fce17037b19b21
parent f7f0026f
......@@ -326,18 +326,30 @@ class AsyncServerSocket : public DelayedDestruction, public AsyncSocketBase {
return sockets;
}
std::vector<NetworkSocket> getNetworkSockets() const {
std::vector<NetworkSocket> sockets;
for (auto& handler : sockets_) {
sockets.push_back(handler.socket_);
}
return sockets;
}
/**
* Backwards compatible getSocket, warns if > 1 socket
*/
int getSocket() const {
return getNetworkSocket().toFd();
}
NetworkSocket getNetworkSocket() const {
if (sockets_.size() > 1) {
VLOG(2) << "Warning: getSocket can return multiple fds, "
<< "but getSockets was not called, so only returning the first";
}
if (sockets_.size() == 0) {
return -1;
return NetworkSocket();
} else {
return sockets_[0].socket_.toFd();
return sockets_[0].socket_;
}
}
......
......@@ -379,7 +379,7 @@ void AsyncSocket::destroy() {
DelayedDestruction::destroy();
}
int AsyncSocket::detachFd() {
NetworkSocket AsyncSocket::detachNetworkSocket() {
VLOG(6) << "AsyncSocket::detachFd(this=" << this << ", fd=" << fd_
<< ", evb=" << eventBase_ << ", state=" << state_
<< ", events=" << std::hex << eventFlags_ << ")";
......@@ -395,7 +395,7 @@ int AsyncSocket::detachFd() {
// Update the EventHandler to stop using this fd.
// This can only be done after closeNow() unregisters the handler.
ioHandler_.changeHandlerFD(NetworkSocket());
return fd.toFd();
return fd;
}
const folly::SocketAddress& AsyncSocket::anyAddress() {
......
......@@ -340,7 +340,11 @@ class AsyncSocket : virtual public AsyncTransportWrapper {
* Get the file descriptor used by the AsyncSocket.
*/
virtual int getFd() const {
return fd_.toFd();
return getNetworkSocket().toFd();
}
virtual NetworkSocket getNetworkSocket() const {
return fd_;
}
/**
......@@ -357,7 +361,11 @@ class AsyncSocket : virtual public AsyncTransportWrapper {
* Returns the file descriptor. The caller assumes ownership of the
* descriptor, and it will not be closed when the AsyncSocket is destroyed.
*/
virtual int detachFd();
virtual int detachFd() {
return detachNetworkSocket().toFd();
}
virtual NetworkSocket detachNetworkSocket();
/**
* Uniquely identifies a handle to a socket option value. Each
......
......@@ -196,8 +196,12 @@ class AsyncUDPSocket : public EventHandler {
* Get internal FD used by this socket
*/
virtual int getFD() const {
return getNetworkSocket().toFd();
}
virtual NetworkSocket getNetworkSocket() const {
CHECK_NE(NetworkSocket(), fd_) << "Need to bind before getting FD out";
return fd_.toFd();
return fd_;
}
/**
......
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