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); handleServerOperation(connSocket);
sif::debug << "Shutting down" << std::endl;
// Done, shut down connection and go back to listening for client requests // Done, shut down connection and go back to listening for client requests
retval = shutdown(connSocket, SHUT_BOTH); retval = shutdown(connSocket, SHUT_BOTH);
if(retval != 0) { if(retval != 0) {
@ -157,7 +158,7 @@ ReturnValue_t TcpTmTcServer::initializeAfterTaskCreation() {
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} }
void TcpTmTcServer::handleServerOperation(socket_t connSocket) { void TcpTmTcServer::handleServerOperation(socket_t& connSocket) {
//int retval = 0; //int retval = 0;
using namespace std::chrono_literals; using namespace std::chrono_literals;
@ -198,12 +199,23 @@ void TcpTmTcServer::handleServerOperation(socket_t connSocket) {
// } // }
// } while(retval > 0); // } while(retval > 0);
while (true) { while (true) {
sif::debug << "polling fd.." << std::endl;
int retval = select(nfds, &rfds, nullptr, &efds, &tv); 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) { if(retval < 0) {
// client might have shut down connection // client might have shut down connection
return; return;
} }
else if(retval > 0) { else if(retval > 0) {
sif::debug << "some descriptor set.." << std::endl;
if(FD_ISSET(connSocket, &rfds)) { if(FD_ISSET(connSocket, &rfds)) {
// data available // data available
int retval = recv( int retval = recv(
@ -212,6 +224,7 @@ void TcpTmTcServer::handleServerOperation(socket_t connSocket) {
receptionBuffer.capacity(), receptionBuffer.capacity(),
tcpConfig.tcpFlags tcpConfig.tcpFlags
); );
sif::debug << "Received " << retval << " bytes" << std::endl;
ringBuffer.writeData(receptionBuffer.data(), retval); ringBuffer.writeData(receptionBuffer.data(), retval);
} }
if(FD_ISSET(connSocket, &efds)) { if(FD_ISSET(connSocket, &efds)) {
@ -229,7 +242,9 @@ void TcpTmTcServer::handleServerOperation(socket_t connSocket) {
bool tcAvailable = false; bool tcAvailable = false;
bool tmSent = false; bool tmSent = false;
size_t availableReadData = ringBuffer.getAvailableReadData(); size_t availableReadData = ringBuffer.getAvailableReadData();
//sif::debug << "ring buffer data: " << availableReadData << std::endl;
if(availableReadData > lastRingBufferSize) { if(availableReadData > lastRingBufferSize) {
sif::debug << "ring buffer size changed" << std::endl;
tcAvailable = true; tcAvailable = true;
handleRingBufferData(availableReadData); handleRingBufferData(availableReadData);
} }

View File

@ -126,7 +126,7 @@ private:
SpacePacketParser* spacePacketParser = nullptr; SpacePacketParser* spacePacketParser = nullptr;
uint8_t lastRingBufferSize = 0; 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 handleTcReception(uint8_t* spacePacket, size_t packetSize);
ReturnValue_t handleTmSending(socket_t connSocket, bool& tmSent); ReturnValue_t handleTmSending(socket_t connSocket, bool& tmSent);
ReturnValue_t handleRingBufferData(size_t availableReadData); ReturnValue_t handleRingBufferData(size_t availableReadData);