Skip to content

Commit

Permalink
Add more verbose comments and reconnect if connfd is invalid during send
Browse files Browse the repository at this point in the history
  • Loading branch information
Andy committed Jan 18, 2025
1 parent 34eb9af commit 25cd78e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
20 changes: 18 additions & 2 deletions decode/decode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include "aerol.h"
#include "decode.h"
#include "forwarder.h"
#include "logger.h"
#include "mskdemodulator.h"
#include "oqpskdemodulator.h"
Expand Down Expand Up @@ -255,8 +256,10 @@ void Decoder::publisherConsumer() {
::free(samplesBuf);
}

DBG("Waiting for forwarder consumer to get the hint to exit");
forwarderThread.waitForFinished();

DBG("Forwarder consumer exited");
emit completed();
}

Expand All @@ -270,9 +273,22 @@ void Decoder::forwarderConsumer() {
while (running.loadAcquire()) {
sendBufferRwLock.lockForRead();
if (sendBuffer.isEmpty()) {
sendBufferCondition.wait(&sendBufferRwLock);
DBG("No items in sendBuffer, forwarder consumer waiting a second for next item add");
sendBufferCondition.wait(&sendBufferRwLock, QDeadlineTimer(MAX_CONNECTION_WAIT_MS));
if (!running.loadAcquire()) {
sendBufferRwLock.unlock();
break;
}

if (sendBuffer.isEmpty()) {
DBG("Still nothing, trying for another wait");
sendBufferRwLock.unlock();
continue;
}
}

DBG("sendBuffer is populated with %lld items for processing", sendBuffer.size());

ACARSItem item = sendBuffer.front();
sendBuffer.pop_front();
sendBufferRwLock.unlock();
Expand Down Expand Up @@ -312,7 +328,7 @@ void Decoder::handleDcdChange(bool old_state, bool new_state) {
}

void Decoder::handleNewFreqCenter(double freq_center) {
DBG("Trying frequency center %.2f in search of signal", freq_center);
DBG("Trying frequency center %.1f in search of signal", freq_center);
}

void Decoder::handleACARS(ACARSItem &item) {
Expand Down
11 changes: 9 additions & 2 deletions decode/forwarder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ void ForwardTarget::reconnect() {
addrinfo *servinfo = nullptr;
addrinfo *p = nullptr;

DBG("Attempting to connect to forwarder target %s", target.toString().toStdString().c_str());

if (servinfo != nullptr) {
::freeaddrinfo(servinfo);
servinfo = nullptr;
Expand Down Expand Up @@ -83,9 +85,9 @@ void ForwardTarget::reconnect() {

Exit:
if (connfd == -1) {
DBG("Failed to connect to forwarder target %s", target.toString().toStdString().c_str());
DBG("Failed to connect to forwarder target");
} else {
DBG("Connected to forwarder target %s", target.toString().toStdString().c_str());
DBG("Connected to forwarder target");
}
}

Expand All @@ -107,6 +109,11 @@ int ForwardTarget::sendFrame(const QByteArray &data) {
void ForwardTarget::send(const QByteArray &data) {
DBG("Attempting to send %lld bytes to forwarding target %s", data.size(), target.toString().toStdString().c_str());

if (connfd == -1) {
DBG("Invalid socket detected, attempting reconnect");
reconnect();
}

int bytesWritten = sendFrame(data);
if (bytesWritten == -1) {
reconnect();
Expand Down

0 comments on commit 25cd78e

Please sign in to comment.