diff options
author | Matthias P. Braendli <matthias.braendli@mpb.li> | 2020-04-21 15:51:31 +0200 |
---|---|---|
committer | Matthias P. Braendli <matthias.braendli@mpb.li> | 2020-04-21 15:51:31 +0200 |
commit | 43d5fa8e85dd013391a8eafc16350cc13b008389 (patch) | |
tree | 63b93aefd0428a6e4a3604d73f1ab076a601f3ad /lib/Socket.h | |
parent | 0aa8e58e6763bda1d20246155e61b7cd54cdfc65 (diff) | |
download | ODR-SourceCompanion-43d5fa8e85dd013391a8eafc16350cc13b008389.tar.gz ODR-SourceCompanion-43d5fa8e85dd013391a8eafc16350cc13b008389.tar.bz2 ODR-SourceCompanion-43d5fa8e85dd013391a8eafc16350cc13b008389.zip |
Common 33a8362: EDI TCP output: handle disconnects
Diffstat (limited to 'lib/Socket.h')
-rw-r--r-- | lib/Socket.h | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/lib/Socket.h b/lib/Socket.h index b9f6317..84def40 100644 --- a/lib/Socket.h +++ b/lib/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(const 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; +}; + } |