-
Notifications
You must be signed in to change notification settings - Fork 3
/
Sock.hpp
89 lines (71 loc) · 2.89 KB
/
Sock.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#ifndef SOCK_DOT_HPP
#define SOCK_DOT_HPP
#include <string>
#include "SockBuffer.hpp"
#include "sa.hpp"
namespace Config {
constexpr auto read_timeout_default = std::chrono::seconds(30);
constexpr auto write_timeout_default = std::chrono::seconds(30);
constexpr auto starttls_timeout_default = std::chrono::seconds(30);
} // namespace Config
class Sock {
public:
Sock(const Sock&) = delete;
Sock& operator=(const Sock&) = delete;
Sock(int fd_in,
int fd_out,
std::function<void(void)> read_hook = []() {},
std::chrono::milliseconds read_timeout = Config::read_timeout_default,
std::chrono::milliseconds write_timeout = Config::write_timeout_default,
std::chrono::milliseconds starttls_timeout
= Config::starttls_timeout_default);
char const* us_c_str() const { return us_addr_str_; }
char const* them_c_str() const { return them_addr_str_; }
std::string const& us_address_literal() const { return us_address_literal_; }
std::string const& them_address_literal() const
{
return them_address_literal_;
}
bool has_peername() const { return them_addr_str_[0] != '\0'; }
bool input_ready(std::chrono::milliseconds wait)
{
return iostream_->input_ready(wait);
}
bool maxed_out() { return iostream_->maxed_out(); }
bool timed_out() { return iostream_->timed_out(); }
std::istream& in() { return iostream_; }
std::ostream& out() { return iostream_; }
bool starttls_server(fs::path config_path)
{
return iostream_->starttls_server(config_path);
}
bool starttls_client(fs::path config_path,
char const* client_name,
char const* server_name,
DNS::RR_collection const& tlsa_rrs,
bool enforce_dane)
{
return iostream_->starttls_client(config_path, client_name, server_name,
tlsa_rrs, enforce_dane);
}
bool tls() { return iostream_->tls(); }
std::string tls_info() { return iostream_->tls_info(); }
bool verified() { return iostream_->verified(); };
void set_max_read(std::streamsize max) { iostream_->set_max_read(max); }
void log_data_on() { iostream_->log_data_on(); }
void log_data_off() { iostream_->log_data_off(); }
void log_stats() { iostream_->log_stats(); }
void log_totals() { iostream_->log_totals(); }
void close_fds() { iostream_->close_fds(); }
private:
boost::iostreams::stream<SockBuffer> iostream_;
socklen_t us_addr_len_{sizeof us_addr_};
socklen_t them_addr_len_{sizeof them_addr_};
sa::sockaddrs us_addr_{};
sa::sockaddrs them_addr_{};
char us_addr_str_[INET6_ADDRSTRLEN]{'\0'};
char them_addr_str_[INET6_ADDRSTRLEN]{'\0'};
std::string us_address_literal_;
std::string them_address_literal_;
};
#endif // SOCK_DOT_HPP