added generic error handler

This commit is contained in:
2021-03-08 23:14:10 +01:00
parent 4e5e6e145e
commit 8be4f45969
4 changed files with 47 additions and 19 deletions

View File

@ -9,25 +9,39 @@ TcWinTcpServer::TcWinTcpServer(object_id_t objectId, object_id_t tmtcUnixUdpBrid
if(serverTcpSocket == 0) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "TcWinTcpServer::TcWinTcpServer: Socket creation failed!" << std::endl;
handleSocketError();
handleError(ErrorSources::SOCKET_CALL);
#endif
}
setsockopt(serverTcpSocket, SOL_SOCKET, SO_REUSEADDR | SO_BROADCAST,
&tcpSockOpt, sizeof(tcpSockOpt));
int retval = setsockopt(serverTcpSocket, SOL_SOCKET, SO_REUSEADDR | SO_BROADCAST,
reinterpret_cast<const char*>(&tcpSockOpt), sizeof(tcpSockOpt));
if(retval != 0) {
}
}
TcWinTcpServer::~TcWinTcpServer() {
}
void TcWinTcpServer::handleSocketError() {
void TcWinTcpServer::handleError(ErrorSources errorSrc) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
int errCode = WSAGetLastError();
std::string errorSrcString;
if(errorSrc == ErrorSources::SETSOCKOPT_CALL) {
errorSrcString = "setsockopt call";
}
else if(errorSrc == ErrorSources::SOCKET_CALL) {
errorSrcString = "socket call";
}
switch(errCode) {
case(WSANOTINITIALISED): {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "TmTcWinUdpBridge::handleSocketError: WSANOTINITIALISED: WSAStartup"
" call necessary" << std::endl;
#endif
sif::warning << "TmTcWinUdpBridge::handleError: " << errorSrcString << " | "
"WSANOTINITIALISED: WSAStartup call necessary" << std::endl;
break;
}
case(WSAEINVAL): {
sif::warning << "TmTcWinUdpBridge::handleError: " << errorSrcString << " | "
"WSAEINVAL: Invalid parameters" << std::endl;
break;
}
default: {
@ -35,12 +49,9 @@ void TcWinTcpServer::handleSocketError() {
https://docs.microsoft.com/en-us/windows/win32/winsock/
windows-sockets-error-codes-2
*/
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "TmTcWinUdpBridge::handleSocketError: Error code: " << errCode << std::endl;
#endif
break;
}
}
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
}