diff options
author | Matthias P. Braendli <matthias.braendli@mpb.li> | 2021-01-15 07:09:03 +0100 |
---|---|---|
committer | Matthias P. Braendli <matthias.braendli@mpb.li> | 2021-01-18 13:22:09 +0100 |
commit | 12670a017ddb14fbf4a932799051dcfe21dd6c78 (patch) | |
tree | 43675f68329676a1ff84f8a26bab8733be224c0b /lib/Socket.h | |
parent | c1d33594ca424b56a34200a6e525cdb1317bad69 (diff) | |
download | dabmux-12670a017ddb14fbf4a932799051dcfe21dd6c78.tar.gz dabmux-12670a017ddb14fbf4a932799051dcfe21dd6c78.tar.bz2 dabmux-12670a017ddb14fbf4a932799051dcfe21dd6c78.zip |
Common 6b5db53: Update zmq.hpp, TCPReceiveServer, EDI decoder and output
Diffstat (limited to 'lib/Socket.h')
-rw-r--r-- | lib/Socket.h | 23 |
1 files changed, 16 insertions, 7 deletions
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 <cstdlib> -#include <iostream> -#include <vector> #include <atomic> -#include <thread> +#include <iostream> #include <list> +#include <memory> +#include <thread> +#include <vector> #include <sys/socket.h> #include <netinet/in.h> @@ -265,6 +266,14 @@ class TCPDataDispatcher std::list<TCPConnection> m_connections; }; +struct TCPReceiveMessage { virtual ~TCPReceiveMessage() {}; }; +struct TCPReceiveMessageDisconnected : public TCPReceiveMessage { }; +struct TCPReceiveMessageEmpty : public TCPReceiveMessage { }; +struct TCPReceiveMessageData : public TCPReceiveMessage { + TCPReceiveMessageData(std::vector<uint8_t> d) : data(d) {}; + std::vector<uint8_t> 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<uint8_t> 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<TCPReceiveMessage> receive(); private: void process(); size_t m_blocksize = 0; - ThreadsafeQueue<std::vector<uint8_t> > m_queue; + ThreadsafeQueue<std::shared_ptr<TCPReceiveMessage> > m_queue; std::atomic<bool> m_running = ATOMIC_VAR_INIT(false); std::string m_exception_data; std::thread m_listener_thread; |