summaryrefslogtreecommitdiffstats
path: root/lib/UdpSocket.cpp
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2017-01-13 16:33:33 +0100
committerMatthias P. Braendli <matthias.braendli@mpb.li>2017-01-13 16:33:33 +0100
commit1bbbac7f62d71f0d0c4c71d429aeb2cfdf96e5ac (patch)
treef9234c8e6491151fddccc2c8d1ff0b0600c44c5f /lib/UdpSocket.cpp
parent7c8ae25ba83fc658dfbe4cd468bb1bdfd3513c74 (diff)
downloaddabmod-1bbbac7f62d71f0d0c4c71d429aeb2cfdf96e5ac.tar.gz
dabmod-1bbbac7f62d71f0d0c4c71d429aeb2cfdf96e5ac.tar.bz2
dabmod-1bbbac7f62d71f0d0c4c71d429aeb2cfdf96e5ac.zip
EDI: add protection against runaway memory usage
Diffstat (limited to 'lib/UdpSocket.cpp')
-rw-r--r--lib/UdpSocket.cpp7
1 files changed, 5 insertions, 2 deletions
diff --git a/lib/UdpSocket.cpp b/lib/UdpSocket.cpp
index b88c731..570da5f 100644
--- a/lib/UdpSocket.cpp
+++ b/lib/UdpSocket.cpp
@@ -261,8 +261,9 @@ UdpReceiver::~UdpReceiver() {
}
}
-void UdpReceiver::start(int port) {
+void UdpReceiver::start(int port, size_t max_packets_queued) {
m_port = port;
+ m_max_packets_queued = max_packets_queued;
m_thread = std::thread(&UdpReceiver::m_run, this);
}
@@ -299,7 +300,9 @@ void UdpReceiver::m_run()
// TODO replace fprintf
fprintf(stderr, "Warning, possible UDP truncation\n");
}
- m_packets.push(packet);
+
+ // If this blocks, the UDP socket will lose incoming packets
+ m_packets.push_wait_if_full(packet, m_max_packets_queued);
}
else
{