UniSet 2.32.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// -------------------------------------------------------------------------
26namespace 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 noexcept override;
39 virtual std::string toString() const noexcept 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) noexcept override;
47 virtual int available() override;
48
49 protected:
50 std::unique_ptr<UDPReceiveU> udp;
51 const std::string host;
52 const int port;
53 };
54
57 {
58 public:
59
60 static std::unique_ptr<UDPSendTransport> createFromXml( UniXML::iterator it, const std::string& defaultIP, int numChan );
61
62 UDPSendTransport( const std::string& host, int port );
63 virtual ~UDPSendTransport();
64
65 virtual bool isConnected() const noexcept override;
66 virtual std::string toString() const noexcept override;
67
68 virtual bool createConnection( bool throwEx, timeout_t sendTimeout ) override;
69 virtual int getSocket() const override;
70
71 // write
72 virtual bool isReadyForSend( timeout_t tout ) noexcept override;
73 virtual ssize_t send( const void* buf, size_t sz ) override;
74
75 protected:
76 std::unique_ptr<UDPSocketU> udp;
77 Poco::Net::SocketAddress saddr;
78 };
79
80} // end of uniset namespace
81// -------------------------------------------------------------------------
82#endif // UDPTransport_H_
83// -------------------------------------------------------------------------
Definition UDPTransport.h:30
Definition UDPTransport.h:57
Definition UNetTransport.h:27
Definition UNetTransport.h:47
Definition UniXML.h:44
Definition Calibration.h:27