something wrong with the socket..

This commit is contained in:
Robin Müller 2021-09-27 18:35:50 +02:00
parent d6b3167922
commit 71036bf6b1
No known key found for this signature in database
GPG Key ID: 11D4952C8CCEF814
2 changed files with 17 additions and 2 deletions

View File

@ -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<char*>(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);
}

View File

@ -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);