25#ifndef MYSQL_HARNESS_NET_TS_SOCKET_H_
26#define MYSQL_HARNESS_NET_TS_SOCKET_H_
30#include <system_error>
40#include <netinet/in.h>
41#include <netinet/ip6.h>
42#include <netinet/tcp.h>
47#include <sys/sockio.h>
65namespace socket_option {
75template <
int Level,
int Name,
class T,
class V = T>
88 template <
typename Protocol>
93 template <
typename Protocol>
98 template <
typename Protocol>
100 return std::addressof(
value_);
103 template <
typename Protocol>
105 return std::addressof(
value_);
108 template <
typename Protocol>
113 template <
class Protocol>
115 if (s !=
sizeof(
value_)) {
116 throw std::length_error(
"size != sizeof(value_)");
127template <
int Level,
int Name>
133template <
int Level,
int Name>
194 std::array<impl::socket::iovec_base, 16>
iov_{};
197 template <
class BufferSequence>
198 explicit msg_hdr(
const BufferSequence &buffers)
200 const size_t iovs_capacity =
iov_.size();
205 (i < iovs_capacity) && (bufcur != bufend); ++i, ++bufcur) {
208 const_cast<CHAR *
>(
reinterpret_cast<const CHAR *
>(bufcur->data()));
209 iov_[i].len =
static_cast<DWORD
>(bufcur->size());
211 iov_[i] = {
const_cast<void *
>(bufcur->data()), bufcur->size()};
216 this->lpBuffers =
iov_.data();
217 this->dwBufferCount =
static_cast<DWORD
>(i);
219 this->msg_iov =
iov_.data();
220 this->msg_iovlen = i;
229 template <
class endpo
int_type>
232 this->
name =
static_cast<SOCKADDR *
>(ep.data());
233 this->namelen = ep.capacity();
235 this->msg_name = ep.data();
236 this->msg_namelen = ep.capacity();
243 template <
class endpo
int_type>
246 ep.resize(this->namelen);
248 ep.resize(this->msg_namelen);
255 template <
class endpo
int_type>
259 const_cast<SOCKADDR *
>(
static_cast<const SOCKADDR *
>(ep.data()));
260 this->namelen = ep.size();
262 this->msg_name =
const_cast<void *
>(ep.data());
263 this->msg_namelen = ep.size();
279 :
value_{e,
static_cast<decltype(
value_.l_linger)
>(t.count())} {}
288 value_.l_linger =
static_cast<int>(t.count());
291 template <
class Protocol>
296 template <
class Protocol>
301 template <
class Protocol>
303 return std::addressof(
value_);
306 template <
class Protocol>
308 return std::addressof(
value_);
311 template <
class Protocol>
316 template <
class Protocol>
318 if (s !=
sizeof(
value_)) {
319 throw std::length_error(
"size != sizeof(::linger)");
349 io_ctx_{std::move(rhs.io_ctx_)} {}
406 if (!res)
return res;
461 static_cast<char>(-1)
469template <
typename Protocol>
488 if (
this == std::addressof(rhs)) {
508 protocol.family(), protocol.type() |
flags, protocol.protocol());
511 if ((
flags & SOCK_NONBLOCK) != 0) {
516 return assign(protocol, res.value());
533 reinterpret_cast<const struct
sockaddr *
>(endpoint.data()),
539 socklen_t *endpoint_size,
546 }
else if (res.error() != std::errc::operation_not_supported) {
556 return {std::in_place, io_ctx,
protocol_, std::move(res.value())};
561 return accept(io_ctx,
static_cast<struct
sockaddr *
>(
nullptr),
nullptr,
568 socklen_t endpoint_len = endpoint.capacity();
570 auto res =
accept(io_ctx,
static_cast<struct
sockaddr *
>(endpoint.data()),
571 &endpoint_len,
flags);
573 endpoint.resize(endpoint_len);
583 template <
typename SettableSocketOption>
585 const SettableSocketOption &option) {
591 template <
typename GettableSocketOption>
593 GettableSocketOption &option)
const {
594 socklen_t option_len = option.size(
protocol_);
599 if (!res)
return res;
608 size_t ep_len = ep.capacity();
622 size_t ep_len = ep.capacity();
635 template <
unsigned long Name,
class T>
645 constexpr unsigned long name()
const {
return Name; }
666 template <
class IoControlCommand>
678 if (ioc.
value() < 0) {
683 return static_cast<size_t>(ioc.
value());
698 static_cast<int>(st));
709template <
typename Protocol>
734 auto res =
open(endpoint.protocol());
735 if (!res)
return res;
739 reinterpret_cast<const struct
sockaddr *
>(endpoint.data()),
743 template <
class CompletionToken>
748 auto res =
open(endpoint.protocol());
750 init.completion_handler(res.error());
758 std::move(
init.completion_handler)]() {
760 const auto old_non_blocking = native_non_blocking();
761 if (old_non_blocking == false) native_non_blocking(true);
763 auto res = connect(endpoint);
766 if (old_non_blocking == false) native_non_blocking(false);
771 const auto ec = res.error();
774 make_error_condition(std::errc::operation_in_progress))
775 && (ec != make_error_condition(
776 std::errc::operation_would_block)) ) {
779 get_executor().context().async_wait(
780 native_handle(), net::socket_base::wait_write,
781 [this, __compl_handler = std::move(__compl_handler)](
782 std::error_code ec) mutable {
789 net::socket_base::error so_error;
791 auto res = get_option(so_error);
793 __compl_handler(res.error());
799 impl::socket::make_error_code(so_error.value()));
805 return init.result.get();
816 template <
typename SettableSocketOption>
818 const SettableSocketOption &option) {
819 return __base::set_option(option);
822 template <
typename GettableSocketOption>
824 GettableSocketOption &option)
const {
833 return __base::release();
836 constexpr bool is_open()
const {
return __base::is_open(); }
839 return __base::local_endpoint();
843 return __base::remote_endpoint();
847 return __base::available();
853 return __base::non_blocking(
mode);
871#if defined(ALL_COMPILERS_FULLY_SUPPORT_CPP14)
889 template <
typename CompletionToken>
890 auto async_wait(
wait_type w, CompletionToken &&token) {
893 get_executor().context().async_wait(
895 [__compl_handler = std::move(
init.completion_handler)](
896 std::error_code ec)
mutable { __compl_handler(ec); });
898 return init.result.get();
907 template <
typename CompletionToken>
908 typename async_result<std::decay_t<CompletionToken>,
909 void(std::error_code)>::return_type
913 using async_completion_handler_type =
914 typename decltype(
init)::completion_handler_type;
919 explicit ClosureType(async_completion_handler_type &&compl_handler)
921 std::forward<decltype(compl_handler)>(compl_handler)} {}
923 void operator()(std::error_code ec) { compl_handler_(ec); }
926 async_completion_handler_type compl_handler_;
934 get_executor().context().async_wait(
936 ClosureType(std::forward<async_completion_handler_type>(
937 init.completion_handler)));
939 return init.result.get();
969template <
typename Protocol>
998 template <
class MutableBufferSequence>
1003 return this->get_executor().context().socket_service()->recvmsg(
1007 template <
class MutableBufferSequence>
1009 const MutableBufferSequence &buffers) {
1010 return receive(buffers, 0);
1013 template <
class MutableBufferSequence>
1015 const MutableBufferSequence &buffers,
endpoint_type &sender,
1020 auto res = this->get_executor().context().socket_service()->recvmsg(
1031 template <
class MutableBufferSequence>
1033 const MutableBufferSequence &buffers,
endpoint_type &sender) {
1034 return receive_from(buffers, sender, 0);
1037 template <
class MutableBufferSequence>
1039 const MutableBufferSequence &buffers) {
1040 return receive(buffers);
1043 template <
class ConstBufferSequence>
1050 return this->get_executor().context().socket_service()->sendmsg(
1054 template <
class ConstBufferSequence>
1056 const ConstBufferSequence &buffers) {
1059 return send(buffers, 0);
1062 template <
class ConstBufferSequence>
1064 const ConstBufferSequence &buffers,
const endpoint_type &recipient,
1071 return this->get_executor().context().socket_service()->sendmsg(
1075 template <
class ConstBufferSequence>
1077 const ConstBufferSequence &buffers,
const endpoint_type &recipient) {
1080 return send_to(buffers, recipient, 0);
1083 template <
class ConstBufferSequence>
1085 const ConstBufferSequence &buffers) {
1088 return send(buffers);
1096 template <
class MutableBufferSequence,
class CompletionToken>
1099 CompletionToken &&token) {
1107 return init.result.get();
1110 this->get_executor().context().async_wait(
1112 [
this, __compl_handler = std::move(
init.completion_handler), &buffers,
1113 __fd = this->native_handle(),
1114 __flags =
flags](std::error_code ec)
mutable {
1116 __compl_handler(ec, 0);
1122 auto res = this->get_executor().context().socket_service()->recvmsg(
1123 __fd, msgs, __flags);
1125 __compl_handler(res.error(), 0);
1127 __compl_handler({}, res.value());
1131 return init.result.get();
1134 template <
class MutableBufferSequence,
class CompletionToken>
1136 CompletionToken &&token) {
1137 return async_receive(buffers, 0, std::forward<CompletionToken>(token));
1142template <
typename Protocol>
1169 template <
class MutableBufferSequence>
1176 auto res = this->get_executor().context().socket_service()->recvmsg(
1179 if (res && res.value() == 0) {
1187 template <
class MutableBufferSequence>
1189 const MutableBufferSequence &buffers) {
1190 return receive(buffers, 0);
1193 template <
class MutableBufferSequence>
1195 const MutableBufferSequence &buffers) {
1196 return receive(buffers);
1199 template <
class ConstBufferSequence>
1208 auto res = this->get_executor().context().socket_service()->sendmsg(
1211 if (res && res.value() == 0) {
1219 template <
class ConstBufferSequence>
1221 const ConstBufferSequence &buffers) {
1224 return send(buffers, 0);
1227 template <
class ConstBufferSequence>
1229 const ConstBufferSequence &buffers) {
1232 return send(buffers);
1240 template <
class MutableBufferSequence,
class CompletionToken>
1243 CompletionToken &&token) {
1250 return init.result.get();
1254 init.completion_handler({}, 0);
1256 return init.result.get();
1271 using compl_handler_type =
typename decltype(
init)::completion_handler_type;
1276 compl_handler_type &&compl_handler,
1277 const MutableBufferSequence &buffers,
1280 : socket_service_{socket_service},
1281 compl_handler_(std::move(compl_handler)),
1286 Completor(
const Completor &) =
delete;
1287 Completor(Completor &&) =
default;
1289 void operator()(std::error_code ec) {
1291 compl_handler_(ec, 0);
1297 const auto res = socket_service_->recvmsg(native_handle_, msgs, flags_);
1299 compl_handler_(res.error(), 0);
1300 }
else if (res.value() == 0) {
1304 compl_handler_({}, res.value());
1312 compl_handler_type compl_handler_;
1313 const MutableBufferSequence &buffers_;
1318 this->get_executor().context().async_wait(
1320 Completor(this->get_executor().context().socket_service(),
1321 std::move(
init.completion_handler), buffers,
1322 this->native_handle(),
flags));
1324 return init.result.get();
1327 template <
class MutableBufferSequence,
class CompletionToken>
1329 CompletionToken &&token) {
1330 return async_receive(buffers, 0, std::forward<CompletionToken>(token));
1333 template <
class ConstBufferSequence,
class CompletionToken>
1341 init.completion_handler({}, 0);
1343 return init.result.get();
1347 using compl_handler_type =
typename decltype(
init)::completion_handler_type;
1352 compl_handler_type &&compl_handler,
1353 const ConstBufferSequence &buffers,
1356 : socket_service_{socket_service},
1357 compl_handler_(std::move(compl_handler)),
1362 Completor(
const Completor &) =
delete;
1363 Completor(Completor &&) =
default;
1365 void operator()(std::error_code ec) {
1367 compl_handler_(ec, 0);
1373 const auto res = socket_service_->sendmsg(native_handle_, msgs, flags_);
1375 compl_handler_(res.error(), 0);
1377 compl_handler_({}, res.value());
1384 compl_handler_type compl_handler_;
1385 const ConstBufferSequence &buffers_;
1391 this->get_executor().context().async_wait(
1393 Completor(this->get_executor().context().socket_service(),
1394 std::move(
init.completion_handler), buffers,
1395 this->native_handle(),
flags));
1397 return init.result.get();
1400 template <
class ConstBufferSequence,
class CompletionToken>
1401 auto async_send(
const ConstBufferSequence &buffers, CompletionToken &&token) {
1404 return async_send(buffers, 0, std::forward<CompletionToken>(token));
1409template <
typename AcceptableProtocol>
1435 return __base::assign(protocol, native_acceptor);
1439 return __base::release();
1444 constexpr bool is_open()
const {
return __base::is_open(); }
1450 template <
typename SettableSocketOption>
1452 const SettableSocketOption &option) {
1453 return __base::set_option(option);
1456 template <
typename GettableSocketOption>
1458 GettableSocketOption &option)
const {
1465 return __base::non_blocking(
mode);
1483 return __base::local_endpoint();
1500 if (accept_res || enable_connection_aborted() ||
1501 accept_res.error() !=
1510 return accept(get_executor().context(), endpoint,
flags);
1520 if (accept_res || enable_connection_aborted() ||
1521 accept_res.error() !=
1528 template <
class CompletionToken>
1536 [
this, __compl_handler = std::move(
init.completion_handler),
1538 &io_ctx](std::error_code ec)
mutable {
1545 auto res = this->get_executor().context().socket_service()->accept(
1546 __fd,
nullptr,
nullptr);
1548 if (!res && !enable_connection_aborted() &&
1555 __compl_handler(res.error(),
socket_type(io_ctx));
1557 __compl_handler({},
socket_type{io_ctx, __protocol, res.value()});
1563 return init.result.get();
1566 template <
class CompletionToken>
1568 return async_accept(get_executor().context(), endpoint,
1569 std::forward<CompletionToken>(token));
1583 template <
class CompletionToken>
1585 CompletionToken &&token) {
1594 [
this, __compl_handler = std::move(
init.completion_handler),
1595 __protocol = protocol_, __fd =
native_handle(), &__ep = endpoint,
1596 &io_ctx](std::error_code ec)
mutable {
1603 socklen_t endpoint_len = __ep.capacity();
1605 auto res = this->get_executor().context().socket_service()->accept(
1606 __fd,
static_cast<sockaddr *
>(__ep.data()), &endpoint_len);
1608 if (!res && !enable_connection_aborted() &&
1615 __compl_handler(res.error(),
socket_type(io_ctx));
1617 __ep.resize(endpoint_len);
1619 __compl_handler({},
socket_type{io_ctx, __protocol, res.value()});
1625 return init.result.get();
1628 template <
class CompletionToken>
1630 return async_accept(get_executor().context(),
1631 std::forward<CompletionToken>(token));
1638#if defined(ALL_COMPILERS_FULLY_SUPPORT_CPP14)
1656 template <
typename CompletionToken>
1657 auto async_wait(
wait_type w, CompletionToken &&token) {
1660 get_executor().context().async_wait(
1662 [__compl_handler = std::move(
init.completion_handler)](
1663 std::error_code ec)
mutable { __compl_handler(ec); });
1665 return init.result.get();
1674 template <
typename CompletionToken>
1675 typename async_result<std::decay_t<CompletionToken>,
1676 void(std::error_code)>::return_type
1680 using async_completion_handler_type =
1681 typename decltype(
init)::completion_handler_type;
1686 explicit ClosureType(async_completion_handler_type &&compl_handler)
1688 std::forward<decltype(compl_handler)>(compl_handler)} {}
1690 void operator()(std::error_code ec) { compl_handler_(ec); }
1693 async_completion_handler_type compl_handler_;
1701 get_executor().context().async_wait(
1703 ClosureType(std::forward<async_completion_handler_type>(
1704 init.completion_handler)));
1706 return init.result.get();
1712 bool enable_connection_aborted_{
false};
1729template <
class Protocol,
class Endpo
intSequence,
class ConnectCondition>
1732 ConnectCondition c) {
1745template <
class Protocol,
class Endpo
intSequence>
1748 return connect(s, endpoints, [](
auto,
auto) {
return true; });
1763template <
class Protocol,
class InputIterator,
class ConnectCondition>
1766 ConnectCondition c) {
1770 for (InputIterator cur = first; cur !=
last; ++cur) {
1772 if (!c(ec, *cur))
continue;
1774 auto res = s.
close();
1780 res = s.
open(
typename Protocol::endpoint(*cur).protocol());
1797template <
class Protocol,
class InputIterator,
class ConnectCondition>
1800 return connect(s, first,
last, [](
auto,
auto) {
return true; });
1805#if defined(MYSQL_HARNESS_HEADER_ONLY)
Definition: protocol.h:32
Definition: executor.h:71
stdx::expected< size_t, std::error_code > send_to(const ConstBufferSequence &buffers, const endpoint_type &recipient)
Definition: socket.h:1076
stdx::expected< size_t, std::error_code > receive_from(const MutableBufferSequence &buffers, endpoint_type &sender)
Definition: socket.h:1032
stdx::expected< bool, error_type > shutdown(socket_base::shutdown_type st) const
Definition: socket.h:1091
basic_datagram_socket & operator=(const basic_datagram_socket &)=delete
basic_datagram_socket(const basic_datagram_socket &)=delete
basic_datagram_socket(io_context &ctx, const protocol_type &proto)
Definition: socket.h:980
stdx::expected< size_t, std::error_code > receive(const MutableBufferSequence &buffers, socket_base::message_flags flags)
Definition: socket.h:999
basic_datagram_socket(io_context &ctx, const protocol_type &protocol, const native_handle_type &native_handle)
Definition: socket.h:994
stdx::expected< size_t, std::error_code > receive_from(const MutableBufferSequence &buffers, endpoint_type &sender, socket_base::message_flags flags)
Definition: socket.h:1014
basic_datagram_socket(basic_datagram_socket &&other)=default
stdx::expected< size_t, std::error_code > receive(const MutableBufferSequence &buffers)
Definition: socket.h:1008
stdx::expected< size_t, std::error_code > send(const ConstBufferSequence &buffers, socket_base::message_flags flags)
Definition: socket.h:1044
auto async_receive(const MutableBufferSequence &buffers, socket_base::message_flags flags, CompletionToken &&token)
Definition: socket.h:1097
basic_datagram_socket & operator=(basic_datagram_socket &&)=default
stdx::expected< size_t, std::error_code > read_some(const MutableBufferSequence &buffers)
Definition: socket.h:1038
stdx::expected< size_t, std::error_code > send(const ConstBufferSequence &buffers)
Definition: socket.h:1055
basic_datagram_socket(io_context &ctx)
Definition: socket.h:979
stdx::expected< size_t, std::error_code > send_to(const ConstBufferSequence &buffers, const endpoint_type &recipient, socket_base::message_flags flags)
Definition: socket.h:1063
~basic_datagram_socket()=default
stdx::expected< size_t, std::error_code > write_some(const ConstBufferSequence &buffers)
Definition: socket.h:1084
auto async_receive(const MutableBufferSequence &buffers, CompletionToken &&token)
Definition: socket.h:1135
Definition: socket.h:1411
basic_socket_acceptor(io_context &ctx)
Definition: socket.h:1422
typename protocol_type::endpoint endpoint_type
Definition: socket.h:1419
auto async_accept(io_context &io_ctx, endpoint_type &endpoint, CompletionToken &&token)
accept a connection with endpoint async'.
Definition: socket.h:1584
std::error_code error_type
Definition: socket.h:1420
stdx::expected< endpoint_type, error_type > local_endpoint() const
Definition: socket.h:1482
bool native_non_blocking() const
Definition: socket.h:1468
bool non_blocking() const
Definition: socket.h:1462
stdx::expected< void, error_type > assign(const protocol_type &protocol, const native_handle_type &native_acceptor)
Definition: socket.h:1432
stdx::expected< native_handle_type, error_type > release()
Definition: socket.h:1438
async_result< std::decay_t< CompletionToken >, void(std::error_code)>::return_type async_wait(wait_type w, CompletionToken &&token)
Definition: socket.h:1677
stdx::expected< socket_type, error_type > accept(int flags=0)
Definition: socket.h:1490
native_handle_type native_handle() const
Definition: socket.h:1442
stdx::expected< void, error_type > listen(int backlog)
Definition: socket.h:1478
stdx::expected< void, error_type > open(const protocol_type &protocol=protocol_type(), int flags=0)
Definition: socket.h:1427
AcceptableProtocol protocol_type
Definition: socket.h:1417
stdx::expected< socket_type, error_type > accept(endpoint_type &endpoint, int flags=0)
Definition: socket.h:1508
typename protocol_type::socket socket_type
Definition: socket.h:1418
stdx::expected< void, error_type > bind(const endpoint_type &endpoint)
Definition: socket.h:1474
stdx::expected< socket_type, error_type > accept(io_context &io_ctx, endpoint_type &endpoint, int flags=0)
Definition: socket.h:1513
stdx::expected< void, error_type > close()
Definition: socket.h:1446
auto async_accept(endpoint_type &endpoint, CompletionToken &&token)
Definition: socket.h:1567
executor_type get_executor() noexcept
Definition: socket.h:1425
protocol_type protocol_
Definition: socket.h:1711
stdx::expected< void, std::error_code > wait(socket_base::wait_type wt)
Definition: socket.h:1634
auto async_accept(CompletionToken &&token)
Definition: socket.h:1629
stdx::expected< void, error_type > cancel()
Definition: socket.h:1448
bool enable_connection_aborted() const
Definition: socket.h:1488
stdx::expected< void, std::error_code > native_non_blocking(bool mode)
Definition: socket.h:1470
auto async_accept(io_context &io_ctx, CompletionToken &&token)
Definition: socket.h:1529
stdx::expected< void, error_type > get_option(GettableSocketOption &option) const
Definition: socket.h:1457
stdx::expected< void, std::error_code > non_blocking(bool mode)
Definition: socket.h:1464
constexpr bool is_open() const
Definition: socket.h:1444
stdx::expected< socket_type, error_type > accept(io_context &io_ctx, int flags=0)
Definition: socket.h:1494
stdx::expected< void, error_type > set_option(const SettableSocketOption &option)
Definition: socket.h:1451
constexpr IoControl(value_type v)
Definition: socket.h:642
constexpr value_type value() const
Definition: socket.h:649
constexpr IoControl()
Definition: socket.h:640
T value_type
Definition: socket.h:638
constexpr void * data()
Definition: socket.h:647
constexpr unsigned long name() const
Definition: socket.h:645
value_type val_
Definition: socket.h:652
template-less base-class of basic_socket_impl.
Definition: socket.h:334
stdx::expected< void, std::error_code > native_non_blocking(bool mode)
Definition: socket.h:393
io_context * io_ctx_
Definition: socket.h:465
basic_socket_impl_base & operator=(const basic_socket_impl_base &rhs)=delete
bool non_blocking_
Definition: socket.h:451
stdx::expected< void, std::error_code > non_blocking(bool mode)
Definition: socket.h:373
constexpr bool non_blocking() const
Definition: socket.h:371
constexpr native_handle_type native_handle() const noexcept
Definition: socket.h:363
constexpr basic_socket_impl_base(io_context &ctx)
Definition: socket.h:339
stdx::expected< native_handle_type, std::error_code > release()
Definition: socket.h:441
stdx::expected< void, std::error_code > cancel()
Definition: socket.h:431
native_handle_type native_handle_
Definition: socket.h:449
stdx::expected< void, std::error_code > close()
Definition: socket.h:415
char native_non_blocking_
Definition: socket.h:452
executor_type get_executor() noexcept
Definition: socket.h:413
impl::socket::native_handle_type native_handle_type
Definition: socket.h:336
basic_socket_impl_base(const basic_socket_impl_base &rhs)=delete
basic_socket_impl_base & operator=(basic_socket_impl_base &&rhs) noexcept
Definition: socket.h:351
bool native_non_blocking() const
Definition: socket.h:383
basic_socket_impl_base(basic_socket_impl_base &&rhs) noexcept
Definition: socket.h:344
constexpr bool is_open() const noexcept
Definition: socket.h:367
~basic_socket_impl_base()=default
typename protocol_type::socket socket_type
Definition: socket.h:478
basic_socket_impl(basic_socket_impl &&rhs)=default
Protocol protocol_type
Definition: socket.h:475
stdx::expected< endpoint_type, error_type > local_endpoint() const
Definition: socket.h:606
stdx::expected< void, error_type > bind(const endpoint_type &endpoint)
Definition: socket.h:530
stdx::expected< socket_type, error_type > accept(io_context &io_ctx, int flags=0)
Definition: socket.h:559
~basic_socket_impl()
Definition: socket.h:498
stdx::expected< endpoint_type, error_type > remote_endpoint() const
Definition: socket.h:620
stdx::expected< void, error_type > open(const protocol_type &protocol=protocol_type(), int flags=0)
Definition: socket.h:502
stdx::expected< void, std::error_code > wait(socket_base::wait_type wt)
Definition: socket.h:701
stdx::expected< bool, error_type > at_mark() const
Definition: socket.h:686
typename protocol_type::endpoint endpoint_type
Definition: socket.h:476
stdx::expected< void, error_type > listen(int backlog=socket_base::max_listen_connections)
Definition: socket.h:578
basic_socket_impl(const basic_socket_impl &)=delete
stdx::expected< void, error_type > assign(const protocol_type &protocol, const native_handle_type &native_handle)
Definition: socket.h:519
stdx::expected< void, error_type > get_option(GettableSocketOption &option) const
Definition: socket.h:592
stdx::expected< void, error_type > set_option(const SettableSocketOption &option)
Definition: socket.h:584
constexpr basic_socket_impl(io_context &ctx) noexcept
Definition: socket.h:480
protocol_type protocol_
Definition: socket.h:706
std::error_code error_type
Definition: socket.h:477
stdx::expected< void, error_type > io_control(IoControlCommand &cmd) const
Definition: socket.h:667
stdx::expected< void, error_type > shutdown(socket_base::shutdown_type st) const
Definition: socket.h:695
basic_socket_impl & operator=(basic_socket_impl &&rhs) noexcept
Definition: socket.h:487
stdx::expected< socket_type, error_type > accept(io_context &io_ctx, endpoint_type &endpoint, int flags=0)
Definition: socket.h:565
stdx::expected< socket_type, error_type > accept(io_context &io_ctx, struct sockaddr *endpoint_data, socklen_t *endpoint_size, int flags=0)
Definition: socket.h:537
stdx::expected< size_t, error_type > available() const
Definition: socket.h:672
basic_socket_impl & operator=(const basic_socket_impl &)=delete
stdx::expected< void, error_type > cancel()
Definition: socket.h:830
stdx::expected< size_t, error_type > available() const
Definition: socket.h:846
stdx::expected< void, std::error_code > native_non_blocking(bool mode)
Definition: socket.h:858
stdx::expected< void, error_type > set_option(const SettableSocketOption &option)
Definition: socket.h:817
bool non_blocking() const
Definition: socket.h:850
Protocol protocol_type
Definition: socket.h:715
stdx::expected< native_handle_type, error_type > release()
Definition: socket.h:832
stdx::expected< void, error_type > close()
Definition: socket.h:828
async_result< std::decay_t< CompletionToken >, void(std::error_code)>::return_type async_wait(wait_type w, CompletionToken &&token)
Definition: socket.h:910
executor_type get_executor() noexcept
Definition: socket.h:720
stdx::expected< void, error_type > connect(const endpoint_type &endpoint)
Definition: socket.h:732
basic_socket(basic_socket &&other)=default
constexpr bool is_open() const
Definition: socket.h:836
native_handle_type native_handle() const noexcept
Definition: socket.h:812
stdx::expected< void, error_type > shutdown(socket_base::shutdown_type st) const
Definition: socket.h:866
auto async_connect(const endpoint_type &endpoint, CompletionToken &&token)
Definition: socket.h:744
bool native_non_blocking() const
Definition: socket.h:856
stdx::expected< void, error_type > bind(const endpoint_type &endpoint)
Definition: socket.h:808
basic_socket & operator=(basic_socket &&)=default
basic_socket(const basic_socket &)=delete
stdx::expected< void, error_type > assign(const protocol_type &protocol, const native_handle_type &native_handle)
Definition: socket.h:722
basic_socket & operator=(const basic_socket &)=delete
basic_socket(io_context &ctx, const protocol_type &proto)
Definition: socket.h:946
basic_socket(io_context &ctx, const protocol_type &proto, const native_handle_type &native_handle)
Definition: socket.h:949
stdx::expected< void, error_type > get_option(GettableSocketOption &option) const
Definition: socket.h:823
stdx::expected< endpoint_type, error_type > remote_endpoint() const
Definition: socket.h:842
stdx::expected< void, error_type > open(const protocol_type &protocol=protocol_type(), int flags=0)
Definition: socket.h:727
basic_socket(io_context &ctx)
Definition: socket.h:944
stdx::expected< endpoint_type, error_type > local_endpoint() const
Definition: socket.h:838
stdx::expected< void, std::error_code > non_blocking(bool mode)
Definition: socket.h:852
stdx::expected< void, std::error_code > wait(socket_base::wait_type wt)
Definition: socket.h:862
Definition: socket.h:1143
stdx::expected< size_t, std::error_code > send(const ConstBufferSequence &buffers)
Definition: socket.h:1220
stdx::expected< size_t, std::error_code > read_some(const MutableBufferSequence &buffers)
Definition: socket.h:1194
stdx::expected< void, error_type > shutdown(socket_base::shutdown_type st) const
Definition: socket.h:1235
stdx::expected< size_t, std::error_code > receive(const MutableBufferSequence &buffers)
Definition: socket.h:1188
basic_stream_socket(const basic_stream_socket &)=delete
auto async_send(const ConstBufferSequence &buffers, CompletionToken &&token)
Definition: socket.h:1401
auto async_receive(const MutableBufferSequence &buffers, CompletionToken &&token)
Definition: socket.h:1328
stdx::expected< size_t, std::error_code > write_some(const ConstBufferSequence &buffers)
Definition: socket.h:1228
basic_stream_socket(io_context &ctx, const protocol_type &protocol, const native_handle_type &native_handle)
Definition: socket.h:1165
basic_stream_socket(basic_stream_socket &&other)=default
stdx::expected< size_t, std::error_code > receive(const MutableBufferSequence &buffers, socket_base::message_flags flags)
Definition: socket.h:1170
auto async_send(const ConstBufferSequence &buffers, socket_base::message_flags flags, CompletionToken &&token)
Definition: socket.h:1334
stdx::expected< size_t, std::error_code > send(const ConstBufferSequence &buffers, socket_base::message_flags flags)
Definition: socket.h:1200
basic_stream_socket(io_context &ctx)
Definition: socket.h:1152
basic_stream_socket & operator=(basic_stream_socket &&)=default
~basic_stream_socket()=default
auto async_receive(const MutableBufferSequence &buffers, socket_base::message_flags flags, CompletionToken &&token)
Definition: socket.h:1241
basic_stream_socket & operator=(const basic_stream_socket &)=delete
basic_stream_socket(io_context &ctx, const protocol_type &proto)
Definition: socket.h:1153
Definition: socket_service_base.h:47
virtual stdx::expected< void, error_type > ioctl(native_handle_type native_handle, unsigned long cmd, void *data) const =0
virtual stdx::expected< void, error_type > bind(native_handle_type native_handle, const struct sockaddr *addr, size_t addr_len) const =0
virtual stdx::expected< void, error_type > getsockopt(native_handle_type native_handle, int level, int optname, void *optval, socklen_t *optlen) const =0
virtual stdx::expected< void, error_type > getsockname(native_handle_type native_handle, struct sockaddr *addr, size_t *addr_len) const =0
virtual stdx::expected< native_handle_type, error_type > socket(int family, int sock_type, int protocol) const =0
virtual stdx::expected< void, error_type > close(native_handle_type native_handle) const =0
virtual stdx::expected< void, error_type > getpeername(native_handle_type native_handle, struct sockaddr *addr, size_t *addr_len) const =0
virtual stdx::expected< native_handle_type, error_type > accept(native_handle_type native_handle, struct sockaddr *addr, socklen_t *addr_len) const =0
virtual stdx::expected< native_handle_type, error_type > accept4(native_handle_type native_handle, struct sockaddr *addr, socklen_t *addr_len, int flags=0) const =0
virtual stdx::expected< void, error_type > setsockopt(native_handle_type native_handle, int level, int optname, const void *optval, socklen_t optlen) const =0
virtual stdx::expected< bool, error_type > native_non_blocking(native_handle_type native_handle) const =0
virtual stdx::expected< void, error_type > listen(native_handle_type native_handle, int backlog) const =0
virtual stdx::expected< void, error_type > connect(native_handle_type native_handle, const struct sockaddr *addr, size_t addr_len) const =0
virtual stdx::expected< void, error_type > wait(native_handle_type fd, wait_type wt) const =0
virtual stdx::expected< void, error_type > shutdown(native_handle_type fd, int how) const =0
Definition: io_context.h:989
io_context & context() const noexcept
Definition: io_context.h:1001
Definition: io_context.h:60
impl::socket::SocketServiceBase * socket_service() const
Definition: io_context.h:134
void async_wait(native_handle_type fd, impl::socket::wait_type wt, Op &&op)
Definition: io_context.h:482
executor_type get_executor() noexcept
Definition: io_context.h:1079
stdx::expected< void, std::error_code > cancel(native_handle_type fd)
cancel all async-ops of a file-descriptor.
Definition: io_context.h:1086
socket option for SO_LINGER
Definition: socket.h:274
linger() noexcept
Definition: socket.h:276
int level(const Protocol &) const noexcept
Definition: socket.h:292
linger(bool e, std::chrono::seconds t) noexcept
Definition: socket.h:278
std::chrono::seconds timeout() const noexcept
Definition: socket.h:284
int name(const Protocol &) const noexcept
Definition: socket.h:297
::linger value_
Definition: socket.h:324
void timeout(std::chrono::seconds t) noexcept
Definition: socket.h:287
void resize(const Protocol &, size_t s)
Definition: socket.h:317
void * data(const Protocol &) noexcept
Definition: socket.h:302
size_t size(const Protocol &) const noexcept
Definition: socket.h:312
void enabled(bool e) noexcept
Definition: socket.h:282
const void * data(const Protocol &) const noexcept
Definition: socket.h:307
bool enabled() const noexcept
Definition: socket.h:281
void set_recipient(const endpoint_type &ep)
set recipient of the message.
Definition: socket.h:256
void set_sender(endpoint_type &ep)
set sender of the message.
Definition: socket.h:230
void resize_sender(endpoint_type &ep)
set the size of the sender after data was received.
Definition: socket.h:244
std::array< impl::socket::iovec_base, 16 > iov_
Definition: socket.h:194
msg_hdr(const BufferSequence &buffers)
Definition: socket.h:198
static constexpr wait_type wait_read
Definition: socket.h:167
static constexpr message_flags message_peek
Definition: socket.h:160
shutdown_type
Definition: socket.h:171
static constexpr shutdown_type shutdown_both
Definition: socket.h:185
static constexpr shutdown_type shutdown_receive
Definition: socket.h:182
static constexpr message_flags message_do_not_route
Definition: socket.h:163
static constexpr message_flags message_out_of_band
Definition: socket.h:161
impl::socket::message_flags message_flags
Definition: socket.h:158
static const int max_listen_connections
Definition: socket.h:187
static constexpr shutdown_type shutdown_send
Definition: socket.h:184
static constexpr wait_type wait_write
Definition: socket.h:168
static constexpr wait_type wait_error
Definition: socket.h:169
base-class of socket options.
Definition: socket.h:76
storage_type * data(const Protocol &)
Definition: socket.h:104
constexpr option_base()
Definition: socket.h:81
constexpr int name(const Protocol &) const noexcept
Definition: socket.h:94
storage_type value_
Definition: socket.h:121
constexpr int level(const Protocol &) const noexcept
Definition: socket.h:89
V storage_type
Definition: socket.h:79
T value_type
Definition: socket.h:78
constexpr size_t size(const Protocol &) const
Definition: socket.h:109
void resize(const Protocol &, size_t s)
Definition: socket.h:114
value_type value() const
Definition: socket.h:86
const storage_type * data(const Protocol &) const
Definition: socket.h:99
constexpr option_base(value_type v)
Definition: socket.h:83
Definition: expected.h:943
static int flags[50]
Definition: hp_test1.cc:39
mysql_service_status_t send(const char *tag, const unsigned char *data, const size_t data_length) noexcept
Definition: message_service.cc:31
Definition: authentication.cc:35
std::error_code make_error_code(DynamicLoaderErrc ec)
make error_code from a DynamicLoaderErrc.
Definition: dynamic_loader.cc:78
stdx::expected< void, error_type > listen(native_handle_type native_handle, int backlog)
Definition: socket.h:148
stdx::expected< native_handle_type, error_type > socket(int family, int sock_type, int protocol)
Definition: socket.h:62
stdx::expected< void, std::error_code > init()
Definition: socket.h:672
stdx::expected< void, error_type > bind(native_handle_type native_handle, const struct sockaddr *addr, size_t addr_len)
wrap bind() in a portable way.
Definition: socket.h:338
stdx::expected< void, error_type > native_non_blocking(native_handle_type native_handle, bool on)
Definition: socket.h:120
stdx::expected< native_handle_type, error_type > accept(native_handle_type native_handle, struct sockaddr *addr, socklen_t *addr_len)
wrap accept() in a portable way.
Definition: socket.h:366
stdx::expected< void, std::error_code > close(native_handle_type native_handle)
Definition: socket.h:74
wait_type
Definition: socket_constants.h:85
::msghdr msghdr_base
Definition: socket_constants.h:59
static constexpr message_flags message_out_of_band
Definition: socket_constants.h:66
static constexpr message_flags message_do_not_route
Definition: socket_constants.h:67
std::error_code error_type
Definition: socket_constants.h:54
std::bitset< 31 > message_flags
Definition: socket_constants.h:63
static constexpr message_flags message_peek
Definition: socket_constants.h:65
stdx::expected< void, error_type > shutdown(native_handle_type fd, int how)
Definition: socket.h:662
int native_handle_type
Definition: socket_constants.h:50
constexpr const native_handle_type kInvalidSocket
Definition: socket_constants.h:51
stdx::expected< void, error_type > wait(native_handle_type fd, wait_type wt)
Definition: socket.h:635
const const_buffer * buffer_sequence_end(const const_buffer &b) noexcept
Definition: buffer.h:184
auto defer(CompletionToken &&token)
Definition: executor.h:803
const const_buffer * buffer_sequence_begin(const const_buffer &b) noexcept
Definition: buffer.h:179
size_t buffer_size(const ConstBufferSequence &buffers) noexcept
Definition: buffer.h:314
stdx::expected< InputIterator, std::error_code > connect(basic_socket< Protocol > &s, InputIterator first, InputIterator last)
Definition: socket.h:1798
std::error_condition make_error_condition(net::stream_errc e) noexcept
Definition: buffer.h:106
std::error_code make_error_code(net::stream_errc e) noexcept
Definition: buffer.h:102
Cursor end()
A past-the-end Cursor.
Definition: rules_table_service.cc:191
static int handle(int sql_errno, const char *sqlstate, const char *message, void *state)
Bridge function between the C++ API offered by this module and the C API of the parser service.
Definition: services.cc:63
stdx::expected< int, std::error_code > open(const char *fname, int flags, mode_t mode) noexcept
Definition: file_handle.cc:78
mode
Definition: file_handle.h:59
native_handle_type native_handle()
Definition: process.h:55
constexpr auto make_unexpected(E &&e) -> unexpected< std::decay_t< E > >
Definition: expected.h:124
struct sockaddr sockaddr
Definition: sock_probe_win32.h:62
case opt name
Definition: sslopt-case.h:32
double seconds()
Definition: task.cc:309