aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2020-09-23 15:07:28 +0200
committerMatthias P. Braendli <matthias.braendli@mpb.li>2020-09-23 15:07:28 +0200
commitb25d18020f13766495d61411ace3bd89c08016ac (patch)
tree120970ce1c62b7f9e9fff59da7dd9a63a280f4e2
parentaf0dfd303377961cb1222a15bb92a7c346b3b305 (diff)
downloadODR-SourceCompanion-b25d18020f13766495d61411ace3bd89c08016ac.tar.gz
ODR-SourceCompanion-b25d18020f13766495d61411ace3bd89c08016ac.tar.bz2
ODR-SourceCompanion-b25d18020f13766495d61411ace3bd89c08016ac.zip
Pull in common 0c5bf36: spread UDP packets over time to avoid bursts
-rw-r--r--lib/edi/Transport.cpp9
1 files changed, 9 insertions, 0 deletions
diff --git a/lib/edi/Transport.cpp b/lib/edi/Transport.cpp
index d8627fd..fa7588a 100644
--- a/lib/edi/Transport.cpp
+++ b/lib/edi/Transport.cpp
@@ -26,6 +26,7 @@
*/
#include "Transport.h"
#include <iterator>
+#include <cmath>
using namespace std;
@@ -131,6 +132,12 @@ void Sender::write(const TagPacket& tagpacket)
edi_fragments.size());
}
+ /* Spread out the transmission of all fragments over 75% of the 24ms AF packet duration
+ * to reduce the risk of losing fragments because of congestion.
+ *
+ * 75% was chosen so that other outputs still have time to do their thing. */
+ const auto inter_fragment_wait_time = std::chrono::microseconds(llrint(0.75 * 24000.0 / edi_fragments.size()));
+
// Send over ethernet
for (auto& edi_frag : edi_fragments) {
if (m_conf.dump) {
@@ -155,6 +162,8 @@ void Sender::write(const TagPacket& tagpacket)
throw logic_error("EDI destination not implemented");
}
}
+
+ std::this_thread::sleep_for(inter_fragment_wait_time);
}
}
else {