cNetwork: Added an OnError callback for listening servers.
The callback receives the error details.
This commit is contained in:
parent
646e636933
commit
7cddb62374
@ -841,6 +841,10 @@ cServerHandleImplPtr cServerHandleImpl::Listen(
|
|||||||
{
|
{
|
||||||
cNetworkSingleton::Get().AddServer(res);
|
cNetworkSingleton::Get().AddServer(res);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
a_ListenCallbacks->OnError(res->m_ErrorCode, res->m_ErrorMsg);
|
||||||
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1062,6 +1066,7 @@ cTCPLink::cTCPLink(cCallbacksPtr a_Callbacks):
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// cNetworkSingleton:
|
// cNetworkSingleton:
|
||||||
|
|
||||||
|
@ -139,6 +139,9 @@ public:
|
|||||||
/** Called when the TCP server created with Listen() accepts an incoming connection.
|
/** Called when the TCP server created with Listen() accepts an incoming connection.
|
||||||
Provides the newly created Link that can be used for communication. */
|
Provides the newly created Link that can be used for communication. */
|
||||||
virtual void OnAccepted(cTCPLink & a_Link) = 0;
|
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;
|
typedef SharedPtr<cListenCallbacks> cListenCallbacksPtr;
|
||||||
|
|
||||||
|
@ -22,6 +22,11 @@ class cEchoServerCallbacks:
|
|||||||
a_Link.Send("Welcome to the simple echo server.\r\n");
|
a_Link.Send("Welcome to the simple echo server.\r\n");
|
||||||
LOGD("Welcome message queued.");
|
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());
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user