fsfw/osal/common/TcpIpBase.cpp

54 lines
1.1 KiB
C++
Raw Normal View History

#include "TcpIpBase.h"
2021-05-12 16:47:53 +02:00
#include "../../platform.h"
2021-05-12 16:47:53 +02:00
#ifdef PLATFORM_UNIX
2021-03-21 12:51:28 +01:00
#include <errno.h>
#include <unistd.h>
#endif
TcpIpBase::TcpIpBase() {
}
ReturnValue_t TcpIpBase::initialize() {
#ifdef _WIN32
/* Initiates Winsock DLL. */
WSAData wsaData;
WORD wVersionRequested = MAKEWORD(2, 2);
int err = WSAStartup(wVersionRequested, &wsaData);
if (err != 0) {
/* Tell the user that we could not find a usable Winsock DLL. */
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "TmTcWinUdpBridge::TmTcWinUdpBridge: WSAStartup failed with error: " <<
err << std::endl;
#endif
return HasReturnvaluesIF::RETURN_FAILED;
}
#endif
return HasReturnvaluesIF::RETURN_OK;
}
2021-03-21 16:29:04 +01:00
TcpIpBase::~TcpIpBase() {
closeSocket(serverSocket);
#ifdef _WIN32
WSACleanup();
#endif
}
int TcpIpBase::closeSocket(socket_t socket) {
2021-05-12 16:47:53 +02:00
#ifdef PLATFORM_WIN
return closesocket(socket);
2021-05-12 16:47:53 +02:00
#elif defined(PLATFORM_UNIX)
return close(socket);
#endif
}
int TcpIpBase::getLastSocketError() {
2021-05-12 16:47:53 +02:00
#ifdef PLATFORM_WIN
return WSAGetLastError();
2021-05-12 16:47:53 +02:00
#elif defined(PLATFORM_UNIX)
return errno;
#endif
}