summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2021-06-07 07:49:55 +0200
committerMatthias P. Braendli <matthias.braendli@mpb.li>2021-06-07 07:49:55 +0200
commitbd6d1656cfcca1f0f351defcd3dcfa617812a909 (patch)
treed74de404b3c1886be570a6c29a02f2e3ce428389 /src
parentc1f2a58fd909071f0f6cfe98ab9c33bcf2c68bdb (diff)
downloaddabmux-bd6d1656cfcca1f0f351defcd3dcfa617812a909.tar.gz
dabmux-bd6d1656cfcca1f0f351defcd3dcfa617812a909.tar.bz2
dabmux-bd6d1656cfcca1f0f351defcd3dcfa617812a909.zip
Handle invalid_argument in EDI input
Diffstat (limited to 'src')
-rw-r--r--src/input/Edi.cpp79
1 files changed, 39 insertions, 40 deletions
diff --git a/src/input/Edi.cpp b/src/input/Edi.cpp
index 338a8e6..be1b4a3 100644
--- a/src/input/Edi.cpp
+++ b/src/input/Edi.cpp
@@ -339,55 +339,54 @@ size_t Edi::readFrame(uint8_t *buffer, size_t size, std::time_t seconds, int utc
void Edi::m_run()
{
while (m_running) {
- switch (m_input_used) {
- case InputUsed::UDP:
- {
- constexpr size_t packsize = 2048;
- auto packet = m_udp_sock.receive(packsize);
- if (packet.buffer.size() == packsize) {
- fprintf(stderr, "Warning, possible UDP truncation\n");
- }
- if (not packet.buffer.empty()) {
- try {
+ try {
+ switch (m_input_used) {
+ case InputUsed::UDP:
+ {
+ constexpr size_t packsize = 2048;
+ auto packet = m_udp_sock.receive(packsize);
+ if (packet.buffer.size() == packsize) {
+ fprintf(stderr, "Warning, possible UDP truncation\n");
+ }
+
+ if (not packet.buffer.empty()) {
EdiDecoder::Packet p(move(packet.buffer));
m_sti_decoder.push_packet(p);
}
- catch (const runtime_error& e) {
- etiLog.level(warn) << "EDI input " << m_name << " exception: " << e.what();
- this_thread::sleep_for(chrono::milliseconds(24));
+ else {
+ this_thread::sleep_for(chrono::milliseconds(12));
}
}
- else {
- this_thread::sleep_for(chrono::milliseconds(12));
- }
- }
- break;
- case InputUsed::TCP:
- {
- auto message = m_tcp_receive_server.receive();
- if (auto data = dynamic_pointer_cast<Socket::TCPReceiveMessageData>(message)) {
- try {
+ break;
+ case InputUsed::TCP:
+ {
+ auto message = m_tcp_receive_server.receive();
+ if (auto data = dynamic_pointer_cast<Socket::TCPReceiveMessageData>(message)) {
m_sti_decoder.push_bytes(data->data);
}
- catch (const runtime_error& e) {
- etiLog.level(warn) << "EDI input " << m_name << " exception: " << e.what();
- this_thread::sleep_for(chrono::milliseconds(24));
+ else if (dynamic_pointer_cast<Socket::TCPReceiveMessageDisconnected>(message)) {
+ etiLog.level(info) << "EDI input " << m_name << " disconnected";
+ m_sti_decoder.push_bytes({}); // Push an empty frame to clear the internal state
+ }
+ else if (dynamic_pointer_cast<Socket::TCPReceiveMessageEmpty>(message)) {
+ this_thread::sleep_for(chrono::milliseconds(12));
+ }
+ else {
+ throw logic_error("unimplemented TCPReceiveMessage type");
}
}
- else if (dynamic_pointer_cast<Socket::TCPReceiveMessageDisconnected>(message)) {
- etiLog.level(info) << "EDI input " << m_name << " disconnected";
- m_sti_decoder.push_bytes({}); // Push an empty frame to clear the internal state
- }
- else if (dynamic_pointer_cast<Socket::TCPReceiveMessageEmpty>(message)) {
- this_thread::sleep_for(chrono::milliseconds(12));
- }
- else {
- throw logic_error("unimplemented TCPReceiveMessage type");
- }
- }
- break;
- default:
- throw logic_error("unimplemented input");
+ break;
+ default:
+ throw logic_error("unimplemented input");
+ }
+ }
+ catch (const invalid_argument& e) {
+ etiLog.level(warn) << "EDI input " << m_name << " exception: " << e.what();
+ this_thread::sleep_for(chrono::milliseconds(24));
+ }
+ catch (const runtime_error& e) {
+ etiLog.level(warn) << "EDI input " << m_name << " exception: " << e.what();
+ this_thread::sleep_for(chrono::milliseconds(24));
}
}
}