-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathendpoint.h
76 lines (60 loc) · 1.22 KB
/
endpoint.h
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#ifndef ENDPOINT_T_H
#define ENDPOINT_T_H
#include <string>
#include <memory>
#include <stdexcept>
#include <sys/socket.h>
class endpoint_t
{
public:
static endpoint_t* create(const std::string &url);
virtual int family() const noexcept = 0;
virtual ~endpoint_t() = default;
};
class ipv4_endpoint_t : public endpoint_t
{
public:
ipv4_endpoint_t(const std::string &endpoint);
int family() const noexcept override
{
return AF_INET;
}
std::uint32_t address() const noexcept
{
return address_;
}
std::uint16_t port() const noexcept
{
return port_;
}
private:
void parse_text(const std::string &endpoint);
private:
std::uint32_t address_;
std::uint16_t port_;
};
#ifndef NO_CAN_SOCKETS
class can_endpoint_t : public endpoint_t
{
public:
can_endpoint_t(const std::string &device);
int family() const noexcept override
{
return AF_CAN;
}
const char* device() const noexcept
{
return device_.c_str();
}
private:
std::string device_;
};
#endif
class bad_endpoint_t : public std::runtime_error
{
public:
bad_endpoint_t()
: std::runtime_error("bad endpoint")
{}
};
#endif // ENDPOINT_T_H