blob: 26033989ed9318dafe51f02241b35f78097a5da0 (
plain)
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 SHARED_NET_NET_HH_
#define SHARED_NET_NET_HH_
#include <arpa/inet.h>
#include <concepts>
#include <cstdint>
#include <cstring>
#include <errno.h>
#include <fcntl.h>
#include <memory>
#include <netdb.h>
#include <netinet/in.h>
#include <optional>
#include <stdexcept>
#include <string.h>
#include <string>
#include <string_view>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <type_traits>
#include <unistd.h>
#include "shared/shared.hh"
namespace shared {
namespace net {
std::string get_net_error(const int code) noexcept;
std::string get_errno_error() noexcept;
std::shared_ptr<addrinfo> get_addr_info(const std::string_view address,
const std::string_view port,
const addrinfo* const hints);
int make_socket(const addrinfo* const info);
void bind_socket(const int socket, const addrinfo* const info);
void connect_socket(const int socket, const addrinfo* const info);
void nonblock_socket(const int sock);
void listen_socket(const int socket);
void* get_info_address(sockaddr& info) noexcept;
void close_socket(const int sock);
// Return socket and the sockaddr_storage we get from an accept call.
struct accept_ret {
sockaddr_storage storage;
int socket;
};
std::optional<accept_ret> get_accept(const int socket);
std::size_t get_backlog_size(const int sock);
std::string get_socket_host_address(const int sock);
std::string get_socket_host_port(const int sock);
std::string get_socket_peer_address(const int sock);
std::string get_socket_peer_port(const int sock);
} // namespace net
} // namespace shared
#endif
|