From d8ac99a0374b528caca66ad8ecb5fb36f6334e77 Mon Sep 17 00:00:00 2001 From: Mattes D Date: Mon, 12 Jan 2015 14:58:52 +0100 Subject: cNetwork: Implemented connection shutdown and close. --- tests/Network/EchoServer.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/Network/EchoServer.cpp b/tests/Network/EchoServer.cpp index 3d9a6228d..1e0ac023f 100644 --- a/tests/Network/EchoServer.cpp +++ b/tests/Network/EchoServer.cpp @@ -38,6 +38,16 @@ class cEchoLinkCallbacks: LOGD("%p (%s:%d): Data received (%u bytes), echoing back.", &a_Link, a_Link.GetRemoteIP().c_str(), a_Link.GetRemotePort(), static_cast(a_Size)); a_Link.Send(a_Data, a_Size); LOGD("Echo queued"); + + // Search for a Ctrl+Z, if found, drop the connection: + for (size_t i = 0; i < a_Size; i++) + { + if (a_Data[i] == '\x1a') + { + a_Link.Close(); + return; + } + } } virtual void OnRemoteClosed(cTCPLink & a_Link) override @@ -67,7 +77,7 @@ int main() ASSERT(Server->IsListening()); // Wait for the user to terminate the server: - printf("Press enter to terminate the server.\n"); + printf("Press enter to close the server.\n"); AString line; std::getline(std::cin, line); @@ -75,6 +85,10 @@ int main() LOG("Server terminating."); Server->Close(); ASSERT(!Server->IsListening()); + LOGD("Server has been closed."); + + printf("Press enter to exit test.\n"); + std::getline(std::cin, line); LOG("Network test finished."); return 0; -- cgit v1.2.3