aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Socket.h
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2019-06-07 10:14:51 +0200
committerMatthias P. Braendli <matthias.braendli@mpb.li>2019-06-07 10:14:51 +0200
commit8b0d4b647a3ac2e21e6a8e7a902eea3ae462e213 (patch)
treec0296c305409bb7fc373625aea05c2f57054eb5c /lib/Socket.h
parent43f4a3a2a695c303bd4fdfbd7fec6def29284f2e (diff)
downloaddabmux-8b0d4b647a3ac2e21e6a8e7a902eea3ae462e213.tar.gz
dabmux-8b0d4b647a3ac2e21e6a8e7a902eea3ae462e213.tar.bz2
dabmux-8b0d4b647a3ac2e21e6a8e7a902eea3ae462e213.zip
Work on STI-D/EDI input
Diffstat (limited to 'lib/Socket.h')
-rw-r--r--lib/Socket.h32
1 files changed, 30 insertions, 2 deletions
diff --git a/lib/Socket.h b/lib/Socket.h
index 82ff5ad..2393584 100644
--- a/lib/Socket.h
+++ b/lib/Socket.h
@@ -104,13 +104,14 @@ class UDPSocket
const UDPSocket& operator=(const UDPSocket& other) = delete;
/** Close the already open socket, and create a new one. Throws a runtime_error on error. */
+ void reinit(int port);
void reinit(int port, const std::string& name);
void close(void);
void send(UDPPacket& packet);
void send(const std::vector<uint8_t>& data, InetAddress destination);
UDPPacket receive(size_t max_size);
- void joinGroup(char* groupname);
+ void joinGroup(const char* groupname, const char* if_addr = nullptr);
void setMulticastSource(const char* source_addr);
void setMulticastTTL(int ttl);
@@ -120,9 +121,36 @@ class UDPSocket
void setBlocking(bool block);
protected:
- SOCKET listenSocket;
+ SOCKET m_sock;
};
+/* Threaded UDP receiver */
+class UDPReceiver {
+ public:
+ UDPReceiver() : m_port(0), m_thread(), m_stop(false), m_packets() {}
+ ~UDPReceiver();
+ UDPReceiver(const UDPReceiver&) = delete;
+ UDPReceiver operator=(const UDPReceiver&) = delete;
+
+ // Start the receiver in a separate thread
+ void start(int port, const std::string& bindto, const std::string& mcastaddr, size_t max_packets_queued);
+
+ // Get the data contained in a UDP packet, blocks if none available
+ // In case of error, throws a runtime_error
+ std::vector<uint8_t> get_packet_buffer(void);
+
+ private:
+ void m_run(void);
+
+ int m_port;
+ std::string m_bindto;
+ std::string m_mcastaddr;
+ size_t m_max_packets_queued;
+ std::thread m_thread;
+ std::atomic<bool> m_stop;
+ ThreadsafeQueue<UDPPacket> m_packets;
+ UDPSocket m_sock;
+};
class TCPSocket {
public: