From 9d6ddfcb36115084237bac3a3f1c49ddf0da765f Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Fri, 15 Jan 2021 08:22:18 +0100 Subject: Common 6b5db53: Update zmq.hpp, TCPReceiveServer, EDI decoder and output --- lib/Socket.h | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) (limited to 'lib/Socket.h') diff --git a/lib/Socket.h b/lib/Socket.h index 8881be3..2291dd5 100644 --- a/lib/Socket.h +++ b/lib/Socket.h @@ -30,11 +30,12 @@ #include "ThreadsafeQueue.h" #include -#include -#include #include -#include +#include #include +#include +#include +#include #include #include @@ -265,6 +266,14 @@ class TCPDataDispatcher std::list m_connections; }; +struct TCPReceiveMessage { virtual ~TCPReceiveMessage() {}; }; +struct TCPReceiveMessageDisconnected : public TCPReceiveMessage { }; +struct TCPReceiveMessageEmpty : public TCPReceiveMessage { }; +struct TCPReceiveMessageData : public TCPReceiveMessage { + TCPReceiveMessageData(std::vector d) : data(d) {}; + std::vector data; +}; + /* A TCP Server to receive data, which abstracts the handling of connects and disconnects. */ class TCPReceiveServer { @@ -276,15 +285,15 @@ class TCPReceiveServer { void start(int listen_port, const std::string& address); - // Return a vector that contains up to blocksize bytes of data, or - // and empty vector if no data is available. - std::vector receive(); + // Return an instance of a subclass of TCPReceiveMessage that contains up to blocksize + // bytes of data, or TCPReceiveMessageEmpty if no data is available. + std::shared_ptr receive(); private: void process(); size_t m_blocksize = 0; - ThreadsafeQueue > m_queue; + ThreadsafeQueue > m_queue; std::atomic m_running = ATOMIC_VAR_INIT(false); std::string m_exception_data; std::thread m_listener_thread; -- cgit v1.2.3