Commit c0a9ed05 authored by Yang Chi's avatar Yang Chi Committed by Facebook Github Bot

Add API to AsyncUDPSocket to check if socket has bound

Summary:
A lot of functions in AsyncUDPSocket just use a CHECK for fd_ and fail
hard if ths socket hasn't bound to a fd. This adds an API for user to actually
find out if socket has bound without crash.

(Note: this ignores all push blocking failures!)

Reviewed By: siyengar

Differential Revision: D8026035

fbshipit-source-id: fc7bf9c1d6d7f045cd4dba94e3278d20d80de887
parent 5313ad0d
......@@ -244,6 +244,10 @@ class AsyncUDPSocket : public EventHandler {
*/
virtual int connect(const folly::SocketAddress& address);
virtual bool isBound() const {
return fd_ != -1;
}
protected:
virtual ssize_t sendmsg(int socket, const struct msghdr* message, int flags) {
return ::sendmsg(socket, message, flags);
......
......@@ -573,3 +573,11 @@ TEST_F(AsyncUDPSocketTest, TestNonExistentServerNoErrCb) {
evb_.loopForever();
EXPECT_FALSE(errRecvd);
}
TEST_F(AsyncUDPSocketTest, TestBound) {
AsyncUDPSocket socket(&evb_);
EXPECT_FALSE(socket.isBound());
folly::SocketAddress address("0.0.0.0", 0);
socket.bind(address);
EXPECT_TRUE(socket.isBound());
}
......@@ -43,6 +43,7 @@ struct MockAsyncUDPSocket : public AsyncUDPSocket {
MOCK_METHOD1(dontFragment, void(bool));
MOCK_METHOD1(setErrMessageCallback, void(ErrMessageCallback*));
MOCK_METHOD1(connect, int(const SocketAddress&));
MOCK_CONST_METHOD0(isBound, bool());
};
} // namespace test
......
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