generic windows udp bridge working as well

This commit is contained in:
Robin Müller 2021-03-21 14:38:28 +01:00
parent b5a14bb9df
commit 078116c7be
4 changed files with 28 additions and 29 deletions

View File

@ -8,32 +8,16 @@
#endif #endif
TcpIpBase::TcpIpBase() { TcpIpBase::TcpIpBase() {
closeSocket(serverSocket);
} }
TcpIpBase::~TcpIpBase() { TcpIpBase::~TcpIpBase() {
closeSocket(serverSocket);
#ifdef _WIN32 #ifdef _WIN32
WSACleanup(); WSACleanup();
#endif #endif
} }
int TcpIpBase::closeSocket(socket_t socket) {
#ifdef _WIN32
return closesocket(socket);
#elif defined(__unix__)
return close(socket);
#endif
}
int TcpIpBase::getLastSocketError() {
#ifdef _WIN32
return WSAGetLastError();
#elif defined(__unix__)
return errno;
#endif
}
ReturnValue_t TcpIpBase::initialize() { ReturnValue_t TcpIpBase::initialize() {
#ifdef _WIN32 #ifdef _WIN32
/* Initiates Winsock DLL. */ /* Initiates Winsock DLL. */
@ -51,3 +35,20 @@ ReturnValue_t TcpIpBase::initialize() {
#endif #endif
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} }
int TcpIpBase::closeSocket(socket_t socket) {
#ifdef _WIN32
return closesocket(socket);
#elif defined(__unix__)
return close(socket);
#endif
}
int TcpIpBase::getLastSocketError() {
#ifdef _WIN32
return WSAGetLastError();
#elif defined(__unix__)
return errno;
#endif
}

View File

@ -154,7 +154,7 @@ ReturnValue_t UdpTcPollingTask::initializeAfterTaskCreation() {
void UdpTcPollingTask::setTimeout(double timeoutSeconds) { void UdpTcPollingTask::setTimeout(double timeoutSeconds) {
#ifdef _WIN32 #ifdef _WIN32
DWORD timeoutMs = timeoutSeconds * 1000.0; DWORD timeoutMs = timeoutSeconds * 1000.0;
int result = setsockopt(serverUdpSocket, SOL_SOCKET, SO_RCVTIMEO, int result = setsockopt(serverSocket, SOL_SOCKET, SO_RCVTIMEO,
reinterpret_cast<const char*>(&timeoutMs), sizeof(DWORD)); reinterpret_cast<const char*>(&timeoutMs), sizeof(DWORD));
if(result == -1) { if(result == -1) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1

View File

@ -65,19 +65,11 @@ ReturnValue_t UdpTmTcBridge::initialize() {
#endif #endif
struct addrinfo *addrResult = nullptr; struct addrinfo *addrResult = nullptr;
struct addrinfo hints = { 0 }; struct addrinfo hints = {};
hints.ai_family = AF_INET; hints.ai_family = AF_INET;
hints.ai_socktype = SOCK_DGRAM; hints.ai_socktype = SOCK_DGRAM;
hints.ai_protocol = IPPROTO_UDP; hints.ai_protocol = IPPROTO_UDP;
//#ifdef _WIN32
// /* See:
// https://docs.microsoft.com/en-us/windows/win32/api/ws2tcpip/nf-ws2tcpip-getaddrinfo
// and
//
// for information about AI_PASSIVE. */
// hints.ai_flags = AI_PASSIVE;
//#endif
/* Set up UDP socket: /* Set up UDP socket:
https://en.wikipedia.org/wiki/Getaddrinfo https://en.wikipedia.org/wiki/Getaddrinfo

View File

@ -4,8 +4,14 @@
#include "TcpIpBase.h" #include "TcpIpBase.h"
#include "../../tmtcservices/TmTcBridge.h" #include "../../tmtcservices/TmTcBridge.h"
#ifdef __unix__ #ifdef _WIN32
#include <ws2tcpip.h>
#elif defined(__unix__)
#include <sys/socket.h> #include <sys/socket.h>
#endif #endif
#include <string> #include <string>