diff options
author | Mattes D <github@xoft.cz> | 2015-01-15 21:10:14 +0100 |
---|---|---|
committer | Mattes D <github@xoft.cz> | 2015-01-22 20:12:57 +0100 |
commit | 7cddb6237418f2d7ec984cd0d4cbdac7140330b0 (patch) | |
tree | af556ec335cf43ab0adeedd9bf86e4995b072b5c | |
parent | cNetwork: Rewritten server listen into a factory method. (diff) | |
download | cuberite-7cddb6237418f2d7ec984cd0d4cbdac7140330b0.tar cuberite-7cddb6237418f2d7ec984cd0d4cbdac7140330b0.tar.gz cuberite-7cddb6237418f2d7ec984cd0d4cbdac7140330b0.tar.bz2 cuberite-7cddb6237418f2d7ec984cd0d4cbdac7140330b0.tar.lz cuberite-7cddb6237418f2d7ec984cd0d4cbdac7140330b0.tar.xz cuberite-7cddb6237418f2d7ec984cd0d4cbdac7140330b0.tar.zst cuberite-7cddb6237418f2d7ec984cd0d4cbdac7140330b0.zip |
-rw-r--r-- | src/OSSupport/Network.cpp | 5 | ||||
-rw-r--r-- | src/OSSupport/Network.h | 3 | ||||
-rw-r--r-- | tests/Network/EchoServer.cpp | 5 |
3 files changed, 13 insertions, 0 deletions
diff --git a/src/OSSupport/Network.cpp b/src/OSSupport/Network.cpp index af63c75d0..4dc8d1df1 100644 --- a/src/OSSupport/Network.cpp +++ b/src/OSSupport/Network.cpp @@ -841,6 +841,10 @@ cServerHandleImplPtr cServerHandleImpl::Listen( { cNetworkSingleton::Get().AddServer(res); } + else + { + a_ListenCallbacks->OnError(res->m_ErrorCode, res->m_ErrorMsg); + } return res; } @@ -1062,6 +1066,7 @@ cTCPLink::cTCPLink(cCallbacksPtr a_Callbacks): + //////////////////////////////////////////////////////////////////////////////// // cNetworkSingleton: diff --git a/src/OSSupport/Network.h b/src/OSSupport/Network.h index 11c45b152..cb5badaeb 100644 --- a/src/OSSupport/Network.h +++ b/src/OSSupport/Network.h @@ -139,6 +139,9 @@ public: /** Called when the TCP server created with Listen() accepts an incoming connection. Provides the newly created Link that can be used for communication. */ virtual void OnAccepted(cTCPLink & a_Link) = 0; + + /** Called when the socket fails to listen on the specified port. */ + virtual void OnError(int a_ErrorCode, const AString & a_ErrorMsg) = 0; }; typedef SharedPtr<cListenCallbacks> cListenCallbacksPtr; diff --git a/tests/Network/EchoServer.cpp b/tests/Network/EchoServer.cpp index 1e0ac023f..333c31e08 100644 --- a/tests/Network/EchoServer.cpp +++ b/tests/Network/EchoServer.cpp @@ -22,6 +22,11 @@ class cEchoServerCallbacks: a_Link.Send("Welcome to the simple echo server.\r\n"); LOGD("Welcome message queued."); } + + virtual void OnError(int a_ErrorCode, const AString & a_ErrorMsg) override + { + LOGWARNING("An error occured while listening for connections: %d (%s).", a_ErrorCode, a_ErrorMsg.c_str()); + } }; |