From c7869f8a51d772ad0654df19741ead8bfe50acfe Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Fri, 15 Jan 2021 08:22:09 +0100 Subject: Common 6b5db53: Update zmq.hpp, TCPReceiveServer, EDI decoder and output --- contrib/Socket.h | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) (limited to 'contrib/Socket.h') diff --git a/contrib/Socket.h b/contrib/Socket.h index 8881be3..2291dd5 100644 --- a/contrib/Socket.h +++ b/contrib/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