UniSet  2.12.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 // -------------------------------------------------------------------------
27 namespace uniset
28 {
31  {
32  public:
33 
34  static std::unique_ptr<MulticastReceiveTransport> createFromXml(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 = "" );
38  virtual ~MulticastReceiveTransport();
39 
40  virtual bool isConnected() const override;
41  virtual std::string toString() const 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 ) override;
51  virtual ssize_t receive(void* r_buf, size_t sz) override;
52  std::string iface() const;
53 
54  protected:
55  std::unique_ptr <MulticastSocketU> udp;
56  const std::string host;
57  const int port;
58  const std::vector<Poco::Net::IPAddress> groups;
59  const std::string ifaceaddr;
60  };
61 
63  public UNetSendTransport
64  {
65  public:
66 
67  static std::unique_ptr<MulticastSendTransport> createFromXml( UniXML::iterator it, int numChan );
68 
69  MulticastSendTransport(const std::string& sockHost, int sockPort, const std::string& groupHost, int groupPort, int ttl = 1 );
70  virtual ~MulticastSendTransport();
71 
72  virtual bool isConnected() const override;
73  virtual std::string toString() const override;
74 
75  virtual bool createConnection(bool throwEx, timeout_t sendTimeout) override;
76  virtual int getSocket() const override;
77  Poco::Net::SocketAddress getGroupAddress();
78 
79  // write
80  virtual bool isReadyForSend(timeout_t tout) override;
81  virtual ssize_t send(const void* buf, size_t sz) override;
82 
83  void setTimeToLive( int ttl );
84  void setLoopBack( bool state );
85 
86  protected:
87  std::unique_ptr <MulticastSocketU> udp;
88  const Poco::Net::SocketAddress sockAddr;
89  const Poco::Net::SocketAddress toAddr;
90  int ttl; // ttl for packets
91  };
92 
93 } // end of uniset namespace
94 // -------------------------------------------------------------------------
95 #endif // MulticastTransport_H_
96 // -------------------------------------------------------------------------
Definition: CommonEventLoop.h:14
Definition: UniXML.h:43
Definition: UNetTransport.h:45
Definition: MulticastTransport.h:29
Definition: UNetTransport.h:26
Definition: MulticastTransport.h:62