Skip to content

Commit

Permalink
Add TestTCPClientDisconnectImmediatelyIssue172
Browse files Browse the repository at this point in the history
  • Loading branch information
zieckey committed Oct 16, 2018
1 parent bc257a5 commit d95ace5
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions test/tcp_client_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,23 @@ TEST_UNIT(testTCPClientConnectLocalhost) {



TEST_UNIT(TestTCPClientDisconnectImmediatelyIssue172) {
const std::string strAddr = "qup.f.360.cn:80";
evpp::EventLoop loop;
evpp::TCPClient client(&loop, strAddr, "TestClient");
client.SetConnectionCallback([&loop, &client](const evpp::TCPConnPtr& conn) {
if (conn->IsConnected()) {
auto f = [&]() {
client.Disconnect();
loop.Stop();
};
loop.RunAfter(evpp::Duration(1.0), f);
}
}
);
client.SetMessageCallback([](const evpp::TCPConnPtr& conn, evpp::Buffer* buf) {
std::string strMsg = buf->NextAllString();
});
client.Connect();
loop.Run();
}

0 comments on commit d95ace5

Please sign in to comment.