diff options
author | Matthias P. Braendli <matthias.braendli@mpb.li> | 2024-11-08 09:50:37 +0100 |
---|---|---|
committer | Matthias P. Braendli <matthias.braendli@mpb.li> | 2024-11-08 09:50:37 +0100 |
commit | 3f382a56da220fbd39fdeb9ce4212629036686cb (patch) | |
tree | 0651faa1336f7e2a6d5631f335d853445bbe74cd /contrib/Socket.h | |
parent | 03156cc8055f3ef083681414b635d9eca7b0f772 (diff) | |
download | ODR-AudioEnc-3f382a56da220fbd39fdeb9ce4212629036686cb.tar.gz ODR-AudioEnc-3f382a56da220fbd39fdeb9ce4212629036686cb.tar.bz2 ODR-AudioEnc-3f382a56da220fbd39fdeb9ce4212629036686cb.zip |
Add logging for TCP sender
Diffstat (limited to 'contrib/Socket.h')
-rw-r--r-- | contrib/Socket.h | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/contrib/Socket.h b/contrib/Socket.h index 1320a64..ab2a14a 100644 --- a/contrib/Socket.h +++ b/contrib/Socket.h @@ -329,10 +329,18 @@ class TCPSendClient { public: TCPSendClient(const std::string& hostname, int port); ~TCPSendClient(); + TCPSendClient(const TCPSendClient&) = delete; + TCPSendClient& operator=(const TCPSendClient&) = delete; - /* Throws a runtime_error on error - */ - void sendall(const std::vector<uint8_t>& buffer); + + struct ErrorStats { + std::string last_error = ""; + size_t num_reconnects = 0; + bool has_seen_new_errors = false; + }; + + /* Throws a runtime_error when the process thread isn't running */ + ErrorStats sendall(const std::vector<uint8_t>& buffer); private: void process(); @@ -349,6 +357,11 @@ class TCPSendClient { std::string m_exception_data; std::thread m_sender_thread; TCPSocket m_listener_socket; + + std::atomic<size_t> m_num_reconnects = ATOMIC_VAR_INIT(0); + size_t m_num_reconnects_prev = 0; + std::mutex m_error_mutex; + std::string m_last_error = ""; }; } |