From 2babe4c236e6bb08f7476cbca2af00b2a88a90e7 Mon Sep 17 00:00:00 2001 From: RipleyTom Date: Thu, 8 Oct 2020 01:25:35 +0200 Subject: [PATCH] Add better handling of RTT for STREAM_P2P --- rpcs3/Emu/Cell/lv2/sys_net.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/rpcs3/Emu/Cell/lv2/sys_net.cpp b/rpcs3/Emu/Cell/lv2/sys_net.cpp index d3c27bdd73..054d9d84f1 100644 --- a/rpcs3/Emu/Cell/lv2/sys_net.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_net.cpp @@ -282,12 +282,25 @@ public: { std::lock_guard lock(data_mutex); rtts[sock_id].num_retries = 0; - // TODO: reduce RTT? + + const auto now = std::chrono::system_clock::now(); + for (auto it = msgs.begin(); it != msgs.end();) { auto& msg = it->second; if (msg.sock_id == sock_id && msg.seq < ack) { + // Decreases RTT if msg is early + if (now < it->first) + { + const auto actual_rtt = std::chrono::duration_cast(now - it->second.initial_sendtime); + const auto cur_rtt = rtts[sock_id].rtt_time; + if (cur_rtt > actual_rtt) + { + rtts[sock_id].rtt_time = (actual_rtt + cur_rtt) / 2; + } + + } it = msgs.erase(it); continue; }