-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathendpoint.h
More file actions
44 lines (27 loc) · 800 Bytes
/
Copy pathendpoint.h
File metadata and controls
44 lines (27 loc) · 800 Bytes
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
#ifndef __ENDPOINT_H__
#define __ENDPOINT_H__
#include <string_view>
#include <string>
#include <cstring>
#include "sys/socket.h"
#include "netinet/in.h"
#include "arpa/inet.h"
namespace async::net {
class endpoint {
public:
endpoint(const char* ip, int port)noexcept {
memset(&_address, 0, sizeof(_address));
_address.sin_family = AF_INET;
_address.sin_port = ::htons(port);
inet_aton(ip, &_address.sin_addr);
}
endpoint(const std::string& ip, int port)noexcept {
endpoint(ip.c_str(), port);
}
sockaddr_in& address()noexcept { return _address; }
socklen_t size()noexcept { return sizeof(_address); }
private:
sockaddr_in _address;
};
}
#endif