UniSet 2.32.1
MulticastTransport.h
1/*
2 * Copyright (c) 2021 Pavel Vainerman.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as
6 * published by the Free Software Foundation, version 2.1.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Lesser Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16// -------------------------------------------------------------------------
17#ifndef MulticastTransport_H_
18#define MulticastTransport_H_
19// -------------------------------------------------------------------------
20#include <string>
21#include <memory>
22#include <vector>
23#include "UNetTransport.h"
24#include "UDPCore.h"
25#include "UniXML.h"
26// -------------------------------------------------------------------------
27namespace uniset
28{
31 {
32 public:
33
34 static std::unique_ptr<MulticastReceiveTransport> createFromXml( UniXML::iterator root, UniXML::iterator it, int numChan);
35 static xmlNode* getReceiveListNode( UniXML::iterator root );
36
37 MulticastReceiveTransport( const std::string& bind, int port, const std::vector<Poco::Net::IPAddress>& joinGroups, const std::string& iface = "" );
39
40 virtual bool isConnected() const noexcept override;
41 virtual std::string toString() const noexcept override;
42 virtual std::string ID() const noexcept override;
43
44 virtual bool createConnection(bool throwEx, timeout_t readTimeout, bool noblock) override;
45 virtual void disconnect() override;
46 virtual int getSocket() const override;
47 std::vector<Poco::Net::IPAddress> getGroups();
48 void setLoopBack( bool state );
49
50 bool isReadyForReceive( timeout_t tout ) noexcept override;
51 virtual ssize_t receive(void* r_buf, size_t sz) override;
52 virtual int available() override;
53 std::string iface() const;
54
55 protected:
56 std::unique_ptr <MulticastSocketU> udp;
57 const std::string host;
58 const int port;
59 const std::vector<Poco::Net::IPAddress> groups;
60 const std::string ifaceaddr;
61 };
62
65 {
66 public:
67
68 static std::unique_ptr<MulticastSendTransport> createFromXml( UniXML::iterator root, UniXML::iterator it, int numChan );
69
70 MulticastSendTransport(const std::string& sockHost, int sockPort, const std::string& groupHost, int groupPort, int ttl = 1 );
72
73 virtual bool isConnected() const noexcept override;
74 virtual std::string toString() const noexcept override;
75
76 virtual bool createConnection(bool throwEx, timeout_t sendTimeout) override;
77 virtual int getSocket() const override;
78 Poco::Net::SocketAddress getGroupAddress();
79
80 // write
81 virtual bool isReadyForSend(timeout_t tout) noexcept override;
82 virtual ssize_t send(const void* buf, size_t sz) override;
83
84 void setTimeToLive( int ttl );
85 void setLoopBack( bool state );
86
87 protected:
88 std::unique_ptr <MulticastSocketU> udp;
89 const Poco::Net::SocketAddress sockAddr;
90 const Poco::Net::SocketAddress toAddr;
91 int ttl; // ttl for packets
92 };
93
94} // end of uniset namespace
95// -------------------------------------------------------------------------
96#endif // MulticastTransport_H_
97// -------------------------------------------------------------------------
Definition MulticastTransport.h:31
Definition MulticastTransport.h:65
Definition UNetTransport.h:27
Definition UNetTransport.h:47
Definition UniXML.h:44
Definition Calibration.h:27