From 2062a6baa4eb25f376077bcb075dcd84295150c4 Mon Sep 17 00:00:00 2001 From: Subodh Iyengar Date: Thu, 22 Sep 2016 01:01:42 -0700 Subject: [PATCH] Add logs for TFO succeded Summary: Add logs for TFO to AsyncSocket and wangle Reviewed By: knekritz Differential Revision: D3906104 fbshipit-source-id: 9a79b6f91273f8017a5e0d72fe5bdc8eff645ebc --- folly/io/async/AsyncSocket.cpp | 4 ++++ folly/io/async/AsyncSocket.h | 14 ++++++++++++++ folly/io/async/test/AsyncSocketTest2.cpp | 7 +++++-- folly/io/async/test/SocketClient.cpp | 5 +++-- 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/folly/io/async/AsyncSocket.cpp b/folly/io/async/AsyncSocket.cpp index 68ff6299..beafbe5f 100644 --- a/folly/io/async/AsyncSocket.cpp +++ b/folly/io/async/AsyncSocket.cpp @@ -1147,6 +1147,10 @@ void AsyncSocket::getPeerAddress(folly::SocketAddress* address) const { *address = addr_; } +bool AsyncSocket::getTFOSucceded() const { + return detail::tfo_succeeded(fd_); +} + int AsyncSocket::setNoDelay(bool noDelay) { if (fd_ < 0) { VLOG(4) << "AsyncSocket::setNoDelay() called on non-open socket " diff --git a/folly/io/async/AsyncSocket.h b/folly/io/async/AsyncSocket.h index ca4272b3..30ae8d84 100644 --- a/folly/io/async/AsyncSocket.h +++ b/folly/io/async/AsyncSocket.h @@ -431,6 +431,20 @@ class AsyncSocket : virtual public AsyncTransportWrapper { return tfoFinished_; } + /** + * Returns whether or not TFO attempt succeded on this + * connection. + * For servers this is pretty straightforward API and can + * be invoked right after the connection is accepted. This API + * will perform one syscall. + * This API is a bit tricky to use for clients, since clients + * only know this for sure after the SYN-ACK is returned. So it's + * appropriate to call this only after the first application + * data is read from the socket when the caller knows that + * the SYN has been ACKed by the server. + */ + bool getTFOSucceded() const; + // Methods controlling socket options /** diff --git a/folly/io/async/test/AsyncSocketTest2.cpp b/folly/io/async/test/AsyncSocketTest2.cpp index afd4f9e0..1e8227f9 100644 --- a/folly/io/async/test/AsyncSocketTest2.cpp +++ b/folly/io/async/test/AsyncSocketTest2.cpp @@ -2465,6 +2465,7 @@ TEST(AsyncSocketTest, ConnectTFO) { ASSERT_EQ(1, rcb.buffers.size()); ASSERT_EQ(sizeof(buf), rcb.buffers[0].length); EXPECT_EQ(0, memcmp(rcb.buffers[0].buffer, buf.data(), buf.size())); + EXPECT_EQ(socket->getTFOFinished(), socket->getTFOSucceded()); } TEST(AsyncSocketTest, ConnectTFOSupplyEarlyReadCB) { @@ -2514,6 +2515,7 @@ TEST(AsyncSocketTest, ConnectTFOSupplyEarlyReadCB) { ASSERT_EQ(1, rcb.buffers.size()); ASSERT_EQ(sizeof(buf), rcb.buffers[0].length); EXPECT_EQ(0, memcmp(rcb.buffers[0].buffer, buf.data(), buf.size())); + EXPECT_EQ(socket->getTFOFinished(), socket->getTFOSucceded()); } /** @@ -2543,10 +2545,9 @@ TEST(AsyncSocketTest, ConnectRefusedTFO) { if (!socket->getTFOFinished()) { EXPECT_EQ(STATE_FAILED, write1.state); - EXPECT_FALSE(socket->getTFOFinished()); } else { EXPECT_EQ(STATE_SUCCEEDED, write1.state); - EXPECT_TRUE(socket->getTFOFinished()); + EXPECT_FALSE(socket->getTFOSucceded()); } EXPECT_EQ(STATE_FAILED, write2.state); @@ -2668,6 +2669,7 @@ TEST(AsyncSocketTest, TestTFOUnsupported) { ASSERT_EQ(1, rcb.buffers.size()); ASSERT_EQ(sizeof(buf), rcb.buffers[0].length); EXPECT_EQ(0, memcmp(rcb.buffers[0].buffer, buf.data(), buf.size())); + EXPECT_EQ(socket->getTFOFinished(), socket->getTFOSucceded()); } TEST(AsyncSocketTest, TestTFOUnsupportedTimeout) { @@ -2874,6 +2876,7 @@ TEST(AsyncSocketTest, ConnectTFOWithBigData) { ASSERT_EQ(1, rcb.buffers.size()); ASSERT_EQ(sizeof(buf), rcb.buffers[0].length); EXPECT_EQ(0, memcmp(rcb.buffers[0].buffer, buf.data(), buf.size())); + EXPECT_EQ(socket->getTFOFinished(), socket->getTFOSucceded()); } #endif diff --git a/folly/io/async/test/SocketClient.cpp b/folly/io/async/test/SocketClient.cpp index 957ec9d0..1a93ab95 100644 --- a/folly/io/async/test/SocketClient.cpp +++ b/folly/io/async/test/SocketClient.cpp @@ -65,8 +65,9 @@ int main(int argc, char** argv) { sock.write((const uint8_t*)FLAGS_msg.data(), FLAGS_msg.size()); - LOG(ERROR) << "TFO attempted: " << sockAddr->getTFOAttempted(); - LOG(ERROR) << "TFO finished: " << sockAddr->getTFOFinished(); + LOG(INFO) << "TFO attempted: " << sockAddr->getTFOAttempted(); + LOG(INFO) << "TFO finished: " << sockAddr->getTFOFinished(); + LOG(INFO) << "TFO success: " << sockAddr->getTFOSucceded(); std::array buf; int32_t bytesRead = 0; -- 2.34.1