fsfw/src/fsfw/osal/common/TcpIpBase.cpp

53 lines
1.1 KiB
C++
Raw Normal View History

2021-07-13 21:02:53 +02:00
#include "fsfw/osal/common/TcpIpBase.h"
2022-02-02 10:29:30 +01:00
2021-07-13 21:02:53 +02:00
#include "fsfw/platform.h"
2022-09-29 16:46:55 +02:00
#include "fsfw/serviceinterface.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
2022-02-02 10:29:30 +01:00
TcpIpBase::TcpIpBase() {}
ReturnValue_t TcpIpBase::initialize() {
#ifdef _WIN32
2022-02-02 10:29:30 +01:00
/* 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
2022-02-02 10:29:30 +01:00
sif::error << "TmTcWinUdpBridge::TmTcWinUdpBridge: WSAStartup failed with error: " << err
<< std::endl;
#endif
2022-08-16 01:08:26 +02:00
return returnvalue::FAILED;
2022-02-02 10:29:30 +01:00
}
#endif
2022-08-16 01:08:26 +02:00
return returnvalue::OK;
}
2021-03-21 16:29:04 +01:00
TcpIpBase::~TcpIpBase() {
2022-02-02 10:29:30 +01:00
closeSocket(serverSocket);
2021-03-21 16:29:04 +01:00
#ifdef _WIN32
2022-02-02 10:29:30 +01:00
WSACleanup();
2021-03-21 16:29:04 +01:00
#endif
}
int TcpIpBase::closeSocket(socket_t socket) {
2021-05-12 16:47:53 +02:00
#ifdef PLATFORM_WIN
2022-02-02 10:29:30 +01:00
return closesocket(socket);
2021-05-12 16:47:53 +02:00
#elif defined(PLATFORM_UNIX)
2022-02-02 10:29:30 +01:00
return close(socket);
#endif
}
int TcpIpBase::getLastSocketError() {
2021-05-12 16:47:53 +02:00
#ifdef PLATFORM_WIN
2022-02-02 10:29:30 +01:00
return WSAGetLastError();
2021-05-12 16:47:53 +02:00
#elif defined(PLATFORM_UNIX)
2022-02-02 10:29:30 +01:00
return errno;
#endif
}