Skip to content

Commit

Permalink
Added configuration file options and increased reconnection timeouts …
Browse files Browse the repository at this point in the history
…to mitigate handler leak. Needs more research. #891
  • Loading branch information
albar965 committed Jun 2, 2022
1 parent a7beb13 commit 21face1
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 16 deletions.
3 changes: 3 additions & 0 deletions src/common/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,9 @@ const QLatin1String OPTIONS_MAPWIDGET_DEBUG("Options/MapWidgetDebug");
const QLatin1String OPTIONS_DOCKHANDLER_DEBUG("Options/DockHandlerDebug");
const QLatin1String OPTIONS_WHAZZUP_PARSER_DEBUG("Options/WhazzupParserDebug");
const QLatin1String OPTIONS_DATAREADER_DEBUG("Options/DataReaderDebug");
const QLatin1String OPTIONS_DATAREADER_RECONNECT_SIM("Options/DataReaderReconnectSim");
const QLatin1String OPTIONS_DATAREADER_RECONNECT_XP("Options/DataReaderReconnectXp");
const QLatin1String OPTIONS_DATAREADER_RECONNECT_SOCKET("Options/DataReaderReconnectSocket");
const QLatin1String OPTIONS_WEATHER_DEBUG("Options/WeatherDebug");
const QLatin1String OPTIONS_MAP_JUMP_BACK_DEBUG("Options/MapJumpBackDebug");
const QLatin1String OPTIONS_PROFILE_JUMP_BACK_DEBUG("Options/ProfileJumpBackDebug");
Expand Down
36 changes: 30 additions & 6 deletions src/connect/connectclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@

using atools::fs::sc::DataReaderThread;

const static int FLUSH_QUEUE_MS = 50;

/* Any metar fetched from the Simulator will time out in 15 seconds */
const static int WEATHER_TIMEOUT_FS_SECS = 15;
const static int NOT_AVAILABLE_TIMEOUT_FS_SECS = 300;

ConnectClient::ConnectClient(MainWindow *parent)
: QObject(parent), mainWindow(parent), metarIdentCache(WEATHER_TIMEOUT_FS_SECS),
notAvailableStations(NOT_AVAILABLE_TIMEOUT_FS_SECS)
Expand All @@ -58,16 +64,22 @@ ConnectClient::ConnectClient(MainWindow *parent)
xpConnectHandler = new atools::fs::sc::XpConnectHandler();

// Create thread class that reads data from handler
dataReader =
new DataReaderThread(mainWindow, settings.getAndStoreValue(lnm::OPTIONS_DATAREADER_DEBUG, false).toBool());
dataReader = new DataReaderThread(mainWindow, settings.getAndStoreValue(lnm::OPTIONS_DATAREADER_DEBUG, false).toBool());

directReconnectSimSec = settings.getAndStoreValue(lnm::OPTIONS_DATAREADER_RECONNECT_SIM, 15).toInt();
directReconnectXpSec = settings.getAndStoreValue(lnm::OPTIONS_DATAREADER_RECONNECT_XP, 5).toInt();
socketReconnectSec = settings.getAndStoreValue(lnm::OPTIONS_DATAREADER_RECONNECT_SOCKET, 10).toInt();

if(simConnectHandler->isLoaded())
{
dataReader->setHandler(simConnectHandler);
dataReader->setReconnectRateSec(directReconnectSimSec);
}
else
{
dataReader->setHandler(xpConnectHandler);

// We were able to connect
dataReader->setReconnectRateSec(DIRECT_RECONNECT_SEC);
dataReader->setReconnectRateSec(directReconnectXpSec);
}

connect(dataReader, &DataReaderThread::postSimConnectData, this, &ConnectClient::postSimConnectData);
connect(dataReader, &DataReaderThread::postStatus, this, &ConnectClient::statusPosted);
Expand Down Expand Up @@ -387,6 +399,12 @@ void ConnectClient::restoreState()
dialog->restoreState();

dataReader->setHandler(handlerByDialogSettings());

if(isXpConnect())
dataReader->setReconnectRateSec(directReconnectXpSec);
else if(isSimConnect())
dataReader->setReconnectRateSec(directReconnectSimSec);

dataReader->setUpdateRate(dialog->getUpdateRateMs(dialog->getCurrentSimType()));
dataReader->setAiFetchRadius(atools::geo::nmToKm(dialog->getAiFetchRadiusNm(dialog->getCurrentSimType())));
fetchOptionsChanged(dialog->getCurrentSimType());
Expand Down Expand Up @@ -583,9 +601,15 @@ void ConnectClient::connectInternal()
if(dialog->isAnyConnectDirect())
{
qDebug() << "Starting direct connection";

// Datareader has its own reconnect mechanism
dataReader->setHandler(handlerByDialogSettings());

if(isXpConnect())
dataReader->setReconnectRateSec(directReconnectXpSec);
else if(isSimConnect())
dataReader->setReconnectRateSec(directReconnectSimSec);

// Copy settings from dialog
updateRateChanged(dialog->getCurrentSimType());
fetchOptionsChanged(dialog->getCurrentSimType());
Expand Down Expand Up @@ -747,7 +771,7 @@ void ConnectClient::closeSocket(bool allowRestart)
{
// For socket based connection use a timer - direct connection reconnects automatically
silent = true;
reconnectNetworkTimer.start(SOCKET_RECONNECT_SEC * 1000);
reconnectNetworkTimer.start(socketReconnectSec * 1000);
}
else
silent = false;
Expand Down
19 changes: 9 additions & 10 deletions src/connect/connectclient.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,16 +117,6 @@ class ConnectClient :
void aiFetchOptionsChanged();

private:
/* Try to reconnect every 5 seconds when network connection is lost */
const int SOCKET_RECONNECT_SEC = 5;
/* Try to reconnect every 5 seconds when the SimConnect or X-Plane connection is lost */
const int DIRECT_RECONNECT_SEC = 5;
const int FLUSH_QUEUE_MS = 50;

/* Any metar fetched from the Simulator will time out in 15 seconds */
const int WEATHER_TIMEOUT_FS_SECS = 15;
const int NOT_AVAILABLE_TIMEOUT_FS_SECS = 300;

void readFromSocket();
void readFromSocketError(QAbstractSocket::SocketError);
void connectedToServerSocket();
Expand Down Expand Up @@ -188,6 +178,15 @@ class ConnectClient :
bool socketConnected = false;

bool errorState = false;

/* Try to reconnect every 10 seconds when network connection is lost */
int socketReconnectSec = 10;

/* Try to reconnect every 15 seconds when the SimConnect connection is lost */
int directReconnectSimSec = 15;

/* Try to reconnect every 5 seconds when the X-Plane connection is lost */
int directReconnectXpSec = 5;
};

#endif // LITTLENAVMAP_CONNECTCLIENT_H

0 comments on commit 21face1

Please sign in to comment.