Skip to content

Commit

Permalink
Refactor: Remove Min_Network_Timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
TwinFan committed Dec 8, 2023
1 parent e958f3c commit a9c1b33
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 32 deletions.
4 changes: 0 additions & 4 deletions Include/DataRefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ const bool DEF_SND_FMOD_INST = false; ///< Enforce using our own FMOD
const bool DEF_SND_FMOD_INST = true; ///< Enforce using our own FMOD instance instead of X-Plane's?
#endif
const int DEF_SUI_TRANSP = 0; ///< Settings UI: transaprent background?
const int DEF_MIN_NETW_TIMEOUT = 5; ///< [s] default minimum network request timeout
const int DEF_MAX_NETW_TIMEOUT = 5; ///< [s] default maximum network request timeout


Expand Down Expand Up @@ -382,7 +381,6 @@ enum dataRefsLT {
DR_CFG_FD_LONG_REFRESH_INTVL,
DR_CFG_FD_BUF_PERIOD,
DR_CFG_FD_REDUCE_HEIGHT,
DR_CFG_MIN_NETW_TIMEOUT,
DR_CFG_MAX_NETW_TIMEOUT,
DR_CFG_LND_LIGHTS_TAXI,
DR_CFG_HIDE_BELOW_AGL,
Expand Down Expand Up @@ -686,7 +684,6 @@ class DataRefs
int fdCurrRefrIntvl = DEF_FD_REFRESH_INTVL; ///< current value of how often to fetch new flight data
int fdBufPeriod = DEF_FD_BUF_PERIOD; ///< seconds to buffer before simulating aircraft
int fdReduceHeight = DEF_FD_REDUCE_HEIGHT; ///< [ft] reduce flight data usage when user aircraft is flying above this altitude
int netwTimeoutMin = DEF_MIN_NETW_TIMEOUT; ///< [s] of min network request timeout
int netwTimeoutMax = DEF_MAX_NETW_TIMEOUT; ///< [s] of max network request timeout
int bLndLightsTaxi = false; // keep landing lights on while taxiing? (to be able to see the a/c as there is no taxi light functionality)
int hideBelowAGL = 0; // if positive: a/c visible only above this height AGL
Expand Down Expand Up @@ -924,7 +921,6 @@ class DataRefs
inline int GetFdRefreshIntvl() const { return fdCurrRefrIntvl; }
inline int GetFdBufPeriod() const { return fdBufPeriod; }
inline int GetAcOutdatedIntvl() const { return 2 * GetFdBufPeriod(); }
inline int GetNetwTimeoutMin() const { return netwTimeoutMin; }
inline int GetNetwTimeoutMax() const { return netwTimeoutMax; }
inline bool GetLndLightsTaxi() const { return bLndLightsTaxi != 0; }
inline int GetHideBelowAGL() const { return hideBelowAGL; }
Expand Down
1 change: 0 additions & 1 deletion Include/LTChannel.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ class LTOnlineChannel : public LTChannel
protected:
CURL* pCurl; // handle into CURL
std::string requBody; ///< body of a POST request
int nTimeout; ///< current network timeout of this channel
char* netData; // where the response goes
size_t netDataPos; // current write pos into netData
size_t netDataSize; // current size of netData
Expand Down
5 changes: 1 addition & 4 deletions Src/DataRefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,6 @@ DataRefs::dataRefDefinitionT DATA_REFS_LT[CNT_DATAREFS_LT] = {
{"livetraffic/cfg/fd_long_refresh_intvl", DataRefs::LTGetInt, DataRefs::LTSetCfgValue, GET_VAR, true, true },
{"livetraffic/cfg/fd_buf_period", DataRefs::LTGetInt, DataRefs::LTSetCfgValue, GET_VAR, true, true },
{"livetraffic/cfg/fd_reduce_height", DataRefs::LTGetInt, DataRefs::LTSetCfgValue, GET_VAR, true, true },
{"livetraffic/cfg/network_timeout_min", DataRefs::LTGetInt, DataRefs::LTSetCfgValue, GET_VAR, true },
{"livetraffic/cfg/network_timeout", DataRefs::LTGetInt, DataRefs::LTSetCfgValue, GET_VAR, true },
{"livetraffic/cfg/lnd_lights_taxi", DataRefs::LTGetInt, DataRefs::LTSetCfgValue, GET_VAR, true },
{"livetraffic/cfg/hide_below_agl", DataRefs::LTGetInt, DataRefs::LTSetCfgValue, GET_VAR, true, true },
Expand Down Expand Up @@ -613,7 +612,6 @@ void* DataRefs::getVarAddr (dataRefsLT dr)
case DR_CFG_FD_LONG_REFRESH_INTVL: return &fdLongRefrIntvl;
case DR_CFG_FD_BUF_PERIOD: return &fdBufPeriod;
case DR_CFG_FD_REDUCE_HEIGHT: return &fdReduceHeight;
case DR_CFG_MIN_NETW_TIMEOUT: return &netwTimeoutMin;
case DR_CFG_MAX_NETW_TIMEOUT: return &netwTimeoutMax;
case DR_CFG_LND_LIGHTS_TAXI: return &bLndLightsTaxi;
case DR_CFG_HIDE_BELOW_AGL: return &hideBelowAGL;
Expand Down Expand Up @@ -1711,7 +1709,7 @@ bool DataRefs::SetCfgValue (void* p, int val)
fdBufPeriod < fdLongRefrIntvl || fdBufPeriod > 180 ||
fdReduceHeight < 1000 || fdReduceHeight > 100000||
fdSnapTaxiDist < 0 || fdSnapTaxiDist > 50 ||
netwTimeoutMax < 5 || netwTimeoutMin > netwTimeoutMax ||
netwTimeoutMax < 5 ||
hideBelowAGL < 0 || hideBelowAGL > MDL_ALT_MAX ||
hideNearbyGnd < 0 || hideNearbyGnd > 500 ||
hideNearbyAir < 0 || hideNearbyAir > 5000 ||
Expand Down Expand Up @@ -1778,7 +1776,6 @@ void DataRefs::ResetAdvCfgToDefaults ()
fdLongRefrIntvl = DEF_FD_LONG_REFR_INTVL;
fdBufPeriod = DEF_FD_BUF_PERIOD;
fdReduceHeight = DEF_FD_REDUCE_HEIGHT;
netwTimeoutMin = DEF_MIN_NETW_TIMEOUT;
netwTimeoutMax = DEF_MAX_NETW_TIMEOUT;
contrailAltMin_ft = DEF_CONTR_ALT_MIN;
contrailAltMax_ft = DEF_CONTR_ALT_MAX;
Expand Down
24 changes: 3 additions & 21 deletions Src/LTChannel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,6 @@ std::ofstream LTOnlineChannel::outRaw;
LTOnlineChannel::LTOnlineChannel (dataRefsLT ch, LTChannelType t, const char* chName) :
LTChannel(ch, t, chName),
pCurl(NULL),
nTimeout(dataRefs.GetNetwTimeoutMax()),
netData((char*)malloc(CURL_MAX_WRITE_SIZE)), // initial buffer allocation
netDataPos(0), netDataSize(CURL_MAX_WRITE_SIZE),
curl_errtxt{0}, httpResponse(HTTP_OK)
Expand Down Expand Up @@ -473,7 +472,7 @@ bool LTOnlineChannel::InitCurl ()

// define the handle
curl_easy_setopt(pCurl, CURLOPT_NOSIGNAL, 1);
curl_easy_setopt(pCurl, CURLOPT_TIMEOUT, nTimeout);
curl_easy_setopt(pCurl, CURLOPT_TIMEOUT, dataRefs.GetNetwTimeoutMax());
curl_easy_setopt(pCurl, CURLOPT_ERRORBUFFER, curl_errtxt);
curl_easy_setopt(pCurl, CURLOPT_WRITEFUNCTION, LTOnlineChannel::ReceiveData);
curl_easy_setopt(pCurl, CURLOPT_WRITEDATA, this);
Expand Down Expand Up @@ -620,7 +619,7 @@ bool LTOnlineChannel::FetchAllData (const positionTy& pos)
// put together the REST request
curl_easy_setopt(pCurl, CURLOPT_URL, url.c_str());
curl_easy_setopt(pCurl, CURLOPT_BUFFERSIZE, netDataSize );
curl_easy_setopt(pCurl, CURLOPT_TIMEOUT, nTimeout);
curl_easy_setopt(pCurl, CURLOPT_TIMEOUT, dataRefs.GetNetwTimeoutMax());

// Set up the request
curl_easy_setopt(pCurl, CURLOPT_NOBODY, 0);
Expand Down Expand Up @@ -670,14 +669,6 @@ bool LTOnlineChannel::FetchAllData (const positionTy& pos)
LOG_MSG(logWARN, ERR_CURL_PERFORM, ChName(), cc, curl_errtxt);
tLastMsg = now;
}
// Increase the timeout
// TODO: Remove the timeout adaptation logic including the second timeout setting
const int prevTimeout = nTimeout;
nTimeout = std::min (nTimeout * 2, // double the timeout
dataRefs.GetNetwTimeoutMax());
if (nTimeout > prevTimeout) {
LOG_MSG(logWARN, "%s: Timeout increased to %ds", ChName(), nTimeout);
}
} else {
SHOW_MSG(logERR, ERR_CURL_PERFORM, ChName(), cc, curl_errtxt);
IncErrCnt();
Expand All @@ -690,17 +681,8 @@ bool LTOnlineChannel::FetchAllData (const positionTy& pos)
curl_easy_getinfo(pCurl, CURLINFO_RESPONSE_CODE, &httpResponse);
switch (httpResponse) {
case HTTP_OK:
// Based on actual time take set a new network timeout as twice the response time
{
const std::chrono::seconds d = std::chrono::duration_cast<std::chrono::seconds>(tEnd - tStart);
// In case of a reduction we reduce to no less than half the previous value,
// keep value between min/max network timeout
nTimeout = std::clamp<int> ((int)d.count() * 2,
std::max(dataRefs.GetNetwTimeoutMin(),nTimeout/2),
dataRefs.GetNetwTimeoutMax());
// LOG_MSG(logWARN, "%s: Timeout set to %ds", ChName(), nTimeout);
break;
}

case HTTP_NOT_FOUND:
// not found is typically handled separately, so only debug-level
LOG_MSG(logDEBUG,ERR_CURL_HTTP_RESP,ChName(),httpResponse, url.c_str());
Expand Down
3 changes: 1 addition & 2 deletions Src/SettingsUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -791,8 +791,7 @@ void LTSettingsUI::buildInterface()
ImGui::FilteredCfgNumber("Above height AGL of", sFilter, DR_CFG_FD_REDUCE_HEIGHT, 1000, 100000, 1000, "%d ft");
ImGui::FilteredCfgNumber("increase refresh to", sFilter, DR_CFG_FD_LONG_REFRESH_INTVL, 10, 180, 5, "%d s");
ImGui::FilteredCfgNumber("Buffering period", sFilter, DR_CFG_FD_BUF_PERIOD, 10, 180, 5, "%d s");
ImGui::FilteredCfgNumber("Min. Network timeout", sFilter, DR_CFG_MIN_NETW_TIMEOUT, 5, 180, 5, "%d s");
ImGui::FilteredCfgNumber("Max. Network timeout", sFilter, DR_CFG_MAX_NETW_TIMEOUT, 5, 180, 5, "%d s");
ImGui::FilteredCfgNumber("Network timeout", sFilter, DR_CFG_MAX_NETW_TIMEOUT, 5, 180, 5, "%d s");

if (!*sFilter) ImGui::TreePop();
}
Expand Down

0 comments on commit a9c1b33

Please sign in to comment.