Add stop_listening()

This commit is contained in:
2025-04-19 14:39:33 +02:00
parent 440837cdbc
commit 4766d4755a
3 changed files with 51 additions and 0 deletions

View File

@@ -24,6 +24,48 @@ TEST(TcpServer, Accept) {
EXPECT_FALSE(server.next_client_available());
}
TEST(TcpServer, RestartListening) {
tcp::NonBlockingServer server;
tcp::NonBlockingClient client;
auto lisRes = server.start_listening(1234);
auto conRes = client.connect({"localhost"}, 1234);
EXPECT_TRUE(server.next_client_available());
auto lisRes2 = server.start_listening(2345);
EXPECT_FALSE(server.next_client_available());
auto conRes2 = client.connect({"localhost"}, 2345);
EXPECT_TRUE(server.next_client_available());
auto statRes2 = client.get_last_connection_status();
if (!statRes2) return;
EXPECT_EQ(statRes2.value(), EISCONN);
}
TEST(TcpServer, StopListening) {
tcp::NonBlockingServer server;
tcp::NonBlockingClient client;
auto lisRes = server.start_listening(1234);
auto conRes = client.connect({"localhost"}, 1234);
EXPECT_TRUE(server.next_client_available());
server.stop_listening();
EXPECT_FALSE(server.next_client_available());
auto conRes2 = client.connect({"localhost"}, 1234);
EXPECT_EQ(client.get_last_connection_status().value(), ECONNREFUSED);
}
TEST(TcpServer, DataAvailable) {
tcp::NonBlockingServer server;
tcp::NonBlockingClient client;