diff options
author | Matthias P. Braendli <matthias.braendli@mpb.li> | 2020-04-21 14:12:50 +0200 |
---|---|---|
committer | Matthias P. Braendli <matthias.braendli@mpb.li> | 2020-04-21 14:12:50 +0200 |
commit | b1438d4fa31aa9e967f1f7e2d48f55ca371151d1 (patch) | |
tree | a49610744f323e6405a400a2250dd8f5a596382f /contrib/Socket.h | |
parent | 90201eb5ff37340b85348f762effd8124449f27f (diff) | |
download | ODR-AudioEnc-b1438d4fa31aa9e967f1f7e2d48f55ca371151d1.tar.gz ODR-AudioEnc-b1438d4fa31aa9e967f1f7e2d48f55ca371151d1.tar.bz2 ODR-AudioEnc-b1438d4fa31aa9e967f1f7e2d48f55ca371151d1.zip |
Change EDI output to handle disconnects
Diffstat (limited to 'contrib/Socket.h')
-rw-r--r-- | contrib/Socket.h | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/contrib/Socket.h b/contrib/Socket.h index b9f6317..b342d8b 100644 --- a/contrib/Socket.h +++ b/contrib/Socket.h @@ -291,4 +291,32 @@ class TCPReceiveServer { TCPSocket m_listener_socket; }; +/* A TCP client that abstracts the handling of connects and disconnects. + */ +class TCPSendClient { + public: + TCPSendClient(const std::string& hostname, int port); + ~TCPSendClient(); + + /* Throws a runtime_error on error + */ + void sendall(std::vector<uint8_t>&& buffer); + + private: + void process(); + + std::string m_hostname; + int m_port; + + bool m_is_connected = false; + + TCPSocket m_sock; + static constexpr size_t MAX_QUEUE_SIZE = 1024; + ThreadsafeQueue<std::vector<uint8_t> > m_queue; + std::atomic<bool> m_running; + std::string m_exception_data; + std::thread m_sender_thread; + TCPSocket m_listener_socket; +}; + } |