diff options
| author | Matthias P. Braendli <matthias.braendli@mpb.li> | 2021-01-15 08:22:18 +0100 | 
|---|---|---|
| committer | Matthias P. Braendli <matthias.braendli@mpb.li> | 2021-01-15 08:22:18 +0100 | 
| commit | 9d6ddfcb36115084237bac3a3f1c49ddf0da765f (patch) | |
| tree | 6b828d92034a3322f9109663be32ff2646009d1f /lib/Socket.h | |
| parent | b65ec3d9d712c23f99f6af6a85aa421a98b4c8a0 (diff) | |
| download | ODR-SourceCompanion-9d6ddfcb36115084237bac3a3f1c49ddf0da765f.tar.gz ODR-SourceCompanion-9d6ddfcb36115084237bac3a3f1c49ddf0da765f.tar.bz2 ODR-SourceCompanion-9d6ddfcb36115084237bac3a3f1c49ddf0da765f.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; | 
