26#ifndef MYSQL_HARNESS_NET_TS_LOCAL_H_
27#define MYSQL_HARNESS_NET_TS_LOCAL_H_
31#include <system_error>
35#define NET_TS_HAS_UNIX_SOCKET
42#define NET_TS_HAS_UNIX_SOCKET
46#ifdef NET_TS_HAS_UNIX_SOCKET
48#if defined(__FreeBSD__) || defined(__APPLE__)
52#if defined(__linux__) || defined(__OpenBSD__)
53#include <sys/socket.h>
71template <
typename Protocol>
88 const auto truncated_path =
92 std::copy(truncated_path.begin(), truncated_path.end(),
data_.sun_path);
117 constexpr size_t size() const noexcept {
118 return offsetof(sockaddr_un, sun_path) +
path_len_;
133 if (
n >= offsetof(sockaddr_un, sun_path)) {
153 return capacity() - offsetof(sockaddr_un, sun_path);
160template <
typename Protocol>
169 if (
path.size() > 0 &&
path[0] ==
'\0') {
177template <
class Protocol>
183 proto.family(), proto.
type(), proto.protocol());
186 const auto fds = *res;
188 const auto assign1_res = sock1.
assign(proto, fds.first);
196 const auto assign2_res = sock2.
assign(proto, fds.second);
207template <
class Protocol>
213template <
class Protocol>
219namespace socket_option {
220#if defined(__linux__) || defined(__OpenBSD__) || defined(__FreeBSD__) || \
221 defined(__NetBSD__) || defined(__APPLE__)
222template <
int Level,
int Name>
225#if defined(__linux__)
227#elif defined(__OpenBSD__)
229#elif defined(__FreeBSD__) || defined(__APPLE__)
231#elif defined(__NetBSD__)
234#error "unsupported OS"
237 constexpr cred() : value_{} {}
239 constexpr explicit cred(
value_type v) : value_{v} {}
243 template <
typename Protocol>
244 constexpr int level(
const Protocol & )
const noexcept {
248 template <
typename Protocol>
253 template <
typename Protocol>
258 template <
typename Protocol>
268 template <
typename Protocol>
269 constexpr size_t size(
const Protocol & )
const {
280 template <
typename Protocol>
281 void resize(
const Protocol &
p,
size_t new_size) {
284 if (new_size > size(
p)) {
285 throw std::length_error(
286 "overrun in socket_option::cred::resize(): current_size=" +
296 size_t size_{
sizeof(value_)};
319#if defined(__linux__) || defined(__OpenBSD__)
320 using peer_creds = socket_option::cred<SOL_SOCKET, SO_PEERCRED>;
321#elif defined(__FreeBSD__) || defined(__APPLE__)
322 using peer_creds = socket_option::cred<SOL_SOCKET, LOCAL_PEERCRED>;
323#elif defined(__NetBSD__)
324 using peer_creds = socket_option::cred<SOL_SOCKET, LOCAL_PEEREID>;
330 constexpr int family() const noexcept {
return AF_UNIX; }
331 constexpr int type() const noexcept {
return SOCK_STREAM; }
332 constexpr int protocol() const noexcept {
return 0; }
348 constexpr int family() const noexcept {
return AF_UNIX; }
349 constexpr int type() const noexcept {
return SOCK_DGRAM; }
350 constexpr int protocol() const noexcept {
return 0; }
374#if defined(__linux__) || defined(__OpenBSD__) || defined(__FreeBSD__) || \
375 defined(__APPLE__) || defined(__NetBSD__)
376 using peer_creds = stream_protocol::peer_creds;
379 constexpr int family() const noexcept {
return AF_UNIX; }
380 constexpr int type() const noexcept {
return SOCK_SEQPACKET; }
381 constexpr int protocol() const noexcept {
return 0; }
Definition: protocol.h:33
virtual enum enum_protocol_type type() const =0
endpoint of Unix domain sockets (AF_UNIX).
Definition: local.h:72
const void * data() const noexcept
Definition: local.h:110
constexpr size_t capacity() const noexcept
Definition: local.h:121
constexpr protocol_type protocol() const noexcept
Definition: local.h:97
void * data() noexcept
Definition: local.h:112
constexpr basic_endpoint() noexcept
Definition: local.h:76
void resize(size_t n) noexcept
resize data().
Definition: local.h:132
Protocol protocol_type
Definition: local.h:74
size_t path_len_
Definition: local.h:157
constexpr size_t max_path_len() const
Definition: local.h:152
sockaddr_un data_
Definition: local.h:156
basic_endpoint(std::string_view path)
Definition: local.h:85
std::string path() const
get path.
Definition: local.h:102
constexpr size_t size() const noexcept
bytes used data().
Definition: local.h:117
constexpr int type() const noexcept
Definition: local.h:349
constexpr int family() const noexcept
Definition: local.h:348
constexpr int protocol() const noexcept
Definition: local.h:350
constexpr int protocol() const noexcept
Definition: local.h:381
constexpr int type() const noexcept
Definition: local.h:380
constexpr int family() const noexcept
Definition: local.h:379
constexpr int family() const noexcept
Definition: local.h:330
constexpr int type() const noexcept
Definition: local.h:331
constexpr int protocol() const noexcept
Definition: local.h:332
stdx::expected< void, error_type > close()
Definition: socket.h:829
stdx::expected< void, error_type > assign(const protocol_type &protocol, const native_handle_type &native_handle)
Definition: socket.h:723
Definition: socket.h:1144
virtual stdx::expected< void, error_type > close(native_handle_type native_handle) const =0
virtual stdx::expected< std::pair< native_handle_type, native_handle_type >, error_type > socketpair(int family, int sock_type, int protocol) const =0
Definition: io_context.h:61
impl::socket::SocketServiceBase * socket_service() const
Definition: io_context.h:135
Definition: expected.h:944
const char * p
Definition: ctype-mb.cc:1237
static std::string to_string(const LEX_STRING &str)
Definition: lex_string.h:50
static char * path
Definition: mysqldump.cc:137
uint16_t value_type
Definition: vt100.h:184
::std::ostream & operator<<(::std::ostream &os, const basic_endpoint< Protocol > &ep)
Definition: local.h:161
bool operator==(const basic_endpoint< Protocol > &a, const basic_endpoint< Protocol > &b)
Definition: local.h:208
bool operator!=(const basic_endpoint< Protocol > &a, const basic_endpoint< Protocol > &b)
Definition: local.h:214
stdx::expected< void, std::error_code > connect_pair(net::io_context *io_ctx, net::basic_socket< Protocol > &sock1, net::basic_socket< Protocol > &sock2)
Definition: local.h:178
constexpr auto make_unexpected(E &&e) -> unexpected< std::decay_t< E > >
Definition: expected.h:125
case opt name
Definition: sslopt-case.h:33
int n
Definition: xcom_base.cc:509