all windows fixes

This commit is contained in:
Robin Müller 2021-09-28 17:26:02 +02:00
parent 5284eadca6
commit d9744365d2
2 changed files with 33 additions and 2 deletions

View File

@ -46,7 +46,9 @@ ReturnValue_t TcpTmTcServer::initialize() {
if(spacePacketParser == nullptr) { if(spacePacketParser == nullptr) {
return HasReturnvaluesIF::RETURN_FAILED; return HasReturnvaluesIF::RETURN_FAILED;
} }
#if defined PLATFORM_UNIX
tcpConfig.tcpFlags |= MSG_DONTWAIT; tcpConfig.tcpFlags |= MSG_DONTWAIT;
#endif
} }
} }
@ -155,6 +157,10 @@ ReturnValue_t TcpTmTcServer::initializeAfterTaskCreation() {
} }
void TcpTmTcServer::handleServerOperation(socket_t& connSocket) { void TcpTmTcServer::handleServerOperation(socket_t& connSocket) {
#if defined PLATFORM_WIN
setSocketNonBlocking(connSocket);
#endif
while (true) { while (true) {
int retval = recv( int retval = recv(
connSocket, connSocket,
@ -172,7 +178,13 @@ void TcpTmTcServer::handleServerOperation(socket_t& connSocket) {
ringBuffer.writeData(receptionBuffer.data(), retval); ringBuffer.writeData(receptionBuffer.data(), retval);
} }
else if(retval < 0) { else if(retval < 0) {
if(errno == EAGAIN) { int errorValue = GetLastError();
#if defined PLATFORM_UNIX
int wouldBlockValue = EAGAIN;
#elif defined PLATFORM_WIN
int wouldBlockValue = WSAEWOULDBLOCK;
#endif
if(errorValue == wouldBlockValue) {
// No data available. Check whether any packets have been read, then send back // No data available. Check whether any packets have been read, then send back
// telemetry if available // telemetry if available
bool tcAvailable = false; bool tcAvailable = false;
@ -191,7 +203,7 @@ void TcpTmTcServer::handleServerOperation(socket_t& connSocket) {
} }
} }
else { else {
tcpip::handleError(tcpip::Protocol::TCP, tcpip::ErrorSources::RECV_CALL); tcpip::handleError(tcpip::Protocol::TCP, tcpip::ErrorSources::RECV_CALL, 300);
} }
} }
} }
@ -375,3 +387,19 @@ void TcpTmTcServer::handleSocketError(ConstStorageAccessor &accessor) {
} }
} }
} }
void TcpTmTcServer::setSocketNonBlocking(socket_t &connSocket) {
u_long iMode = 1;
int iResult = ioctlsocket(connSocket, FIONBIO, &iMode);
if(iResult != NO_ERROR) {
#if FSFW_VERBOSE_LEVEL >= 1
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "TcpTmTcServer::handleServerOperation: Setting socket"
" non-blocking failed with error " << iResult;
#else
sif::printWarning("TcpTmTcServer::handleServerOperation: Setting socket"
" non-blocking failed with error %d\n", iResult);
#endif
#endif
}
}

View File

@ -136,6 +136,9 @@ private:
ReturnValue_t handleTmSending(socket_t connSocket, bool& tmSent); ReturnValue_t handleTmSending(socket_t connSocket, bool& tmSent);
ReturnValue_t handleTcRingBufferData(size_t availableReadData); ReturnValue_t handleTcRingBufferData(size_t availableReadData);
void handleSocketError(ConstStorageAccessor& accessor); void handleSocketError(ConstStorageAccessor& accessor);
#if defined PLATFORM_WIN
void setSocketNonBlocking(socket_t& connSocket);
#endif
}; };
#endif /* FSFW_OSAL_COMMON_TCP_TMTC_SERVER_H_ */ #endif /* FSFW_OSAL_COMMON_TCP_TMTC_SERVER_H_ */