forked from microsoft/AirSim
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathUdpSocket.hpp
56 lines (40 loc) · 1.46 KB
/
UdpSocket.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#ifndef MavLinkCom_UdpSocket_hpp
#define MavLinkCom_UdpSocket_hpp
#include <string>
#include <memory>
namespace mavlinkcom_impl {
class UdpSocketImpl;
}
namespace mavlinkcom {
class UdpSocket;
// This class represents a simple single-threaded Socket interface specific for Udp connections
// Basic socket functions are exposed through this
class UdpSocket
{
public:
UdpSocket();
// initiate a connection on a socket
int connect(const std::string& addr, int port);
// bind the socket to an address
int bind(const std::string& localaddr, int port);
void close();
// Send message on a socket
// Used when the socket is in a connected state (so that the intended recipient is known)
int send(const void *pkt, size_t size);
// Send message to the specified address, port
int sendto(const void *buf, size_t size, const std::string& address, uint16_t port);
// Receive message on socket
int recv(void *pkt, size_t size, uint32_t timeout_ms);
// return the IP address and port of the last received packet
void last_recv_address(std::string& ip_addr, uint16_t &port);
bool reuseaddress();
void set_broadcast(void);
public:
//needed for piml pattern
~UdpSocket();
private:
std::unique_ptr<mavlinkcom_impl::UdpSocketImpl> pImpl;
friend class mavlinkcom_impl::UdpSocketImpl;
};
}
#endif