UniSet  2.12.1
UDPTransport.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 UDPTransport_H_
18 #define UDPTransport_H_
19 // -------------------------------------------------------------------------
20 #include <string>
21 #include <memory>
22 #include "UNetTransport.h"
23 #include "UDPCore.h"
24 #include "UniXML.h"
25 // -------------------------------------------------------------------------
26 namespace uniset
27 {
30  {
31  public:
32 
33  static std::unique_ptr<UDPReceiveTransport> createFromXml( UniXML::iterator it, const std::string& defaultIP, int numChan );
34 
35  UDPReceiveTransport( const std::string& bind, int port );
36  virtual ~UDPReceiveTransport();
37 
38  virtual bool isConnected() const override;
39  virtual std::string toString() const override;
40  virtual std::string ID() const noexcept override;
41 
42  virtual bool createConnection( bool throwEx, timeout_t readTimeout, bool noblock ) override;
43  virtual void disconnect() override;
44  virtual int getSocket() const override;
45  virtual ssize_t receive( void* r_buf, size_t sz ) override;
46  virtual bool isReadyForReceive(timeout_t tout) override;
47 
48  protected:
49  std::unique_ptr<UDPReceiveU> udp;
50  const std::string host;
51  const int port;
52  };
53 
55  public UNetSendTransport
56  {
57  public:
58 
59  static std::unique_ptr<UDPSendTransport> createFromXml( UniXML::iterator it, const std::string& defaultIP, int numChan );
60 
61  UDPSendTransport( const std::string& host, int port );
62  virtual ~UDPSendTransport();
63 
64  virtual bool isConnected() const override;
65  virtual std::string toString() const override;
66 
67  virtual bool createConnection( bool throwEx, timeout_t sendTimeout ) override;
68  virtual int getSocket() const override;
69 
70  // write
71  virtual bool isReadyForSend( timeout_t tout ) override;
72  virtual ssize_t send( const void* buf, size_t sz ) override;
73 
74  protected:
75  std::unique_ptr<UDPSocketU> udp;
76  Poco::Net::SocketAddress saddr;
77  };
78 
79 } // end of uniset namespace
80 // -------------------------------------------------------------------------
81 #endif // UDPTransport_H_
82 // -------------------------------------------------------------------------
Definition: CommonEventLoop.h:14
Definition: UniXML.h:43
Definition: UNetTransport.h:45
Definition: UDPTransport.h:28
Definition: UNetTransport.h:26
Definition: UDPTransport.h:54