Skip to content

Commit

Permalink
Track 32 latency values
Browse files Browse the repository at this point in the history
  • Loading branch information
Soreepeong committed Feb 18, 2021
1 parent 8c52d61 commit eb3273f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
7 changes: 4 additions & 3 deletions XivAlexander/App_Network_IcmpPingTracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ struct ConnectionPair {
static std::unique_ptr<App::Network::IcmpPingTracker> s_instance;
static std::mutex s_latestKnownLatencyLock;
static std::map<ConnectionPair, std::vector<uint64_t>> s_latestKnownLatency;
static const int LatencyTrackCount = 16;
static const int LatencyTrackCount = 32;

class App::Network::IcmpPingTracker::Implementation {
public:
Expand Down Expand Up @@ -62,7 +62,7 @@ class App::Network::IcmpPingTracker::Implementation {
DWORD waitTime;
size_t successCount = 0;
do {
const auto interval = successCount > 16 ? 10000 : 1000;
const auto interval = successCount > LatencyTrackCount ? 10000 : 1000;
const auto startTime = Utils::GetHighPerformanceCounter();
const auto ok = IcmpSendEcho2Ex(hIcmp, nullptr, nullptr, nullptr, info.Pair.Source.S_un.S_addr, info.Pair.Destination.S_un.S_addr, SendBuf, sizeof SendBuf, nullptr, ReplyBuf, sizeof ReplyBuf, interval);
const auto endTime = Utils::GetHighPerformanceCounter();
Expand All @@ -75,7 +75,8 @@ class App::Network::IcmpPingTracker::Implementation {
const auto newPos = list.empty() ? 0 : std::upper_bound(list.begin(), list.end(), latency) - list.begin();
list.insert(list.begin() + newPos, latency);
if (list.size() > LatencyTrackCount) {
if (newPos >= LatencyTrackCount / 2)
// try to send new item to middle
if (newPos < LatencyTrackCount / 2)
list.pop_back();
else
list.erase(list.begin());
Expand Down
5 changes: 3 additions & 2 deletions XivAlexander/App_Network_SocketHook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ class App::Network::SingleConnection::Internals {
std::map<size_t, std::vector<std::function<bool(Structures::FFXIVMessage*, std::vector<uint8_t>&)>>> m_incomingHandlers;
std::map<size_t, std::vector<std::function<bool(Structures::FFXIVMessage*, std::vector<uint8_t>&)>>> m_outgoingHandlers;

static const size_t LatencyTrackCount = 16;
static const size_t LatencyTrackCount = 32;
std::deque<uint64_t> KeepAliveRequestTimestamps;
std::vector<uint64_t> ObservedLatencyList;

Expand Down Expand Up @@ -232,7 +232,8 @@ class App::Network::SingleConnection::Internals {
const auto newPos = ObservedLatencyList.empty() ? 0 : std::upper_bound(ObservedLatencyList.begin(), ObservedLatencyList.end(), delay) - ObservedLatencyList.begin();
ObservedLatencyList.insert(ObservedLatencyList.begin() + newPos, delay);
if (ObservedLatencyList.size() > LatencyTrackCount) {
if (newPos >= LatencyTrackCount / 2)
// try to send new item to middle
if (newPos < LatencyTrackCount / 2)
ObservedLatencyList.pop_back();
else
ObservedLatencyList.erase(ObservedLatencyList.begin());
Expand Down

0 comments on commit eb3273f

Please sign in to comment.