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

# Conflicts:
#	src/common/constants.h
  • Loading branch information
albar965 committed Jun 6, 2022
1 parent d62982a commit b0b2ab2
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 36 deletions.
46 changes: 26 additions & 20 deletions src/common/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -268,26 +268,32 @@ const QLatin1Literal OPTIONS_DIALOG_WEB_DOCROOT_DLG("OptionsDialog/WebDocroot");
const QLatin1Literal OPTIONS_DIALOG_RANGE_DISTANCES("OptionsDialog/RangeDistances");

/* Other options that are only accessible in the configuration file */
const QLatin1Literal OPTIONS_DIALOG_LANGUAGE("OptionsDialog/Language");
const QLatin1Literal OPTIONS_DIALOG_FONT("OptionsDialog/Font");
const QLatin1Literal OPTIONS_DIALOG_MAP_FONT("OptionsDialog/MapFont");
const QLatin1Literal OPTIONS_PIXMAP_CACHE("Options/PixmapCache");
const QLatin1Literal OPTIONS_MARBLE_DEBUG("Options/MarbleDebug");
const QLatin1Literal OPTIONS_CONNECTCLIENT_DEBUG("Options/ConnectClientDebug");
const QLatin1Literal OPTIONS_MAPWIDGET_DEBUG("Options/MapWidgetDebug");
const QLatin1Literal OPTIONS_DOCKHANDLER_DEBUG("Options/DockHandlerDebug");
const QLatin1Literal OPTIONS_WHAZZUP_PARSER_DEBUG("Options/WhazzupParserDebug");
const QLatin1Literal OPTIONS_DATAREADER_DEBUG("Options/DataReaderDebug");
const QLatin1Literal OPTIONS_WEATHER_DEBUG("Options/WeatherDebug");
const QLatin1Literal OPTIONS_ONLINE_NETWORK_DEBUG("Options/OnlineNetworkDebug");
const QLatin1Literal OPTIONS_TRACK_DEBUG("Options/TrackDebug");
const QLatin1Literal OPTIONS_WEATHER_LEVELS("Options/WeatherLevels");
const QLatin1Literal OPTIONS_WIND_DEBUG("Options/WindDebug");
const QLatin1Literal OPTIONS_WEBSERVER_DEBUG("Options/WebserverDebug");
const QLatin1Literal OPTIONS_VERSION("Options/Version");
const QLatin1Literal OPTIONS_NO_USER_AGENT("Options/NoUserAgent");
const QLatin1Literal OPTIONS_WEATHER_UPDATE("Options/WeatherUpdate");
const QLatin1Literal OPTIONS_PROFILE_SIMPLYFY("Options/SimplifyProfile");
const QLatin1String OPTIONS_DIALOG_LANGUAGE("OptionsDialog/Language");
const QLatin1String OPTIONS_DIALOG_FONT("OptionsDialog/Font");
const QLatin1String OPTIONS_DIALOG_MAP_FONT("OptionsDialog/MapFont");
const QLatin1String OPTIONS_PIXMAP_CACHE("Options/PixmapCache");
const QLatin1String OPTIONS_MARBLE_DEBUG("Options/MarbleDebug");
const QLatin1String OPTIONS_CONNECTCLIENT_DEBUG("Options/ConnectClientDebug");
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");
const QLatin1String OPTIONS_MAP_LAYER_DEBUG("Options/MapLayerDebug");
const QLatin1String OPTIONS_ONLINE_NETWORK_DEBUG("Options/OnlineNetworkDebug");
const QLatin1String OPTIONS_TRACK_DEBUG("Options/TrackDebug");
const QLatin1String OPTIONS_WEATHER_LEVELS("Options/WeatherLevels");
const QLatin1String OPTIONS_WIND_DEBUG("Options/WindDebug");
const QLatin1String OPTIONS_WEBSERVER_DEBUG("Options/WebserverDebug");
const QLatin1String OPTIONS_VERSION("Options/Version");
const QLatin1String OPTIONS_NO_USER_AGENT("Options/NoUserAgent");
const QLatin1String OPTIONS_WEATHER_UPDATE("Options/WeatherUpdate");
const QLatin1String OPTIONS_PROFILE_SIMPLYFY("Options/SimplifyProfile");

/* Track download URLs */
const QLatin1Literal OPTIONS_TRACK_NAT_URL("Track/NatUrl");
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 @@ -748,7 +772,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 b0b2ab2

Please sign in to comment.