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 template <
typename CompletionToken>
875 get_executor().context().async_wait(
877 [__compl_handler = std::move(
init.completion_handler)](
878 std::error_code ec)
mutable { __compl_handler(ec); });
880 return init.result.get();
909template <
typename Protocol>
938 template <
class MutableBufferSequence>
943 return this->get_executor().context().socket_service()->recvmsg(
947 template <
class MutableBufferSequence>
949 const MutableBufferSequence &buffers) {
950 return receive(buffers, 0);
953 template <
class MutableBufferSequence>
960 auto res = this->get_executor().context().socket_service()->recvmsg(
971 template <
class MutableBufferSequence>
973 const MutableBufferSequence &buffers,
endpoint_type &sender) {
974 return receive_from(buffers, sender, 0);
977 template <
class MutableBufferSequence>
979 const MutableBufferSequence &buffers) {
980 return receive(buffers);
983 template <
class ConstBufferSequence>
990 return this->get_executor().context().socket_service()->sendmsg(
994 template <
class ConstBufferSequence>
996 const ConstBufferSequence &buffers) {
999 return send(buffers, 0);
1002 template <
class ConstBufferSequence>
1004 const ConstBufferSequence &buffers,
const endpoint_type &recipient,
1011 return this->get_executor().context().socket_service()->sendmsg(
1015 template <
class ConstBufferSequence>
1017 const ConstBufferSequence &buffers,
const endpoint_type &recipient) {
1020 return send_to(buffers, recipient, 0);
1023 template <
class ConstBufferSequence>
1025 const ConstBufferSequence &buffers) {
1028 return send(buffers);
1036 template <
class MutableBufferSequence,
class CompletionToken>
1039 CompletionToken &&token) {
1050 return init.result.get();
1053 this->get_executor().context().async_wait(
1055 [socket_service = this->get_executor().context().socket_service(),
1056 compl_handler = std::move(
init.completion_handler), &buffers,
1058 flags](std::error_code ec)
mutable {
1060 compl_handler(ec, 0);
1068 compl_handler(res.error(), 0);
1070 compl_handler({}, res.value());
1074 return init.result.get();
1077 template <
class MutableBufferSequence,
class CompletionToken>
1079 CompletionToken &&token) {
1083 return async_receive(buffers, 0, std::forward<CompletionToken>(token));
1088template <
typename Protocol>
1115 template <
class MutableBufferSequence>
1122 auto res = this->get_executor().context().socket_service()->recvmsg(
1125 if (res && res.value() == 0) {
1133 template <
class MutableBufferSequence>
1135 const MutableBufferSequence &buffers) {
1136 return receive(buffers, 0);
1139 template <
class MutableBufferSequence>
1141 const MutableBufferSequence &buffers) {
1142 return receive(buffers);
1145 template <
class ConstBufferSequence>
1154 auto res = this->get_executor().context().socket_service()->sendmsg(
1157 if (res && res.value() == 0) {
1165 template <
class ConstBufferSequence>
1167 const ConstBufferSequence &buffers) {
1170 return send(buffers, 0);
1173 template <
class ConstBufferSequence>
1175 const ConstBufferSequence &buffers) {
1178 return send(buffers);
1186 template <
class MutableBufferSequence,
class CompletionToken>
1189 CompletionToken &&token) {
1199 return init.result.get();
1203 init.completion_handler({}, 0);
1205 return init.result.get();
1208 this->get_executor().context().async_wait(
1210 [socket_service = this->get_executor().context().socket_service(),
1211 compl_handler = std::move(
init.completion_handler), buffers,
1214 compl_handler(ec, 0);
1222 compl_handler(res.error(), 0);
1223 }
else if (res.value() == 0) {
1227 compl_handler({}, res.value());
1233 return init.result.get();
1236 template <
class MutableBufferSequence,
class CompletionToken>
1238 CompletionToken &&token) {
1242 return async_receive(buffers, 0, std::forward<CompletionToken>(token));
1245 template <
class ConstBufferSequence,
class CompletionToken>
1252 init.completion_handler({}, 0);
1254 return init.result.get();
1257 this->get_executor().context().async_wait(
1259 [socket_service = this->get_executor().context().socket_service(),
1260 compl_handler = std::move(
init.completion_handler), buffers,
1263 compl_handler(ec, 0);
1271 compl_handler(res.error(), 0);
1273 compl_handler({}, res.value());
1279 return init.result.get();
1282 template <
class ConstBufferSequence,
class CompletionToken>
1283 auto async_send(
const ConstBufferSequence &buffers, CompletionToken &&token) {
1285 return async_send(buffers, 0, std::forward<CompletionToken>(token));
1290template <
typename AcceptableProtocol>
1316 return __base::assign(protocol, native_acceptor);
1320 return __base::release();
1325 constexpr bool is_open()
const {
return __base::is_open(); }
1331 template <
typename SettableSocketOption>
1333 const SettableSocketOption &option) {
1334 return __base::set_option(option);
1337 template <
typename GettableSocketOption>
1339 GettableSocketOption &option)
const {
1346 return __base::non_blocking(
mode);
1364 return __base::local_endpoint();
1381 if (accept_res || enable_connection_aborted() ||
1382 accept_res.error() !=
1391 return accept(get_executor().context(), endpoint,
flags);
1401 if (accept_res || enable_connection_aborted() ||
1402 accept_res.error() !=
1409 template <
class CompletionToken>
1417 [
this, __compl_handler = std::move(
init.completion_handler),
1419 &io_ctx](std::error_code ec)
mutable {
1426 auto res = this->get_executor().context().socket_service()->accept(
1427 __fd,
nullptr,
nullptr);
1429 if (!res && !enable_connection_aborted() &&
1436 __compl_handler(res.error(),
socket_type(io_ctx));
1438 __compl_handler({},
socket_type{io_ctx, __protocol, res.value()});
1444 return init.result.get();
1447 template <
class CompletionToken>
1449 return async_accept(get_executor().context(), endpoint,
1450 std::forward<CompletionToken>(token));
1464 template <
class CompletionToken>
1466 CompletionToken &&token) {
1475 [
this, __compl_handler = std::move(
init.completion_handler),
1476 __protocol = protocol_, __fd =
native_handle(), &__ep = endpoint,
1477 &io_ctx](std::error_code ec)
mutable {
1484 socklen_t endpoint_len = __ep.capacity();
1486 auto res = this->get_executor().context().socket_service()->accept(
1487 __fd,
static_cast<sockaddr *
>(__ep.data()), &endpoint_len);
1489 if (!res && !enable_connection_aborted() &&
1496 __compl_handler(res.error(),
socket_type(io_ctx));
1498 __ep.resize(endpoint_len);
1500 __compl_handler({},
socket_type{io_ctx, __protocol, res.value()});
1506 return init.result.get();
1509 template <
class CompletionToken>
1511 return async_accept(get_executor().context(),
1512 std::forward<CompletionToken>(token));
1519 template <
typename CompletionToken>
1523 get_executor().context().async_wait(
1525 [compl_handler = std::move(
init.completion_handler)](
1526 std::error_code ec)
mutable { compl_handler(ec); });
1528 return init.result.get();
1533 bool enable_connection_aborted_{
false};
1550template <
class Protocol,
class Endpo
intSequence,
class ConnectCondition>
1553 ConnectCondition c) {
1566template <
class Protocol,
class Endpo
intSequence>
1569 return connect(s, endpoints, [](
auto,
auto) {
return true; });
1584template <
class Protocol,
class InputIterator,
class ConnectCondition>
1587 ConnectCondition c) {
1591 for (InputIterator cur = first; cur !=
last; ++cur) {
1593 if (!c(ec, *cur))
continue;
1595 auto res = s.
close();
1601 res = s.
open(
typename Protocol::endpoint(*cur).protocol());
1618template <
class Protocol,
class InputIterator,
class ConnectCondition>
1621 return connect(s, first,
last, [](
auto,
auto) {
return true; });
1626#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:1016
stdx::expected< size_t, std::error_code > receive_from(const MutableBufferSequence &buffers, endpoint_type &sender)
Definition: socket.h:972
stdx::expected< bool, error_type > shutdown(socket_base::shutdown_type st) const
Definition: socket.h:1031
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:920
stdx::expected< size_t, std::error_code > receive(const MutableBufferSequence &buffers, socket_base::message_flags flags)
Definition: socket.h:939
basic_datagram_socket(io_context &ctx, const protocol_type &protocol, const native_handle_type &native_handle)
Definition: socket.h:934
stdx::expected< size_t, std::error_code > receive_from(const MutableBufferSequence &buffers, endpoint_type &sender, socket_base::message_flags flags)
Definition: socket.h:954
basic_datagram_socket(basic_datagram_socket &&other)=default
stdx::expected< size_t, std::error_code > receive(const MutableBufferSequence &buffers)
Definition: socket.h:948
stdx::expected< size_t, std::error_code > send(const ConstBufferSequence &buffers, socket_base::message_flags flags)
Definition: socket.h:984
auto async_receive(const MutableBufferSequence &buffers, socket_base::message_flags flags, CompletionToken &&token)
Definition: socket.h:1037
basic_datagram_socket & operator=(basic_datagram_socket &&)=default
stdx::expected< size_t, std::error_code > read_some(const MutableBufferSequence &buffers)
Definition: socket.h:978
stdx::expected< size_t, std::error_code > send(const ConstBufferSequence &buffers)
Definition: socket.h:995
basic_datagram_socket(io_context &ctx)
Definition: socket.h:919
stdx::expected< size_t, std::error_code > send_to(const ConstBufferSequence &buffers, const endpoint_type &recipient, socket_base::message_flags flags)
Definition: socket.h:1003
~basic_datagram_socket()=default
stdx::expected< size_t, std::error_code > write_some(const ConstBufferSequence &buffers)
Definition: socket.h:1024
auto async_receive(const MutableBufferSequence &buffers, CompletionToken &&token)
Definition: socket.h:1078
Definition: socket.h:1292
basic_socket_acceptor(io_context &ctx)
Definition: socket.h:1303
typename protocol_type::endpoint endpoint_type
Definition: socket.h:1300
auto async_accept(io_context &io_ctx, endpoint_type &endpoint, CompletionToken &&token)
accept a connection with endpoint async'.
Definition: socket.h:1465
std::error_code error_type
Definition: socket.h:1301
stdx::expected< endpoint_type, error_type > local_endpoint() const
Definition: socket.h:1363
bool native_non_blocking() const
Definition: socket.h:1349
bool non_blocking() const
Definition: socket.h:1343
stdx::expected< void, error_type > assign(const protocol_type &protocol, const native_handle_type &native_acceptor)
Definition: socket.h:1313
stdx::expected< native_handle_type, error_type > release()
Definition: socket.h:1319
stdx::expected< socket_type, error_type > accept(int flags=0)
Definition: socket.h:1371
native_handle_type native_handle() const
Definition: socket.h:1323
stdx::expected< void, error_type > listen(int backlog)
Definition: socket.h:1359
stdx::expected< void, error_type > open(const protocol_type &protocol=protocol_type(), int flags=0)
Definition: socket.h:1308
AcceptableProtocol protocol_type
Definition: socket.h:1298
stdx::expected< socket_type, error_type > accept(endpoint_type &endpoint, int flags=0)
Definition: socket.h:1389
typename protocol_type::socket socket_type
Definition: socket.h:1299
stdx::expected< void, error_type > bind(const endpoint_type &endpoint)
Definition: socket.h:1355
stdx::expected< socket_type, error_type > accept(io_context &io_ctx, endpoint_type &endpoint, int flags=0)
Definition: socket.h:1394
stdx::expected< void, error_type > close()
Definition: socket.h:1327
auto async_accept(endpoint_type &endpoint, CompletionToken &&token)
Definition: socket.h:1448
executor_type get_executor() noexcept
Definition: socket.h:1306
protocol_type protocol_
Definition: socket.h:1532
stdx::expected< void, std::error_code > wait(socket_base::wait_type wt)
Definition: socket.h:1515
auto async_accept(CompletionToken &&token)
Definition: socket.h:1510
stdx::expected< void, error_type > cancel()
Definition: socket.h:1329
bool enable_connection_aborted() const
Definition: socket.h:1369
stdx::expected< void, std::error_code > native_non_blocking(bool mode)
Definition: socket.h:1351
auto async_accept(io_context &io_ctx, CompletionToken &&token)
Definition: socket.h:1410
stdx::expected< void, error_type > get_option(GettableSocketOption &option) const
Definition: socket.h:1338
auto async_wait(wait_type w, CompletionToken &&token)
Definition: socket.h:1520
stdx::expected< void, std::error_code > non_blocking(bool mode)
Definition: socket.h:1345
constexpr bool is_open() const
Definition: socket.h:1325
stdx::expected< socket_type, error_type > accept(io_context &io_ctx, int flags=0)
Definition: socket.h:1375
stdx::expected< void, error_type > set_option(const SettableSocketOption &option)
Definition: socket.h:1332
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
auto async_wait(wait_type w, CompletionToken &&token)
Definition: socket.h:872
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:886
basic_socket(io_context &ctx, const protocol_type &proto, const native_handle_type &native_handle)
Definition: socket.h:889
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:884
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:1089
stdx::expected< size_t, std::error_code > send(const ConstBufferSequence &buffers)
Definition: socket.h:1166
stdx::expected< size_t, std::error_code > read_some(const MutableBufferSequence &buffers)
Definition: socket.h:1140
stdx::expected< void, error_type > shutdown(socket_base::shutdown_type st) const
Definition: socket.h:1181
stdx::expected< size_t, std::error_code > receive(const MutableBufferSequence &buffers)
Definition: socket.h:1134
basic_stream_socket(const basic_stream_socket &)=delete
auto async_send(const ConstBufferSequence &buffers, CompletionToken &&token)
Definition: socket.h:1283
auto async_receive(const MutableBufferSequence &buffers, CompletionToken &&token)
Definition: socket.h:1237
stdx::expected< size_t, std::error_code > write_some(const ConstBufferSequence &buffers)
Definition: socket.h:1174
basic_stream_socket(io_context &ctx, const protocol_type &protocol, const native_handle_type &native_handle)
Definition: socket.h:1111
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:1116
auto async_send(const ConstBufferSequence &buffers, socket_base::message_flags flags, CompletionToken &&token)
Definition: socket.h:1246
stdx::expected< size_t, std::error_code > send(const ConstBufferSequence &buffers, socket_base::message_flags flags)
Definition: socket.h:1146
basic_stream_socket(io_context &ctx)
Definition: socket.h:1098
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:1187
basic_stream_socket & operator=(const basic_stream_socket &)=delete
basic_stream_socket(io_context &ctx, const protocol_type &proto)
Definition: socket.h:1099
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:32
void * begin(THD *thd, const TABLE *table, size_t data_size, size_t memory, size_t num_threads) noexcept
Definition: bulk_data_service.cc:1533
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:786
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:312
stdx::expected< InputIterator, std::error_code > connect(basic_socket< Protocol > &s, InputIterator first, InputIterator last)
Definition: socket.h:1619
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
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