aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/Socket.cpp
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2024-11-08 09:50:37 +0100
committerMatthias P. Braendli <matthias.braendli@mpb.li>2024-11-08 09:50:37 +0100
commit3f382a56da220fbd39fdeb9ce4212629036686cb (patch)
tree0651faa1336f7e2a6d5631f335d853445bbe74cd /contrib/Socket.cpp
parent03156cc8055f3ef083681414b635d9eca7b0f772 (diff)
downloadODR-AudioEnc-3f382a56da220fbd39fdeb9ce4212629036686cb.tar.gz
ODR-AudioEnc-3f382a56da220fbd39fdeb9ce4212629036686cb.tar.bz2
ODR-AudioEnc-3f382a56da220fbd39fdeb9ce4212629036686cb.zip
Add logging for TCP sender
Diffstat (limited to 'contrib/Socket.cpp')
-rw-r--r--contrib/Socket.cpp17
1 files changed, 16 insertions, 1 deletions
diff --git a/contrib/Socket.cpp b/contrib/Socket.cpp
index 2df1559..a85b98b 100644
--- a/contrib/Socket.cpp
+++ b/contrib/Socket.cpp
@@ -1222,7 +1222,7 @@ TCPSendClient::~TCPSendClient()
}
}
-void TCPSendClient::sendall(const std::vector<uint8_t>& buffer)
+TCPSendClient::ErrorStats TCPSendClient::sendall(const std::vector<uint8_t>& buffer)
{
if (not m_running) {
throw runtime_error(m_exception_data);
@@ -1234,6 +1234,17 @@ void TCPSendClient::sendall(const std::vector<uint8_t>& buffer)
vector<uint8_t> discard;
m_queue.try_pop(discard);
}
+
+ TCPSendClient::ErrorStats es;
+ es.num_reconnects = m_num_reconnects.load();
+
+ es.has_seen_new_errors = es.num_reconnects != m_num_reconnects_prev;
+ m_num_reconnects_prev = es.num_reconnects;
+
+ auto lock = unique_lock<mutex>(m_error_mutex);
+ es.last_error = m_last_error;
+
+ return es;
}
void TCPSendClient::process()
@@ -1255,12 +1266,16 @@ void TCPSendClient::process()
}
else {
try {
+ m_num_reconnects.fetch_add(1, std::memory_order_seq_cst);
m_sock.connect(m_hostname, m_port);
m_is_connected = true;
}
catch (const runtime_error& e) {
m_is_connected = false;
this_thread::sleep_for(chrono::seconds(1));
+
+ auto lock = unique_lock<mutex>(m_error_mutex);
+ m_last_error = e.what();
}
}
}