From cd5ef5af74b7dbee8c27549cd219a4ce5a0999c5 Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Tue, 21 Apr 2020 15:56:26 +0200 Subject: Common 33a8362: EDI TCP output: handle disconnects --- lib/edioutput/Transport.cpp | 41 ++++++++++++++++++++--------------------- lib/edioutput/Transport.h | 2 +- 2 files changed, 21 insertions(+), 22 deletions(-) (limited to 'lib/edioutput') diff --git a/lib/edioutput/Transport.cpp b/lib/edioutput/Transport.cpp index 0d5c237..4c91483 100644 --- a/lib/edioutput/Transport.cpp +++ b/lib/edioutput/Transport.cpp @@ -87,9 +87,8 @@ Sender::Sender(const configuration_t& conf) : tcp_dispatchers.emplace(tcp_dest.get(), dispatcher); } else if (auto tcp_dest = dynamic_pointer_cast(edi_dest)) { - auto tcp_socket = make_shared(); - tcp_socket->connect(tcp_dest->dest_addr, tcp_dest->dest_port); - tcp_senders.emplace(tcp_dest.get(), tcp_socket); + auto tcp_send_client = make_shared(tcp_dest->dest_addr, tcp_dest->dest_port); + tcp_senders.emplace(tcp_dest.get(), tcp_send_client); } else { throw logic_error("EDI destination not implemented"); @@ -127,8 +126,18 @@ void Sender::write(const TagPacket& tagpacket) edi_fragments = edi_interleaver.Interleave(edi_fragments); } + if (m_conf.verbose) { + fprintf(stderr, "EDI number of PFT fragments %zu\n", + edi_fragments.size()); + } + // Send over ethernet - for (const auto& edi_frag : edi_fragments) { + for (auto& edi_frag : edi_fragments) { + if (m_conf.dump) { + ostream_iterator debug_iterator(edi_debug_file); + copy(edi_frag.begin(), edi_frag.end(), debug_iterator); + } + for (auto& dest : m_conf.destinations) { if (const auto& udp_dest = dynamic_pointer_cast(dest)) { Socket::InetAddress addr; @@ -140,26 +149,21 @@ void Sender::write(const TagPacket& tagpacket) tcp_dispatchers.at(tcp_dest.get())->write(edi_frag); } else if (auto tcp_dest = dynamic_pointer_cast(dest)) { - tcp_senders.at(tcp_dest.get())->sendall(edi_frag.data(), edi_frag.size()); + tcp_senders.at(tcp_dest.get())->sendall(edi_frag); } else { throw logic_error("EDI destination not implemented"); } } - - if (m_conf.dump) { - ostream_iterator debug_iterator(edi_debug_file); - copy(edi_frag.begin(), edi_frag.end(), debug_iterator); - } - } - - if (m_conf.verbose) { - fprintf(stderr, "EDI number of PFT fragments %zu\n", - edi_fragments.size()); } } else { // Send over ethernet + if (m_conf.dump) { + ostream_iterator debug_iterator(edi_debug_file); + copy(af_packet.begin(), af_packet.end(), debug_iterator); + } + for (auto& dest : m_conf.destinations) { if (const auto& udp_dest = dynamic_pointer_cast(dest)) { Socket::InetAddress addr; @@ -171,17 +175,12 @@ void Sender::write(const TagPacket& tagpacket) tcp_dispatchers.at(tcp_dest.get())->write(af_packet); } else if (auto tcp_dest = dynamic_pointer_cast(dest)) { - tcp_senders.at(tcp_dest.get())->sendall(af_packet.data(), af_packet.size()); + tcp_senders.at(tcp_dest.get())->sendall(af_packet); } else { throw logic_error("EDI destination not implemented"); } } - - if (m_conf.dump) { - ostream_iterator debug_iterator(edi_debug_file); - copy(af_packet.begin(), af_packet.end(), debug_iterator); - } } } diff --git a/lib/edioutput/Transport.h b/lib/edioutput/Transport.h index df6fe56..73b2ab6 100644 --- a/lib/edioutput/Transport.h +++ b/lib/edioutput/Transport.h @@ -64,7 +64,7 @@ class Sender { std::unordered_map> udp_sockets; std::unordered_map> tcp_dispatchers; - std::unordered_map> tcp_senders; + std::unordered_map> tcp_senders; }; } -- cgit v1.2.3