Commit cddcd91c authored by Jorge Lopez Silva's avatar Jorge Lopez Silva Committed by Facebook Github Bot

Add methods to tell if a socket is accepting/reading.

Summary: It's desirable to know if a given server socket is accepting or if a regular UDP socket is reading.

Reviewed By: dddmello

Differential Revision: D16529348

fbshipit-source-id: 2e9a2e505f97344d21449aed7c9effc298877e41
parent 60be5ec6
...@@ -158,6 +158,13 @@ class AsyncUDPServerSocket : private AsyncUDPSocket::ReadCallback, ...@@ -158,6 +158,13 @@ class AsyncUDPServerSocket : private AsyncUDPSocket::ReadCallback,
return evb_; return evb_;
} }
/**
* Indicates if the current socket is accepting.
*/
bool isAccepting() const {
return socket_->isReading();
}
/** /**
* Pauses accepting datagrams on the underlying socket. * Pauses accepting datagrams on the underlying socket.
*/ */
......
...@@ -281,6 +281,10 @@ class AsyncUDPSocket : public EventHandler { ...@@ -281,6 +281,10 @@ class AsyncUDPSocket : public EventHandler {
return fd_ != NetworkSocket(); return fd_ != NetworkSocket();
} }
virtual bool isReading() const {
return readCallback_ != nullptr;
}
virtual void detachEventBase(); virtual void detachEventBase();
virtual void attachEventBase(folly::EventBase* evb); virtual void attachEventBase(folly::EventBase* evb);
......
...@@ -150,6 +150,10 @@ class UDPServer { ...@@ -150,6 +150,10 @@ class UDPServer {
socket_->resumeAccepting(); socket_->resumeAccepting();
} }
bool isAccepting() {
return socket_->isAccepting();
}
// Whether writes from the UDP server should change the port for each message. // Whether writes from the UDP server should change the port for each message.
void setChangePortForWrites(bool changePortForWrites) { void setChangePortForWrites(bool changePortForWrites) {
changePortForWrites_ = changePortForWrites; changePortForWrites_ = changePortForWrites;
...@@ -406,11 +410,13 @@ TEST_F(AsyncSocketIntegrationTest, PingPongPauseResumeListening) { ...@@ -406,11 +410,13 @@ TEST_F(AsyncSocketIntegrationTest, PingPongPauseResumeListening) {
// Exchange should not happen when paused. // Exchange should not happen when paused.
server->pauseAccepting(); server->pauseAccepting();
EXPECT_FALSE(server->isAccepting());
auto pausedClient = performPingPongTest(server->address(), folly::none); auto pausedClient = performPingPongTest(server->address(), folly::none);
ASSERT_EQ(pausedClient->pongRecvd(), 0); ASSERT_EQ(pausedClient->pongRecvd(), 0);
// Exchange does occur after resuming. // Exchange does occur after resuming.
server->resumeAccepting(); server->resumeAccepting();
EXPECT_TRUE(server->isAccepting());
auto pingClient = performPingPongTest(server->address(), folly::none); auto pingClient = performPingPongTest(server->address(), folly::none);
ASSERT_GT(pingClient->pongRecvd(), 0); ASSERT_GT(pingClient->pongRecvd(), 0);
} }
......
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