From 71036bf6b168ecd9c4bd524cd1ec820211df29f8 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 27 Sep 2021 18:35:50 +0200 Subject: [PATCH] something wrong with the socket.. --- src/fsfw/osal/common/TcpTmTcServer.cpp | 17 ++++++++++++++++- src/fsfw/osal/common/TcpTmTcServer.h | 2 +- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/fsfw/osal/common/TcpTmTcServer.cpp b/src/fsfw/osal/common/TcpTmTcServer.cpp index fbbf83e4..9c5a8304 100644 --- a/src/fsfw/osal/common/TcpTmTcServer.cpp +++ b/src/fsfw/osal/common/TcpTmTcServer.cpp @@ -135,6 +135,7 @@ ReturnValue_t TcpTmTcServer::performOperation(uint8_t opCode) { handleServerOperation(connSocket); + sif::debug << "Shutting down" << std::endl; // Done, shut down connection and go back to listening for client requests retval = shutdown(connSocket, SHUT_BOTH); if(retval != 0) { @@ -157,7 +158,7 @@ ReturnValue_t TcpTmTcServer::initializeAfterTaskCreation() { return HasReturnvaluesIF::RETURN_OK; } -void TcpTmTcServer::handleServerOperation(socket_t connSocket) { +void TcpTmTcServer::handleServerOperation(socket_t& connSocket) { //int retval = 0; using namespace std::chrono_literals; @@ -198,12 +199,23 @@ void TcpTmTcServer::handleServerOperation(socket_t connSocket) { // } // } while(retval > 0); while (true) { + sif::debug << "polling fd.." << std::endl; int retval = select(nfds, &rfds, nullptr, &efds, &tv); + // data available + int test = recv( + connSocket, + reinterpret_cast(receptionBuffer.data()), + receptionBuffer.capacity(), + tcpConfig.tcpFlags + ); + sif::debug << "Received " << retval << " bytes" << std::endl; if(retval < 0) { // client might have shut down connection return; } + else if(retval > 0) { + sif::debug << "some descriptor set.." << std::endl; if(FD_ISSET(connSocket, &rfds)) { // data available int retval = recv( @@ -212,6 +224,7 @@ void TcpTmTcServer::handleServerOperation(socket_t connSocket) { receptionBuffer.capacity(), tcpConfig.tcpFlags ); + sif::debug << "Received " << retval << " bytes" << std::endl; ringBuffer.writeData(receptionBuffer.data(), retval); } if(FD_ISSET(connSocket, &efds)) { @@ -229,7 +242,9 @@ void TcpTmTcServer::handleServerOperation(socket_t connSocket) { bool tcAvailable = false; bool tmSent = false; size_t availableReadData = ringBuffer.getAvailableReadData(); + //sif::debug << "ring buffer data: " << availableReadData << std::endl; if(availableReadData > lastRingBufferSize) { + sif::debug << "ring buffer size changed" << std::endl; tcAvailable = true; handleRingBufferData(availableReadData); } diff --git a/src/fsfw/osal/common/TcpTmTcServer.h b/src/fsfw/osal/common/TcpTmTcServer.h index 64785a46..ff7757d0 100644 --- a/src/fsfw/osal/common/TcpTmTcServer.h +++ b/src/fsfw/osal/common/TcpTmTcServer.h @@ -126,7 +126,7 @@ private: SpacePacketParser* spacePacketParser = nullptr; uint8_t lastRingBufferSize = 0; - void handleServerOperation(socket_t connSocket); + void handleServerOperation(socket_t& connSocket); ReturnValue_t handleTcReception(uint8_t* spacePacket, size_t packetSize); ReturnValue_t handleTmSending(socket_t connSocket, bool& tmSent); ReturnValue_t handleRingBufferData(size_t availableReadData);