summaryrefslogtreecommitdiffstats
path: root/src/dabOutput
diff options
context:
space:
mode:
Diffstat (limited to 'src/dabOutput')
-rw-r--r--src/dabOutput/dabOutput.h7
-rw-r--r--src/dabOutput/dabOutputTcp.cpp36
2 files changed, 20 insertions, 23 deletions
diff --git a/src/dabOutput/dabOutput.h b/src/dabOutput/dabOutput.h
index eaa623f..c10d358 100644
--- a/src/dabOutput/dabOutput.h
+++ b/src/dabOutput/dabOutput.h
@@ -222,11 +222,6 @@ class TCPDataDispatcher;
class DabOutputTcp : public DabOutput
{
public:
- DabOutputTcp() {}
- DabOutputTcp(const DabOutputTcp& other) = delete;
- const DabOutputTcp& operator=(const DabOutputTcp& other) = delete;
- ~DabOutputTcp();
-
int Open(const char* name);
int Write(void* buffer, int size);
int Close();
@@ -238,7 +233,7 @@ class DabOutputTcp : public DabOutput
private:
std::string uri_;
- TCPDataDispatcher* dispatcher_;
+ std::shared_ptr<TCPDataDispatcher> dispatcher_;
};
// -------------- Simul ------------------
diff --git a/src/dabOutput/dabOutputTcp.cpp b/src/dabOutput/dabOutputTcp.cpp
index 8696bec..2aab48a 100644
--- a/src/dabOutput/dabOutputTcp.cpp
+++ b/src/dabOutput/dabOutputTcp.cpp
@@ -95,6 +95,10 @@ class TCPConnection
m_running = false;
}
}
+
+ auto addr = m_sock.getRemoteAddress();
+ etiLog.level(debug) << "Dropping TCP Connection from " <<
+ addr.getHostAddress() << ":" << addr.getPort();
}
};
@@ -121,22 +125,28 @@ class TCPDataDispatcher
connection.queue.push(data);
}
- m_connections.remove_if([](TCPConnection& conn){ return conn.is_overloaded(); });
+ m_connections.remove_if([](const TCPConnection& conn){ return conn.is_overloaded(); });
}
private:
void process(long) {
- m_listener_socket.listen();
+ try {
+ m_listener_socket.listen();
- const int timeout_ms = 1000;
+ const int timeout_ms = 1000;
- while (m_running) {
- // Add a new TCPConnection to the list, constructing it from the client socket
- auto optional_sock = m_listener_socket.accept(timeout_ms);
- if (optional_sock) {
- m_connections.emplace(m_connections.begin(), std::move(*optional_sock));
+ while (m_running) {
+ // Add a new TCPConnection to the list, constructing it from the client socket
+ auto sock = m_listener_socket.accept(timeout_ms);
+ if (sock.isValid()) {
+ m_connections.emplace(m_connections.begin(), move(sock));
+ }
}
}
+ catch (std::runtime_error& e) {
+ etiLog.level(error) << "TCPDataDispatcher caught runtime error: " << e.what();
+ m_running = false;
+ }
}
atomic<bool> m_running;
@@ -145,14 +155,6 @@ class TCPDataDispatcher
std::list<TCPConnection> m_connections;
};
-DabOutputTcp::~DabOutputTcp()
-{
- if (dispatcher_) {
- delete dispatcher_;
- dispatcher_ = nullptr;
- }
-}
-
static bool parse_uri(const char *uri, long *port, string& addr)
{
char* const hostport = strdup(uri); // the uri is actually an tuple host:port
@@ -199,7 +201,7 @@ int DabOutputTcp::Open(const char* name)
uri_ = name;
if (success) {
- dispatcher_ = new TCPDataDispatcher();
+ dispatcher_ = make_shared<TCPDataDispatcher>();
try {
dispatcher_->start(port, address);
}