2021-03-08 23:00:53 +01:00
|
|
|
#include "TcWinTcpServer.h"
|
|
|
|
#include "../../serviceinterface/ServiceInterface.h"
|
|
|
|
#include <winsock2.h>
|
|
|
|
|
|
|
|
TcWinTcpServer::TcWinTcpServer(object_id_t objectId, object_id_t tmtcUnixUdpBridge):
|
|
|
|
SystemObject(objectId) {
|
|
|
|
/* Open TCP socket */
|
|
|
|
serverTcpSocket = socket(AF_INET, SOCK_STREAM, 0);
|
|
|
|
if(serverTcpSocket == 0) {
|
|
|
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
|
|
|
sif::warning << "TcWinTcpServer::TcWinTcpServer: Socket creation failed!" << std::endl;
|
2021-03-08 23:14:10 +01:00
|
|
|
handleError(ErrorSources::SOCKET_CALL);
|
2021-03-08 23:00:53 +01:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2021-03-08 23:14:10 +01:00
|
|
|
int retval = setsockopt(serverTcpSocket, SOL_SOCKET, SO_REUSEADDR | SO_BROADCAST,
|
|
|
|
reinterpret_cast<const char*>(&tcpSockOpt), sizeof(tcpSockOpt));
|
|
|
|
if(retval != 0) {
|
|
|
|
|
|
|
|
}
|
2021-03-08 23:00:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TcWinTcpServer::~TcWinTcpServer() {
|
|
|
|
}
|
|
|
|
|
2021-03-08 23:14:10 +01:00
|
|
|
void TcWinTcpServer::handleError(ErrorSources errorSrc) {
|
|
|
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
2021-03-08 23:00:53 +01:00
|
|
|
int errCode = WSAGetLastError();
|
2021-03-08 23:14:10 +01:00
|
|
|
std::string errorSrcString;
|
|
|
|
if(errorSrc == ErrorSources::SETSOCKOPT_CALL) {
|
|
|
|
errorSrcString = "setsockopt call";
|
|
|
|
}
|
|
|
|
else if(errorSrc == ErrorSources::SOCKET_CALL) {
|
|
|
|
errorSrcString = "socket call";
|
|
|
|
}
|
2021-03-08 23:00:53 +01:00
|
|
|
switch(errCode) {
|
|
|
|
case(WSANOTINITIALISED): {
|
2021-03-08 23:14:10 +01:00
|
|
|
sif::warning << "TmTcWinUdpBridge::handleError: " << errorSrcString << " | "
|
|
|
|
"WSANOTINITIALISED: WSAStartup call necessary" << std::endl;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case(WSAEINVAL): {
|
|
|
|
sif::warning << "TmTcWinUdpBridge::handleError: " << errorSrcString << " | "
|
|
|
|
"WSAEINVAL: Invalid parameters" << std::endl;
|
2021-03-08 23:00:53 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: {
|
|
|
|
/*
|
|
|
|
https://docs.microsoft.com/en-us/windows/win32/winsock/
|
|
|
|
windows-sockets-error-codes-2
|
|
|
|
*/
|
|
|
|
sif::warning << "TmTcWinUdpBridge::handleSocketError: Error code: " << errCode << std::endl;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2021-03-08 23:14:10 +01:00
|
|
|
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
|
2021-03-08 23:00:53 +01:00
|
|
|
}
|