Draft
Draft
Date: 2018-04-04
Revises: N4734
Reply to: Jonathan Wakely
[email protected]
Note: this is an early draft. It’s known to be incomplet and incorrekt, and it has lots of ba d
formatting.
Dxxxx
Contents
1 Scope 1
2 Normative references 2
4 General Principles 4
4.1 Conformance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
4.2 Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
9 Error reporting 9
9.1 Synchronous operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
9.2 Asynchronous operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
9.3 Error conditions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
9.4 Suppression of signals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
10 Library summary 11
11 Convenience header 13
11.1 Header <experimental/net> synopsis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
12 Forward declarations 14
12.1 Header <experimental/netfwd> synopsis . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
13 Asynchronous model 16
13.1 Header <experimental/executor> synopsis . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
13.2 Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
13.3 Class template async_result . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
13.4 Class template async_completion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
13.5 Class template associated_allocator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
13.6 Function get_associated_allocator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
13.7 Class execution_context . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
13.8 Class execution_context::service . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
13.9 Class template is_executor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
13.10 Executor argument tag . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
13.11 uses_executor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
13.12 Class template associated_executor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
c ISO/IEC 2018 – All rights reserved ii
Dxxxx
15 Timers 67
15.1 Header <experimental/timer> synopsis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
15.2 Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
15.3 Class template wait_traits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
15.4 Class template basic_waitable_timer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
16 Buffers 73
16.1 Header <experimental/buffer> synopsis . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
16.2 Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
16.3 Error codes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
16.4 Class mutable_buffer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
16.5 Class const_buffer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
16.6 Buffer type traits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
16.7 Buffer sequence access . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
16.8 Function buffer_size . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
16.9 Function buffer_copy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
16.10 Buffer arithmetic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
16.11 Buffer creation functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
16.12 Class template dynamic_vector_buffer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
16.13 Class template dynamic_string_buffer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
16.14 Dynamic buffer creation functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
17 Buffer-oriented streams 93
17.1 Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
17.2 Class transfer_all . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
17.3 Class transfer_at_least . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
17.4 Class transfer_exactly . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
17.5 Synchronous read operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
17.6 Asynchronous read operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
17.7 Synchronous write operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
c ISO/IEC 2018 – All rights reserved iii
Dxxxx
18 Sockets 105
18.1 Header <experimental/socket> synopsis . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
18.2 Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
18.3 Error codes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116
18.4 Class socket_base . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
18.5 Socket options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
18.6 Class template basic_socket . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122
18.7 Class template basic_datagram_socket . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132
18.8 Class template basic_stream_socket . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140
18.9 Class template basic_socket_acceptor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146
Index 220
c ISO/IEC 2018 – All rights reserved iv
Dxxxx
1 Scope [scope]
1 This document describes extensions to the C++ Standard Library. This document specifies requirements for
implementations of an interface that computer programs written in the C++ programming language may use
to perform operations related to networking, such as operations involving sockets, timers, buffer management,
host name resolution and internet protocols. This document is applicable to information technology systems
that can perform network operations, such as those with operating systems that conform to the POSIX
interface. This document is applicable only to vendors who wish to provide the interface it describes.
Scope
c ISO/IEC 2018 – All rights reserved 1
Dxxxx
Normative references
c ISO/IEC 2018 – All rights reserved 2
Dxxxx
3 Terms that are used only in a small portion of this document are defined where they are used and italicized
where they are defined.
3.1 [defs.host.byte.order]
host byte order
the arrangement of bytes in any integer type when using a specific machine architecture
[SOURCE: ISO/IEC 9945:2009, 3.193]
3.2 [defs.net.byte.order]
network byte order
the way of representing any integer type such that, when transmitted over a network via a network endpoint,
the int type is transmitted as an appropriate number of octets with the most significant octet first, followed
by any other octets in descending order of significance
[SOURCE: ISO/IEC 9945:2009, 3.237]
3.3 [defs.sync.op]
synchronous operation
operation where control is not returned until the operation completes
3.4 [defs.async.op]
asynchronous operation
operation where control is returned immediately without waiting for the operation to complete
[ Note 1 to entry: Multiple asynchronous operations may be executed concurrently. — end note ]
§ 3.4
c ISO/IEC 2018 – All rights reserved 3
Dxxxx
§ 4.2
c ISO/IEC 2018 – All rights reserved 4
Dxxxx
2 Unless otherwise specified, references to other entities described in this document are assumed to be qualified
with std::experimental::net::v1::, references to entities described in the C++ standard are assumed to
be qualified with std::, and references to entities described in C++ Extensions for Library Fundamentals are
assumed to be qualified with std::experimental::fundamentals_v2::.
§ 8.2.1
c ISO/IEC 2018 – All rights reserved 8
Dxxxx
(1.1) — Uses where system errors are truly exceptional and indicate a serious failure. Throwing an exception is
the most appropriate response.
(1.2) — Uses where system errors are routine and do not necessarily represent failure. Returning an error code
is the most appropriate response. This allows application specific error handling, including simply
ignoring the error.
— end note ]
2 Functions not having an argument of type error_code& report errors as follows, unless otherwise specified:
(2.1) — When a call by the implementation to an operating system or other underlying API results in an error
that prevents the function from meeting its specifications, the function exits via an exception of a type
that would match a handler of type system_error.
(2.2) — Destructors throw nothing.
3 Functions having an argument of type error_code& report errors as follows, unless otherwise specified:
(3.1) — If a call by the implementation to an operating system or other underlying API results in an error
that prevents the function from meeting its specifications, the error_code& argument ec is set as
appropriate for the specific error. Otherwise, the ec argument is set such that !ec is true.
4 Where a function is specified as two overloads, with and without an argument of type error_code&:
R f (A1 a1, A2 a2, ..., AN aN);
R f (A1 a1, A2 a2, ..., AN aN, error_code& ec);
5 then, when R is non-void, the effects of the first overload are as if:
error_code ec;
R r(f (a1, a2, ..., aN, ec));
if (ec) throw system_error(ec, S);
return r;
6 otherwise, when R is void, the effects of the first overload are as if:
error_code ec;
f (a1, a2, ..., aN, ec);
if (ec) throw system_error(ec, S);
7 except that the type thrown may differ as specified above. S is an ntbs indicating where the exception was
thrown. [ Note: A possible value for S is __func__. — end note ]
8 For both overloads, failure to allocate storage is reported by throwing an exception as described in the C++
standard (C++ 2014 [res.on.exception.handling]).
9 In this document, when a type requirement is specified using two function call expressions f, with and without
an argument ec of type error_code:
§ 9.1
c ISO/IEC 2018 – All rights reserved 9
Dxxxx
then the effects of the first call expression of f shall be as described for the first overload above.
§ 9.4
c ISO/IEC 2018 – All rights reserved 10
Dxxxx
Clause Header(s)
Convenience header (11) <experimental/net>
Forward declarations (12) <experimental/netfwd>
Asynchronous model (13) <experimental/executor>
Basic I/O services (14) <experimental/io_context>
Timers (15) <experimental/timer>
Buffers (16) <experimental/buffer>
Buffer-oriented streams (17)
Sockets (18) <experimental/socket>
Socket iostreams (19)
Socket algorithms (20)
Internet protocol (21) <experimental/internet>
1 Throughout this document, the names of the template parameters are used to express type requirements, as
listed in Table 3.
Library summary
c ISO/IEC 2018 – All rights reserved 11
Dxxxx
Library summary
c ISO/IEC 2018 – All rights reserved 12
Dxxxx
1 [ Note: This header is provided as a convenience for programs so that they may access all networking facilities
via a single, self-contained #include. — end note ]
§ 11.1
c ISO/IEC 2018 – All rights reserved 13
Dxxxx
class execution_context;
template<class T, class Executor>
class executor_binder;
template<class Executor>
class executor_work_guard;
class system_executor;
class executor;
template<class Executor>
class strand;
class io_context;
template<class Protocol>
class basic_socket;
template<class Protocol>
class basic_datagram_socket;
template<class Protocol>
class basic_stream_socket;
template<class Protocol>
class basic_socket_acceptor;
template<class Protocol, class Clock = chrono::steady_clock,
class WaitTraits = wait_traits<Clock>>
class basic_socket_streambuf;
template<class Protocol, class Clock = chrono::steady_clock,
class WaitTraits = wait_traits<Clock>>
class basic_socket_iostream;
namespace ip {
class address;
class address_v4;
class address_v6;
template<class Address>
class basic_address_iterator;
using address_v4_iterator = basic_address_iterator<address_v4>;
using address_v6_iterator = basic_address_iterator<address_v6>;
§ 12.1
c ISO/IEC 2018 – All rights reserved 14
Dxxxx
template<class Address>
class basic_address_range;
using address_v4_range = basic_address_range<address_v4>;
using address_v6_range = basic_address_range<address_v6>;
class network_v4;
class network_v6;
template<class InternetProtocol>
class basic_endpoint;
template<class InternetProtocol>
class basic_resolver_entry;
template<class InternetProtocol>
class basic_resolver_results;
template<class InternetProtocol>
class basic_resolver;
class tcp;
class udp;
} // namespace ip
} // inline namespace v1
} // namespace net
} // namespace experimental
} // namespace std
1 Default template arguments are described as appearing both in <netfwd> and in the synopsis of other headers
but it is well-formed to include both <netfwd> and one or more of the other headers. [ Note: It is the
implementation’s responsibility to implement headers so that including <netfwd> and other headers does not
violate the rules about multiple occurrences of default arguments. — end note ]
§ 12.1
c ISO/IEC 2018 – All rights reserved 15
Dxxxx
// 13.6, get_associated_allocator:
template<class T>
associated_allocator_t<T> get_associated_allocator(const T& t) noexcept;
template<class T, class ProtoAllocator>
associated_allocator_t<T, ProtoAllocator>
get_associated_allocator(const T& t, const ProtoAllocator& a) noexcept;
class execution_context;
class service_already_exists;
template<class T>
constexpr bool is_executor_v = is_executor<T>::value;
struct executor_arg_t { };
constexpr executor_arg_t executor_arg = executor_arg_t();
§ 13.1
c ISO/IEC 2018 – All rights reserved 16
Dxxxx
// 13.13, get_associated_executor:
template<class T>
associated_executor_t<T> get_associated_executor(const T& t) noexcept;
template<class T, class Executor>
associated_executor_t<T, Executor>
get_associated_executor(const T& t, const Executor& ex) noexcept;
template<class T, class ExecutionContext>
associated_executor_t<T, typename ExecutionContext::executor_type>
get_associated_executor(const T& t, ExecutionContext& ctx) noexcept;
// 13.15, bind_executor:
template<class Executor>
class executor_work_guard;
// 13.17, make_work_guard:
template<class Executor>
executor_work_guard<Executor>
make_work_guard(const Executor& ex);
template<class ExecutionContext>
executor_work_guard<typename ExecutionContext::executor_type>
make_work_guard(ExecutionContext& ctx);
template<class T>
§ 13.1
c ISO/IEC 2018 – All rights reserved 17
Dxxxx
executor_work_guard<associated_executor_t<T>>
make_work_guard(const T& t);
template<class T, class U>
auto make_work_guard(const T& t, U&& u)
-> decltype(make_work_guard(get_associated_executor(t, forward<U>(u))));
class system_executor;
class system_context;
class bad_executor;
class executor;
// 13.22, dispatch:
template<class CompletionToken>
DEDUCED dispatch(CompletionToken&& token);
template<class Executor, class CompletionToken>
DEDUCED dispatch(const Executor& ex, CompletionToken&& token);
template<class ExecutionContext, class CompletionToken>
DEDUCED dispatch(ExecutionContext& ctx, CompletionToken&& token);
// 13.23, post:
template<class CompletionToken>
DEDUCED post(CompletionToken&& token);
template<class Executor, class CompletionToken>
DEDUCED post(const Executor& ex, CompletionToken&& token);
template<class ExecutionContext, class CompletionToken>
DEDUCED post(ExecutionContext& ctx, CompletionToken&& token);
// 13.24, defer:
template<class CompletionToken>
DEDUCED defer(CompletionToken&& token);
template<class Executor, class CompletionToken>
DEDUCED defer(const Executor& ex, CompletionToken&& token);
template<class ExecutionContext, class CompletionToken>
DEDUCED defer(ExecutionContext& ctx, CompletionToken&& token);
template<class Executor>
class strand;
template<class Executor>
bool operator==(const strand<Executor>& a, const strand<Executor>& b);
§ 13.1
c ISO/IEC 2018 – All rights reserved 18
Dxxxx
template<class Executor>
bool operator!=(const strand<Executor>& a, const strand<Executor>& b);
} // inline namespace v1
} // namespace net
} // namespace experimental
template<class Allocator>
struct uses_allocator<experimental::net::v1::executor, Allocator>
: true_type {};
} // namespace std
§ 13.2.2
c ISO/IEC 2018 – All rights reserved 19
Dxxxx
function object of MoveConstructible (C++ 2014 [moveconstructible]) type Func such that f() is a valid
expression, a denotes a (possibly const) value of type A where A is a type meeting the ProtoAllocator
requirements (13.2.1), and u denotes an identifier.
§ 13.2.2
c ISO/IEC 2018 – All rights reserved 20
Dxxxx
§ 13.2.2
c ISO/IEC 2018 – All rights reserved 21
Dxxxx
§ 13.2.4
c ISO/IEC 2018 – All rights reserved 22
Dxxxx
— end example ]
5 A service’s shutdown member function shall destroy all copies of function objects that are held by the service.
4 The associator’s primary template shall be defined. A program may partially specialize the associator class
template for some user-defined type S.
5 Finally, the associator shall provide the following type alias and function template in the enclosing namespace:
template<class S, class C = D> using X _t = typename X <S, C>::type;
where X is replaced with the name of the associator class template. [ Note: This function template is provided
as a convenience, to automatically deduce the source and candidate types. — end note ]
§ 13.2.7.2
c ISO/IEC 2018 – All rights reserved 24
Dxxxx
return result.get();
}
3 For convenience, initiating functions may be implemented using the async_completion template:
template<class CompletionToken>
auto async_xyz(T1 t1, T2 t2, CompletionToken&& token)
{
async_completion<CompletionToken, void(R1, R2)> init(token);
return init.result.get();
}
— end example ]
§ 13.2.7.5
c ISO/IEC 2018 – All rights reserved 25
Dxxxx
(1.2) — Otherwise, the implementation does not assume the validity of the argument after the initiating function
completes. [ Note: In other words, the program is not required to guarantee the validity of the argument
after the initiating function completes. — end note ] The implementation may make copies of the
argument, and all copies shall be destroyed no later than immediately after invocation of the completion
handler.
§ 13.2.7.11
c ISO/IEC 2018 – All rights reserved 26
Dxxxx
2 Let Alloc1 be a type, satisfying the ProtoAllocator (13.2.1) requirements, that represents the asynchronous
operation’s default allocation strategy. [ Note: Typically allocator<void>. — end note ] Let alloc1 be a
value of type Alloc1.
3 A completion handler object of type CompletionHandler has an associated allocator object alloc2 of type
Alloc2 satisfying the ProtoAllocator (13.2.1) requirements. The type Alloc2 is associated_allocator_-
t<CompletionHandler, Alloc1>. Let alloc2 be a value of type Alloc2 obtained by performing get_-
associated_allocator(completion_handler, alloc1).
4 The asynchronous operations defined in this document:
(4.1) — If required, allocate memory using only the completion handler’s associated allocator.
(4.2) — Prior to completion handler execution, deallocate any memory allocated using the completion handler’s
associated allocator.
5 [ Note: The implementation can perform operating system or underlying API calls that perform memory
allocations not using the associated allocator. Invocations of the allocator functions do not introduce data
races (see C++ 2014 [res.on.data.races]). — end note ]
§ 13.2.7.14
c ISO/IEC 2018 – All rights reserved 27
Dxxxx
explicit async_result(completion_handler_type&) {}
async_result(const async_result&) = delete;
async_result& operator=(const async_result&) = delete;
return_type get() {}
};
} // inline namespace v1
} // namespace net
} // namespace experimental
} // namespace std
2 The template parameter CompletionToken shall be an object type. The template parameter Signature
shall be a call signature (C++ 2014 [func.def]).
3 Specializations of async_result shall satisfy the Destructible requirements (C++ 2014 [destructible]) in
addition to the requirements in Table 7. In this table, R is a specialization of async_result; r is a modifiable
lvalue of type R; and h is a modifiable lvalue of type R::completion_handler_type.
§ 13.3
c ISO/IEC 2018 – All rights reserved 28
Dxxxx
} // inline namespace v1
} // namespace net
} // namespace experimental
} // namespace std
2 The template parameter Signature shall be a call signature (C++ 2014 [func.def]).
explicit async_completion(CompletionToken& t);
3 Effects: If CompletionToken and completion_handler_type are the same type, binds completion_-
handler to t; otherwise, initializes completion_handler with std::forward<CompletionToken>(t).
Initializes result with completion_handler.
§ 13.5
c ISO/IEC 2018 – All rights reserved 29
Dxxxx
namespace net {
inline namespace v1 {
} // inline namespace v1
} // namespace net
} // namespace experimental
} // namespace std
§ 13.6
c ISO/IEC 2018 – All rights reserved 30
Dxxxx
class execution_context
{
public:
class service;
execution_context();
execution_context(const execution_context&) = delete;
execution_context& operator=(const execution_context&) = delete;
virtual ~execution_context();
protected:
// service access:
template<class Service> typename Service::key_type&
use_service(execution_context& ctx);
template<class Service, class... Args> Service&
make_service(execution_context& ctx, Args&&... args);
template<class Service> bool has_service(const execution_context& ctx) noexcept;
class service_already_exists : public logic_error { };
} // inline namespace v1
} // namespace net
} // namespace experimental
} // namespace std
2 Access to the services of an execution_context is via three function templates, use_service, make_service
and has_service.
3 In a call to use_service<Service>, the type argument chooses a service, identified by Service::key_type,
from a set of services in an execution_context. If the service is not present in the execution_context,
an object of type Service is created and added to the execution_context. A program can check if an
execution_context implements a particular service with the function template has_service<Service>.
4 Service objects may be explicitly added to an execution_context using the function template make_-
service<Service>. If the service is already present, make_service exits via an exception of type service_-
§ 13.7
c ISO/IEC 2018 – All rights reserved 31
Dxxxx
already_exists.
5 Once a service reference is obtained from an execution_context object by calling use_service, that
reference remains usable until a call to destroy().
6 If a call to a specialization of use_service or make_service recursively calls another specialization of
use_service or make_service which would choose the same service (identified by key_type) from the same
execution_context, then the behavior is undefined. [ Note: Nested calls to specializations for different
service types are well-defined. — end note ]
§ 13.7.5
c ISO/IEC 2018 – All rights reserved 32
Dxxxx
class execution_context::service
{
protected:
// construct / copy / destroy:
// service observers:
private:
// service operations:
} // inline namespace v1
} // namespace net
} // namespace experimental
} // namespace std
§ 13.8
c ISO/IEC 2018 – All rights reserved 33
Dxxxx
} // inline namespace v1
} // namespace net
} // namespace experimental
} // namespace std
struct executor_arg_t { };
constexpr executor_arg_t executor_arg = executor_arg_t();
} // inline namespace v1
} // namespace net
} // namespace experimental
} // namespace std
1 The executor_arg_t struct is an empty structure type used as a unique type to disambiguate constructor and
function overloading. Specifically, types may have constructors with executor_arg_t as the first argument,
immediately followed by an argument of a type that satisfies the Executor requirements (13.2.2).
13.11 uses_executor [async.uses.executor]
13.11.1 uses_executor trait [async.uses.executor.trait]
namespace std {
namespace experimental {
namespace net {
inline namespace v1 {
} // inline namespace v1
} // namespace net
} // namespace experimental
} // namespace std
1 Remark: Detects whether T has a nested executor_type that is convertible from Executor. Meets the
BinaryTypeTrait requirements (C++ 2014 [meta.rqmts]). The implementation provides a definition that
§ 13.11.1
c ISO/IEC 2018 – All rights reserved 34
Dxxxx
is derived from true_type if the qualified-id T::executor_type is valid and denotes a type and is_-
convertible<Executor, T::executor_type>::value != false, otherwise it is derived from false_type.
A program may specialize this template to derive from true_type for a user-defined type T that does not
have a nested executor_type but nonetheless can be constructed with an executor if the first argument of a
constructor has type executor_arg_t and the second argument has type Executor.
13.11.2 uses-executor construction [async.uses.executor.cons]
1 Uses-executor construction with executor Executor refers to the construction of an object obj of type T,
using constructor arguments v1, v2, ..., vN of types V1, V2, ..., VN, respectively, and an executor ex
of type Executor, according to the following rules:
(1.1) — if uses_executor_v<T, Executor> is true and is_constructible<T, executor_arg_t, Executor,
V1, V2, ..., VN>::value is true, then obj is initialized as obj(executor_arg, ex, v1, v2, ...,
vN);
(1.2) — otherwise, obj is initialized as obj(v1, v2, ..., vN).
} // inline namespace v1
} // namespace net
} // namespace experimental
} // namespace std
§ 13.12
c ISO/IEC 2018 – All rights reserved 35
Dxxxx
using target_type = T;
using executor_type = Executor;
§ 13.14
c ISO/IEC 2018 – All rights reserved 36
Dxxxx
~executor_binder();
// 13.14.2, executor binder access:
template<class... Args>
result_of_t<T&(Args&&...)> operator()(Args&&... args);
template<class... Args>
result_of_t<const T&(Args&&...)> operator()(Args&&... args) const;
private:
Executor ex_; // exposition only
T target_; // exposition only
};
} // inline namespace v1
} // namespace net
} // namespace experimental
} // namespace std
§ 13.14.1
c ISO/IEC 2018 – All rights reserved 37
Dxxxx
§ 13.14.4
c ISO/IEC 2018 – All rights reserved 38
Dxxxx
return_type get();
private:
async_result<T, Signature> target_; // exposition only
};
} // inline namespace v1
} // namespace net
} // namespace experimental
} // namespace std
return_type get();
2 Returns: target_.get().
} // inline namespace v1
} // namespace net
} // namespace experimental
} // namespace std
§ 13.14.5
c ISO/IEC 2018 – All rights reserved 39
Dxxxx
} // inline namespace v1
} // namespace net
} // namespace experimental
} // namespace std
template<class Executor>
class executor_work_guard
{
§ 13.16
c ISO/IEC 2018 – All rights reserved 40
Dxxxx
public:
// types:
~executor_work_guard();
// executor work guard observers:
private:
Executor ex_; // exposition only
bool owns_; // exposition only
};
} // inline namespace v1
} // namespace net
} // namespace experimental
} // namespace std
~executor_work_guard();
6 Effects: If owns_ is true, performs ex_.on_work_finished().
§ 13.16.1
c ISO/IEC 2018 – All rights reserved 41
Dxxxx
7 Returns: ex_.
template<class ExecutionContext>
executor_work_guard<typename ExecutionContext::executor_type>
make_work_guard(ExecutionContext& ctx);
3 Returns: make_work_guard(ctx.get_executor()).
4 Remarks: This function shall not participate in overload resolution unless is_convertible<Execution-
Context&, execution_context&>::value is true.
template<class T>
executor_work_guard<associated_executor_t<T>>
make_work_guard(const T& t);
5 Returns: make_work_guard(get_associated_executor(t)).
6 Remarks: This function shall not participate in overload resolution unless is_executor_v<T> is false
and is_convertible<T&, execution_context&>::value is false.
class system_executor
{
public:
// constructors:
§ 13.18
c ISO/IEC 2018 – All rights reserved 42
Dxxxx
system_executor() {}
} // inline namespace v1
} // namespace net
} // namespace experimental
} // namespace std
2 Class system_executor satisfies the Destructible (C++ 2014 [destructible]), DefaultConstructible (C++
2014 [defaultconstructible]), and Executor (13.2.2) type requirements.
3 To satisfy the Executor requirements for the post and defer member functions, the system executor may
create thread objects to run the submitted function objects. These thread objects are collectively referred
to as system threads.
§ 13.18.2
c ISO/IEC 2018 – All rights reserved 43
Dxxxx
system_context() = delete;
system_context(const system_context&) = delete;
system_context& operator=(const system_context&) = delete;
~system_context();
// system_context operations:
void stop();
bool stopped() const noexcept;
void join();
};
} // inline namespace v1
} // namespace net
} // namespace experimental
} // namespace std
~system_context();
4 Effects: Performs stop() followed by join().
§ 13.19
c ISO/IEC 2018 – All rights reserved 44
Dxxxx
void stop();
6 Effects: Signals all system threads to exit as soon as possible. If a system thread is currently executing
a function object, the thread will exit only after completion of that function object. Returns without
waiting for the system threads to complete.
7 Postconditions: stopped() == true.
void join();
9 Effects: Blocks the calling thread (C++ 2014 [defns.block]) until all system threads have completed.
10 Synchronization: The completion of each system thread synchronizes with (C++ 2014 [intro.multithread])
the corresponding successful join() return.
} // inline namespace v1
} // namespace net
} // namespace experimental
} // namespace std
bad_executor() noexcept;
2 Effects: constructs a bad_executor object.
3 Postconditions: what() returns an implementation-defined ntbs.
class executor
{
public:
// 13.21.1, construct / copy / destroy:
§ 13.21
c ISO/IEC 2018 – All rights reserved 45
Dxxxx
executor() noexcept;
executor(nullptr_t) noexcept;
executor(const executor& e) noexcept;
executor(executor&& e) noexcept;
template<class Executor> executor(Executor e);
template<class Executor, class ProtoAllocator>
executor(allocator_arg_t, const ProtoAllocator& a, Executor e);
~executor();
// 13.21.4, executor modifiers:
§ 13.21
c ISO/IEC 2018 – All rights reserved 46
Dxxxx
} // inline namespace v1
} // namespace net
} // namespace experimental
template<class Allocator>
struct uses_allocator<experimental::net::v1::executor, Allocator>
: true_type {};
} // namespace std
2 Class executor meets the requirements of Executor (13.2.2), DefaultConstructible (C++ 2014 [default-
constructible]), and CopyAssignable (C++ 2014 [copyassignable]).
3 [ Note: To meet the noexcept requirements for executor copy constructors and move constructors, implemen-
tations can share a target between two or more executor objects. — end note ]
4 The target is the executor object that is held by the wrapper.
executor(nullptr_t) noexcept;
2 Postconditions: !*this.
executor(executor&& e) noexcept;
4 Effects: If !e, *this has no target; otherwise, moves e.target() or move-constructs the target of e
into the target of *this, leaving e in a valid state with an unspecified value.
§ 13.21.2
c ISO/IEC 2018 – All rights reserved 47
Dxxxx
§ 13.21.5
c ISO/IEC 2018 – All rights reserved 48
Dxxxx
§ 13.21.8
c ISO/IEC 2018 – All rights reserved 49
Dxxxx
§ 13.22
c ISO/IEC 2018 – All rights reserved 50
Dxxxx
§ 13.23
c ISO/IEC 2018 – All rights reserved 51
Dxxxx
§ 13.24
c ISO/IEC 2018 – All rights reserved 52
Dxxxx
template<class Executor>
class strand
{
public:
// types:
strand();
explicit strand(Executor ex);
template<class ProtoAllocator>
strand(allocator_arg_t, const ProtoAllocator& alloc, Executor ex);
strand(const strand& other) noexcept;
strand(strand&& other) noexcept;
template<class OtherExecutor> strand(const strand<OtherExecutor>& other) noexcept;
template<class OtherExecutor> strand(strand<OtherExecutor>&& other) noexcept;
~strand();
// 13.25.4, strand operations:
private:
Executor inner_ex_; // exposition only
§ 13.25
c ISO/IEC 2018 – All rights reserved 53
Dxxxx
};
} // inline namespace v1
} // namespace net
} // namespace experimental
} // namespace std
template<class ProtoAllocator>
strand(allocator_arg_t, const ProtoAllocator& a, Executor ex);
4 Effects: Constructs an object of class strand<Executor> that represents a unique ordered, non-
concurrent state. Initializes inner_ex_ as inner_ex_(ex). A copy of the allocator argument a is used
to allocate memory, if necessary, for the internal data structures of the constructed strand object.
§ 13.25.1
c ISO/IEC 2018 – All rights reserved 54
Dxxxx
§ 13.25.2
c ISO/IEC 2018 – All rights reserved 55
Dxxxx
§ 13.25.4
c ISO/IEC 2018 – All rights reserved 56
Dxxxx
// use_future_t members:
constexpr use_future_t() noexcept(noexcept(allocator_type()));
explicit use_future_t(const allocator_type& a) noexcept;
template<class OtherProtoAllocator> use_future_t<OtherProtoAllocator>
rebind(const OtherProtoAllocator& a) const noexcept;
allocator_type get_allocator() const noexcept;
template <class F> unspecified operator()(F&& f) const;
};
} // inline namespace v1
} // namespace net
} // namespace experimental
} // namespace std
§ 13.26.2
c ISO/IEC 2018 – All rights reserved 57
Dxxxx
return_type get();
};
§ 13.26.3
c ISO/IEC 2018 – All rights reserved 58
Dxxxx
3 The implementation specializes associated_executor for F. For function objects executed using the associ-
ated executor’s dispatch(), post() or defer() functions, any exception thrown is caught by the executor
and stored in the associated shared state.
4 For any executor type E, the associated object for the associator associated_executor<F, E> is an executor
where, for function objects executed using the executor’s dispatch(), post() or defer() functions, any
exception thrown by a function object is caught by the executor and stored in the associated shared state.
5 When an object r1 of type R is constructed from t1, the expression r1.get() returns a future with the same
shared state as t1.
6 The type of R::return_type and the effects of F::operator() are defined in Table 10. After establishing
these effects, F::operator() makes the shared state ready. In this table, N is the value of sizeof...(Args);
let i be in the range [0, N ) and let Ti be the ith type in Args; let Ui be decay_t<Ti > for each type Ti in
Args; let Ai be the deduced type of the ith argument to F::operator(); and let ai be the ith argument to
F::operator().
Table 10 — async_result<use_future_t<ProtoAllocator>,
Result(Args...)> semantics
§ 13.26.3
c ISO/IEC 2018 – All rights reserved 59
Dxxxx
Table 10 — async_result<use_future_t<ProtoAllocator>,
Result(Args...)> semantics (continued)
return_type get();
private:
return_type future_; // exposition only
};
} // inline namespace v1
} // namespace net
} // namespace experimental
} // namespace std
return_type get();
2 Returns: std::move(future_).
§ 13.27
c ISO/IEC 2018 – All rights reserved 60
Dxxxx
class io_context;
} // inline namespace v1
} // namespace net
} // namespace experimental
} // namespace std
class executor_type;
using count_type = implementation-defined ;
io_context();
explicit io_context(int concurrency_hint);
io_context(const io_context&) = delete;
io_context& operator=(const io_context&) = delete;
// io_context operations:
count_type run();
template<class Rep, class Period>
count_type run_for(const chrono::duration<Rep, Period>& rel_time);
template<class Clock, class Duration>
count_type run_until(const chrono::time_point<Clock, Duration>& abs_time);
count_type run_one();
template<class Rep, class Period>
count_type run_one_for(const chrono::duration<Rep, Period>& rel_time);
template<class Clock, class Duration>
§ 14.2
c ISO/IEC 2018 – All rights reserved 61
Dxxxx
count_type poll();
count_type poll_one();
void stop();
void restart();
};
} // inline namespace v1
} // namespace net
} // namespace experimental
} // namespace std
§ 14.2.1
c ISO/IEC 2018 – All rights reserved 62
Dxxxx
count_type run();
4 Effects: Equivalent to:
count_type n = 0;
while (run_one())
if (n != numeric_limits<count_type>::max())
++n;
5 Returns: n.
6 [ Note: Calling run from a thread that is currently calling a run function can introduce the potential
for deadlock. It is the caller’s responsibility to avoid such deadlocks. — end note ]
9 Returns: n.
count_type run_one();
10 Effects: If the io_context object has no outstanding work, performs stop(). Otherwise, blocks while
the io_context has outstanding work, or until the io_context is stopped, or until one function object
has been executed.
11 If an executed function object throws an exception, the exception propagates to the caller of run_one().
The io_context state is as if the function object had returned normally.
12 Returns: 1 if a function object was executed, otherwise 0.
13 Remarks: This function may invoke additional function objects through nested calls to the io_context
executor’s dispatch member function. These do not count towards the return value.
14 [ Note: Calling run_one from a thread that is currently calling a run function can introduce the potential
for deadlock. It is the caller’s responsibility to avoid such deadlocks. — end note ]
§ 14.2.1
c ISO/IEC 2018 – All rights reserved 63
Dxxxx
16 Effects: If the io_context object has no outstanding work, performs stop(). Otherwise, blocks
while the io_context has outstanding work, or until the expiration of the absolute timeout (C++ 2014
[thread.req.timing]) specified by abs_time, or until the io_context is stopped, or until one function
object has been executed.
17 If an executed function object throws an exception, the exception propagates to the caller of run_one().
The io_context state is as if the function object had returned normally.
18 Returns: 1 if a function object was executed, otherwise 0.
19 Remarks: This function may invoke additional function objects through nested calls to the io_context
executor’s dispatch member function. These do not count towards the return value.
count_type poll();
20 Effects: Equivalent to:
count_type n = 0;
while (poll_one())
if (n != numeric_limits<count_type>::max())
++n;
21 Returns: n.
count_type poll_one();
22 Effects: If the io_context object has no outstanding work, performs stop(). Otherwise, if there is a
function object ready for immediate execution, executes it.
23 If an executed function object throws an exception, the exception propagates to the caller of poll_one().
The io_context state is as if the function object had returned normally.
24 Returns: 1 if a function object was invoked, otherwise 0.
25 Remarks: This function may invoke additional function objects through nested calls to the io_context
executor’s dispatch member function. These do not count towards the return value.
void stop();
26 Effects: Stops the io_context. Concurrent calls to any run function will end as soon as possible. If a
call to a run function is currently executing a function object, the call will end only after completion of
that function object. The call to stop() returns without waiting for concurrent calls to run functions
to complete.
27 Postconditions: stopped() == true.
28 [ Note: When stopped() == true, subsequent calls to a run function will exit immediately with a
return value of 0, without executing any function objects. An io_context remains in the stopped state
until a call to restart(). — end note ]
void restart();
30 Postconditions: stopped() == false.
§ 14.2.1
c ISO/IEC 2018 – All rights reserved 64
Dxxxx
class io_context::executor_type
{
public:
// 14.3.1, construct / copy / destroy:
} // inline namespace v1
} // namespace net
} // namespace experimental
} // namespace std
§ 14.3.1
c ISO/IEC 2018 – All rights reserved 65
Dxxxx
§ 14.3.4
c ISO/IEC 2018 – All rights reserved 66
Dxxxx
15 Timers [timer]
1 This clause defines components for performing timer operations.
2 [ Example: Performing a synchronous wait operation on a timer:
io_context c;
steady_timer t(c);
t.expires_after(seconds(5));
t.wait();
— end example ]
3 [ Example: Performing an asynchronous wait operation on a timer:
void handler(error_code ec) { ... }
...
io_context c;
steady_timer t(c);
t.expires_after(seconds(5));
t.async_wait(handler);
c.run();
— end example ]
namespace std {
namespace experimental {
namespace net {
inline namespace v1 {
} // inline namespace v1
} // namespace net
} // namespace experimental
} // namespace std
§ 15.2.1
c ISO/IEC 2018 – All rights reserved 67
Dxxxx
— end note ]
2 For a type Clock meeting the Clock requirements (C++ 2014 [time.clock.req]), a type X meets the WaitTraits
requirements if it satisfies the requirements listed below.
3 In Table 11, t denotes a (possibly const) value of type Clock::time_point; and d denotes a (possibly const)
value of type Clock::duration.
template<class Clock>
struct wait_traits
{
static typename Clock::duration to_wait_duration(
const typename Clock::duration& d);
} // inline namespace v1
} // namespace net
} // namespace experimental
} // namespace std
1 Class template wait_traits satisfies the WaitTraits (15.2.1) type requirements. Template argument Clock
is a type meeting the Clock requirements (C++ 2014 [time.clock.req]).
§ 15.3
c ISO/IEC 2018 – All rights reserved 68
Dxxxx
~basic_waitable_timer();
basic_waitable_timer& operator=(const basic_waitable_timer&) = delete;
basic_waitable_timer& operator=(basic_waitable_timer&& rhs);
size_t cancel();
size_t cancel_one();
void wait();
void wait(error_code& ec);
§ 15.4
c ISO/IEC 2018 – All rights reserved 69
Dxxxx
template<class CompletionToken>
DEDUCED async_wait(CompletionToken&& token);
};
} // inline namespace v1
} // namespace net
} // namespace experimental
} // namespace std
1 Instances of class template basic_waitable_timer meet the requirements of Destructible (C++ 2014
[destructible]), MoveConstructible (C++ 2014 [moveconstructible]), and MoveAssignable (C++ 2014 [move-
assignable]).
15.4.1 basic_waitable_timer constructors [timer.waitable.cons]
explicit basic_waitable_timer(io_context& ctx);
1 Effects: Equivalent to basic_waitable_timer(ctx, time_point()).
basic_waitable_timer(basic_waitable_timer&& rhs);
5 Effects: Move constructs an object of class basic_waitable_timer<Clock, WaitTraits> that refers
to the state originally represented by rhs.
6 Postconditions:
(6.1) — get_executor() == rhs.get_executor().
(6.2) — expiry() returns the same value as rhs.expiry() prior to the constructor invocation.
(6.3) — rhs.expiry() == time_point().
§ 15.4.3
c ISO/IEC 2018 – All rights reserved 70
Dxxxx
size_t cancel();
2 Effects: Causes any outstanding asynchronous wait operations to complete. Completion handlers for
canceled operations are passed an error code ec such that ec == errc::operation_canceled yields
true.
3 Returns: The number of operations that were canceled.
4 Remarks: Does not block (C++ 2014 [defns.block]) the calling thread pending completion of the canceled
operations.
size_t cancel_one();
5 Effects: Causes the outstanding asynchronous wait operation that was initiated first, if any, to complete
as soon as possible. The completion handler for the canceled operation is passed an error code ec such
that ec == errc::operation_canceled yields true.
6 Returns: 1 if an operation was canceled, otherwise 0.
7 Remarks: Does not block (C++ 2014 [defns.block]) the calling thread pending completion of the canceled
operation.
void wait();
void wait(error_code& ec);
13 Effects: Establishes the postcondition as if by repeatedly blocking the calling thread (C++ 2014
[defns.block]) for the relative time produced by WaitTraits::to_wait_duration(expiry()).
14 Postconditions: ec || expiry() <= clock_type::now().
template<class CompletionToken>
DEDUCED async_wait(CompletionToken&& token);
§ 15.4.4
c ISO/IEC 2018 – All rights reserved 71
Dxxxx
§ 15.4.4
c ISO/IEC 2018 – All rights reserved 72
Dxxxx
16 Buffers [buffer]
16.1 Header <experimental/buffer> synopsis [buffer.synop]
namespace std {
namespace experimental {
namespace net {
inline namespace v1 {
class mutable_buffer;
class const_buffer;
template<class T>
constexpr bool is_mutable_buffer_sequence_v = is_mutable_buffer_sequence<T>::value;
template<class T>
constexpr bool is_const_buffer_sequence_v = is_const_buffer_sequence<T>::value;
template<class T>
constexpr bool is_dynamic_buffer_v = is_dynamic_buffer<T>::value;
template<class ConstBufferSequence>
size_t buffer_size(const ConstBufferSequence& buffers) noexcept;
§ 16.1
c ISO/IEC 2018 – All rights reserved 73
Dxxxx
§ 16.1
c ISO/IEC 2018 – All rights reserved 74
Dxxxx
class transfer_all;
class transfer_at_least;
class transfer_exactly;
§ 16.1
c ISO/IEC 2018 – All rights reserved 75
Dxxxx
§ 16.1
c ISO/IEC 2018 – All rights reserved 76
Dxxxx
§ 16.1
c ISO/IEC 2018 – All rights reserved 77
Dxxxx
} // inline namespace v1
} // namespace net
} // namespace experimental
} // namespace std
§ 16.2.1
c ISO/IEC 2018 – All rights reserved 78
Dxxxx
— there is no
requirement that
operator-> is
provided, and
— there is no
requirement that
reference be a
reference type.
X u(x); post:
equal(
net::buffer_sequence_begin(x),
net::buffer_sequence_end(x),
net::buffer_sequence_begin(u),
net::buffer_sequence_end(u),
[](const mutable_buffer& b1,
const mutable_buffer& b2)
{
return b1.data() == b2.data()
&& b1.size() == b2.size();
})
§ 16.2.2
c ISO/IEC 2018 – All rights reserved 79
Dxxxx
— there is no
requirement that
operator-> is
provided, and
— there is no
requirement that
reference be a
reference type.
X u(x); post:
equal(
net::buffer_sequence_begin(x),
net::buffer_sequence_end(x),
net::buffer_sequence_begin(u),
net::buffer_sequence_end(u),
[](const const_buffer& b1,
const const_buffer& b2)
{
return b1.data() == b2.data()
&& b1.size() == b2.size();
})
§ 16.2.4
c ISO/IEC 2018 – All rights reserved 80
Dxxxx
internal to the dynamic buffer, but direct access to the elements is provided to permit them to be efficiently
used with I/O operations. [ Note: Such as the send or receive operations of a socket. The readable bytes
would be used as the constant buffer sequence for send, and the writable bytes used as the mutable buffer
sequence for receive. — end note ] Data written to the writable bytes of a dynamic buffer object is
appended to the readable bytes of the same object.
2 A type X meets the DynamicBuffer requirements if it satisfies the requirements of Destructible (C++ 2014
[destructible]) and MoveConstructible (C++ 2014 [moveconstructible]), as well as the additional requirements
listed in Table 14.
3 In Table 14, x denotes a value of type X, x1 denotes a (possibly const) value of type X, and n denotes a
(possibly const) value of type size_t.
§ 16.2.4
c ISO/IEC 2018 – All rights reserved 81
Dxxxx
class mutable_buffer
§ 16.4
c ISO/IEC 2018 – All rights reserved 82
Dxxxx
{
public:
// constructors:
mutable_buffer() noexcept;
mutable_buffer(void* p, size_t n) noexcept;
// members:
void* data() const noexcept;
size_t size() const noexcept;
mutable_buffer& operator+=(size_t n) noexcept;
private:
void* data_; // exposition only
size_t size_; // exposition only
};
} // inline namespace v1
} // namespace net
} // namespace experimental
} // namespace std
class const_buffer
{
public:
// constructors:
const_buffer() noexcept;
§ 16.5
c ISO/IEC 2018 – All rights reserved 83
Dxxxx
// members:
const void* data() const noexcept;
size_t size() const noexcept;
const_buffer& operator+=(size_t n) noexcept;
private:
const void* data_; // exposition only
size_t size_; // exposition only
};
} // inline namespace v1
} // namespace net
} // namespace experimental
} // namespace std
§ 16.6
c ISO/IEC 2018 – All rights reserved 84
Dxxxx
} // inline namespace v1
} // namespace net
} // namespace experimental
} // namespace std
1 This subclause contains templates that may be used to query the properties of a type at compile time. Each
of these templates is a UnaryTypeTrait (C++ 2014 [meta.rqmts]) with a BaseCharacteristic of true_type if
the corresponding condition is true, otherwise false_type.
§ 16.8
c ISO/IEC 2018 – All rights reserved 85
Dxxxx
size_t total_size = 0;
auto i = std::experimental::net::buffer_sequence_begin(buffers);
auto end = std::experimental::net::buffer_sequence_end(buffers);
for (; i != end; ++i)
{
const_buffer b(*i);
total_size += b.size();
}
return total_size;
§ 16.10
c ISO/IEC 2018 – All rights reserved 86
Dxxxx
§ 16.11
c ISO/IEC 2018 – All rights reserved 87
Dxxxx
buffer(
begin(data) != end(data) ? std::addressof(*begin(data)) : nullptr,
(end(data) - begin(data)) * sizeof(*begin(data)));
// constructors:
explicit dynamic_vector_buffer(vector<T, Allocator>& vec) noexcept;
dynamic_vector_buffer(vector<T, Allocator>& vec,
size_t maximum_size) noexcept;
dynamic_vector_buffer(dynamic_vector_buffer&&) = default;
// members:
size_t size() const noexcept;
§ 16.12
c ISO/IEC 2018 – All rights reserved 88
Dxxxx
private:
vector<T, Allocator>& vec_; // exposition only
size_t size_; // exposition only
const size_t max_size_; // exposition only
};
} // inline namespace v1
} // namespace net
} // namespace experimental
} // namespace std
§ 16.12
c ISO/IEC 2018 – All rights reserved 89
Dxxxx
// constructors:
explicit dynamic_string_buffer(basic_string<CharT, Traits, Allocator>& str) noexcept;
dynamic_string_buffer(basic_string<CharT, Traits, Allocator>& str,
size_t maximum_size) noexcept;
dynamic_string_buffer(dynamic_string_buffer&&) = default;
// members:
size_t size() const noexcept;
size_t max_size() const noexcept;
size_t capacity() const noexcept;
const_buffers_type data() const noexcept;
mutable_buffers_type prepare(size_t n);
void commit(size_t n) noexcept;
void consume(size_t n);
private:
basic_string<CharT, Traits, Allocator>& str_; // exposition only
size_t size_; // exposition only
const size_t max_size_; // exposition only
};
} // inline namespace v1
} // namespace net
} // namespace experimental
} // namespace std
§ 16.13
c ISO/IEC 2018 – All rights reserved 90
Dxxxx
§ 16.14
c ISO/IEC 2018 – All rights reserved 91
Dxxxx
§ 16.14
c ISO/IEC 2018 – All rights reserved 92
Dxxxx
§ 17.1.2
c ISO/IEC 2018 – All rights reserved 93
Dxxxx
§ 17.1.4
c ISO/IEC 2018 – All rights reserved 94
Dxxxx
§ 17.2
c ISO/IEC 2018 – All rights reserved 95
Dxxxx
namespace experimental {
namespace net {
inline namespace v1 {
class transfer_all
{
public:
size_t operator()(const error_code& ec, size_t) const;
};
} // inline namespace v1
} // namespace net
} // namespace experimental
} // namespace std
class transfer_at_least
{
public:
explicit transfer_at_least(size_t m);
size_t operator()(const error_code& ec, size_t n) const;
private:
size_t minimum_; // exposition only
};
} // inline namespace v1
} // namespace net
} // namespace experimental
} // namespace std
§ 17.4
c ISO/IEC 2018 – All rights reserved 96
Dxxxx
namespace std {
namespace experimental {
namespace net {
inline namespace v1 {
class transfer_exactly
{
public:
explicit transfer_exactly(size_t e);
size_t operator()(const error_code& ec, size_t n) const;
private:
size_t exact_; // exposition only
};
} // inline namespace v1
} // namespace net
} // namespace experimental
} // namespace std
§ 17.5
c ISO/IEC 2018 – All rights reserved 97
Dxxxx
read operation so far. The completion condition return value specifies the maximum number of bytes
to be read on the subsequent read_some call. Overloads where a completion condition is not specified
behave as if called with an object of class transfer_all.
4 The synchronous read operation continues until:
(4.1) — the total number of bytes transferred is equal to buffer_size(buffers); or
(4.2) — the completion condition returns 0.
5 On return, ec contains the error_code value from the most recent read_some call.
6 Returns: The total number of bytes transferred in the synchronous read operation.
7 Remarks: This function shall not participate in overload resolution unless is_mutable_buffer_-
sequence_v<MutableBufferSequence> is true.
§ 17.5
c ISO/IEC 2018 – All rights reserved 98
Dxxxx
§ 17.6
c ISO/IEC 2018 – All rights reserved 99
Dxxxx
§ 17.7
c ISO/IEC 2018 – All rights reserved 100
Dxxxx
§ 17.8
c ISO/IEC 2018 – All rights reserved 101
Dxxxx
§ 17.8
c ISO/IEC 2018 – All rights reserved 102
Dxxxx
14 The program shall ensure both the AsyncWriteStream object stream and the memory associated with
the dynamic buffer b are valid until the completion handler for the asynchronous operation is invoked.
15 On completion of the asynchronous operation, ec is the error_code value from the most recent
asynchronous write_some operation, and n is the total number of bytes transferred.
16 Remarks: This function shall not participate in overload resolution unless is_dynamic_buffer_-
v<DynamicBuffer> is true.
§ 17.10
c ISO/IEC 2018 – All rights reserved 103
Dxxxx
3 Effects: Initiates an asynchronous operation to read data from the buffer-oriented asynchronous read
stream (17.1.2) object stream by performing zero or more asynchronous read_some operations on the
stream, until the readable bytes of the dynamic buffer (16.2.4) object b contain the specified delimiter
delim.
4 Data is placed into the dynamic buffer object b. A mutable buffer sequence (16.2.1) is obtained
prior to each async_read_some call using b.prepare(N), where N is an unspecified value such that
N <= max_size() - size(). [ Note: Implementations can use b.capacity() when determining N,
to minimize the number of asynchronous read_some operations performed on the stream. — end
note ] After the completion of each asynchronous read_some operation, the implementation performs
b.commit(n), where n is the value passed to the asynchronous read_some operation’s completion
handler.
5 The asynchronous read_until operation continues until:
(5.1) — the readable bytes of b contain the delimiter delim; or
(5.2) — b.size() == b.max_size(); or
(5.3) — an asynchronous read_some operation fails.
6 The program shall ensure the AsyncReadStream object stream is valid until the completion handler
for the asynchronous operation is invoked.
7 If delim is of type string_view, the implementation copies the underlying sequence of characters prior
to initiating an asynchronous read_some operation on the stream. [ Note: This means that the caller
is not required to guarantee the validity of the delimiter string after the call to async_read_until
returns. — end note ]
8 On completion of the asynchronous operation, if the readable bytes of b contain the delimiter, ec
is set such that !ec is true. Otherwise, if b.size() == b.max_size(), ec is set such that ec ==
stream_errc::not_found. If b.size() < b.max_size(), ec is the error_code from the most recent
asynchronous read_some operation. n is the number of readable bytes in b up to and including the
delimiter, if present, otherwise 0.
§ 17.10
c ISO/IEC 2018 – All rights reserved 104
Dxxxx
18 Sockets [socket]
18.1 Header <experimental/socket> synopsis [socket.synop]
namespace std {
namespace experimental {
namespace net {
inline namespace v1 {
// Sockets:
class socket_base;
template<class Protocol>
class basic_socket;
template<class Protocol>
class basic_datagram_socket;
template<class Protocol>
class basic_stream_socket;
template<class Protocol>
class basic_socket_acceptor;
§ 18.1
c ISO/IEC 2018 – All rights reserved 105
Dxxxx
} // inline namespace v1
} // namespace net
§ 18.1
c ISO/IEC 2018 – All rights reserved 106
Dxxxx
} // namespace experimental
} // namespace std
1 The figure below illustrates relationships between various types described in this document. A solid line from
A to B that is terminated by an open arrow indicates that A is derived from B. A solid line from A to B
that starts with a diamond and is terminated by a solid arrow indicates that A contains an object of type
B. A dotted line from A to B indicates that A is a synonym for the class template B with the specified
template argument.
2 For an object s, the conditions under which its synchronous socket operations may block the calling thread
(C++ 2014 [defns.block]) are determined as follows.
3 If:
§ 18.2.1
c ISO/IEC 2018 – All rights reserved 107
Dxxxx
§ 18.2.4
c ISO/IEC 2018 – All rights reserved 108
Dxxxx
3 In the table below, a denotes a (possibly const) value of type X, b denotes a value of type X, and s denotes a
(possibly const) value of a type that is convertible to size_t and denotes a size in bytes.
§ 18.2.4
c ISO/IEC 2018 – All rights reserved 109
Dxxxx
§ 18.2.6
c ISO/IEC 2018 – All rights reserved 110
Dxxxx
§ 18.2.8
c ISO/IEC 2018 – All rights reserved 111
Dxxxx
§ 18.2.10
c ISO/IEC 2018 – All rights reserved 112
Dxxxx
3 In this document, types that satisfy the BooleanSocketOption requirements are defined as follows.
class C
{
public:
// constructors:
C () noexcept;
explicit C (bool v) noexcept;
// members:
C & operator=(bool v) noexcept;
5 Let L and N identify the POSIX macros to be passed as the level and option_name arguments, respectively,
to POSIX setsockopt and getsockopt.
C () noexcept;
6 Postconditions: !value().
§ 18.2.10
c ISO/IEC 2018 – All rights reserved 113
Dxxxx
8 Returns: *this.
9 Postconditions: value() == v.
3 In this document, types that satisfy the IntegerSocketOption requirements are defined as follows.
§ 18.2.11
c ISO/IEC 2018 – All rights reserved 114
Dxxxx
class C
{
public:
// constructors:
C () noexcept;
explicit C (int v) noexcept;
// members:
C & operator=(int v) noexcept;
5 Let L and N identify the POSIX macros to be passed as the level and option_name arguments, respectively,
to POSIX setsockopt and getsockopt.
C () noexcept;
6 Postconditions: !value().
§ 18.2.11
c ISO/IEC 2018 – All rights reserved 115
Dxxxx
13 Returns: std::addressof(value_).
§ 18.3
c ISO/IEC 2018 – All rights reserved 116
Dxxxx
2 The object’s default_error_condition and equivalent virtual functions behave as specified for the
class error_category. The object’s name virtual function returns a pointer to the string "socket".
class socket_base
{
public:
class broadcast;
class debug;
class do_not_route;
class keep_alive;
class linger;
class out_of_band_inline;
class receive_buffer_size;
class receive_low_watermark;
class reuse_address;
class send_buffer_size;
class send_low_watermark;
using shutdown_type = T1 ;
static constexpr shutdown_type shutdown_receive;
static constexpr shutdown_type shutdown_send;
static constexpr shutdown_type shutdown_both;
using wait_type = T2 ;
static constexpr wait_type wait_read;
static constexpr wait_type wait_write;
static constexpr wait_type wait_error;
using message_flags = T3 ;
static constexpr message_flags message_peek;
static constexpr message_flags message_out_of_band;
static constexpr message_flags message_do_not_route;
protected:
socket_base();
~socket_base();
};
} // inline namespace v1
} // namespace net
§ 18.4
c ISO/IEC 2018 – All rights reserved 117
Dxxxx
} // namespace experimental
} // namespace std
§ 18.4
c ISO/IEC 2018 – All rights reserved 118
Dxxxx
§ 18.5
c ISO/IEC 2018 – All rights reserved 119
Dxxxx
class socket_base::linger
{
public:
// constructors:
linger() noexcept;
linger(bool e, chrono::seconds t) noexcept;
// members:
bool enabled() const noexcept;
void enabled(bool e) noexcept;
§ 18.5.1
c ISO/IEC 2018 – All rights reserved 120
Dxxxx
} // inline namespace v1
} // namespace net
} // namespace experimental
} // namespace std
2 linger satisfies the requirements of Destructible (C++ 2014 [destructible]), DefaultConstructible (C++
2014 [defaultconstructible]), CopyConstructible (C++ 2014 [copyconstructible]), CopyAssignable (C++
2014 [copyassignable]), GettableSocketOption (18.2.8), and SettableSocketOption (18.2.9).
3 Extensible implementations provide the following member functions:
namespace std {
namespace experimental {
namespace net {
inline namespace v1 {
class socket_base::linger
{
public:
template<class Protocol> int level(const Protocol& p) const noexcept;
template<class Protocol> int name(const Protocol& p) const noexcept;
template<class Protocol> void data(const Protocol& p) noexcept;
template<class Protocol> const void* data(const Protocol& p) const noexcept;
template<class Protocol> size_t size(const Protocol& p) const noexcept;
template<class Protocol> void resize(const Protocol& p, size_t s);
// remainder unchanged
private:
::linger value_; // exposition only
};
} // inline namespace v1
} // namespace net
} // namespace experimental
} // namespace std
linger() noexcept;
4 Postconditions: !enabled() && timeout() == chrono::seconds(0).
§ 18.5.1
c ISO/IEC 2018 – All rights reserved 121
Dxxxx
template<class Protocol>
class basic_socket : public socket_base
{
public:
// types:
§ 18.6
c ISO/IEC 2018 – All rights reserved 122
Dxxxx
void close();
void close(error_code& ec);
void cancel();
void cancel(error_code& ec);
template<class SettableSocketOption>
void set_option(const SettableSocketOption& option);
template<class SettableSocketOption>
void set_option(const SettableSocketOption& option, error_code& ec);
template<class GettableSocketOption>
void get_option(GettableSocketOption& option) const;
template<class GettableSocketOption>
void get_option(GettableSocketOption& option, error_code& ec) const;
template<class IoControlCommand>
void io_control(IoControlCommand& command);
template<class IoControlCommand>
void io_control(IoControlCommand& command, error_code& ec);
§ 18.6
c ISO/IEC 2018 – All rights reserved 123
Dxxxx
template<class CompletionToken>
DEDUCED async_connect(const endpoint_type& endpoint,
CompletionToken&& token);
template<class CompletionToken>
DEDUCED async_wait(wait_type w, CompletionToken&& token);
protected:
// 18.6.1, construct / copy / destroy:
~basic_socket();
basic_socket& operator=(const basic_socket&) = delete;
basic_socket& operator=(basic_socket&& rhs);
template<class OtherProtocol>
basic_socket& operator=(basic_socket<OtherProtocol>&& rhs);
private:
protocol_type protocol_; // exposition only
};
} // inline namespace v1
} // namespace net
} // namespace experimental
} // namespace std
2 Instances of class template basic_socket meet the requirements of Destructible (C++ 2014 [destructible]),
MoveConstructible (C++ 2014 [moveconstructible]), and MoveAssignable (C++ 2014 [moveassignable]).
3 When an operation has its effects specified as if by passing the result of native_handle() to a POSIX
function, then the operation fails with error condition errc::bad_file_descriptor if is_open() == false
at the point in the effects when the POSIX function is called.
§ 18.6.1
c ISO/IEC 2018 – All rights reserved 124
Dxxxx
5 Postconditions:
(5.1) — get_executor() == ctx.get_executor().
(5.2) — is_open() == true.
(5.3) — non_blocking() == false.
(5.4) — protocol_ == endpoint.protocol().
basic_socket(basic_socket&& rhs);
9 Effects: Move constructs an object of class basic_socket<Protocol> that refers to the state originally
represented by rhs.
10 Postconditions:
(10.1) — get_executor() == rhs.get_executor().
(10.2) — is_open() returns the same value as rhs.is_open() prior to the constructor invocation.
(10.3) — non_blocking() returns the same value as rhs.non_blocking() prior to the constructor invoca-
tion.
(10.4) — native_handle() returns the prior value of rhs.native_handle().
(10.5) — protocol_ is the prior value of rhs.protocol_.
(10.6) — rhs.is_open() == false.
§ 18.6.1
c ISO/IEC 2018 – All rights reserved 125
Dxxxx
template<class OtherProtocol>
basic_socket(basic_socket<OtherProtocol>&& rhs);
11 Requires: OtherProtocol is implicitly convertible to Protocol.
12 Effects: Move constructs an object of class basic_socket<Protocol> that refers to the state originally
represented by rhs.
13 Postconditions:
(13.1) — get_executor() == rhs.get_executor().
(13.2) — is_open() returns the same value as rhs.is_open() prior to the constructor invocation.
(13.3) — non_blocking() returns the same value as rhs.non_blocking() prior to the constructor invoca-
tion.
(13.4) — native_handle() returns the prior value of rhs.native_handle().
(13.5) — protocol_ is the result of converting the prior value of rhs.protocol_.
(13.6) — rhs.is_open() == false.
14 Remarks: This constructor shall not participate in overload resolution unless OtherProtocol is implicitly
convertible to Protocol.
template<class OtherProtocol>
basic_socket& operator=(basic_socket<OtherProtocol>&& rhs);
§ 18.6.3
c ISO/IEC 2018 – All rights reserved 126
Dxxxx
native_handle_type native_handle();
2 Returns: The native representation of this socket.
4 Postconditions:
(4.1) — is_open() == true.
(4.2) — non_blocking() == false.
(4.3) — protocol_ == protocol.
5 Error conditions:
(5.1) — socket_errc::already_open — if is_open() == true.
§ 18.6.4
c ISO/IEC 2018 – All rights reserved 127
Dxxxx
native_handle_type release();
native_handle_type release(error_code& ec);
10 Requires: is_open() == true.
11 Effects: Cancels all outstanding asynchronous operations associated with this socket. Comple-
tion handlers for canceled asynchronous operations are passed an error code ec such that ec ==
errc::operation_canceled yields true.
12 Returns: The native representation of this socket.
13 Postconditions: is_open() == false.
14 Remarks: Since the native socket is not closed prior to returning it, the caller is responsible for closing
it.
void close();
void close(error_code& ec);
16 Effects: If is_open() is true, cancels all outstanding asynchronous operations associated with
this socket, and establishes the postcondition as if by POSIX close(native_handle()). Comple-
tion handlers for canceled asynchronous operations are passed an error code ec such that ec ==
errc::operation_canceled yields true.
17 Postconditions: is_open() == false.
void cancel();
void cancel(error_code& ec);
18 Effects: Cancels all outstanding asynchronous operations associated with this socket. Comple-
tion handlers for canceled asynchronous operations are passed an error code ec such that ec ==
errc::operation_canceled yields true.
19 Error conditions:
(19.1) — errc::bad_file_descriptor — if is_open() is false.
20 Remarks: Does not block (C++ 2014 [defns.block]) the calling thread pending completion of the canceled
operations.
template<class SettableSocketOption>
void set_option(const SettableSocketOption& option);
template<class SettableSocketOption>
void set_option(const SettableSocketOption& option, error_code& ec);
21 Effects: Sets an option on this socket, as if by POSIX:
setsockopt(native_handle(), option.level(protocol_), option.name(protocol_),
option.data(protocol_), option.size(protocol_));
§ 18.6.4
c ISO/IEC 2018 – All rights reserved 128
Dxxxx
template<class GettableSocketOption>
void get_option(GettableSocketOption& option);
template<class GettableSocketOption>
void get_option(GettableSocketOption& option, error_code& ec);
22 Effects: Gets an option from this socket, as if by POSIX:
socklen_t option_len = option.size(protocol_);
int result = getsockopt(native_handle(), option.level(protocol_),
option.name(protocol_), option.data(protocol_),
&option_len);
if (result == 0)
option.resize(option_len);
template<class IoControlCommand>
void io_control(IoControlCommand& command);
template<class IoControlCommand>
void io_control(IoControlCommand& command, error_code& ec);
23 Effects: Executes an I/O control command on this socket, as if by POSIX:
ioctl(native_handle(), command.name(), command.data());
30 The native non-blocking mode has no effect on the behavior of the synchronous or asynchronous
operations specified in this clause.
31 Error conditions:
§ 18.6.4
c ISO/IEC 2018 – All rights reserved 129
Dxxxx
§ 18.6.4
c ISO/IEC 2018 – All rights reserved 130
Dxxxx
template<class CompletionToken>
DEDUCED async_connect(const endpoint_type& endpoint, CompletionToken&& token);
45 Completion signature: void(error_code ec).
46 Effects: If is_open() is false, opens this socket by performing open(endpoint.protocol(), ec). If
ec, the operation completes immediately with no further action. Initiates an asynchronous operation
to connect this socket to the specified remote endpoint, as if by POSIX connect(native_handle(),
endpoint.data(), endpoint.size()).
47 When an asynchronous connect operation on this socket is simultaneously outstanding with another
asynchronous connect, read, or write operation on this socket, the behavior is undefined.
48 If a program performs a synchronous operation on this socket, other than close or cancel, while there
is an outstanding asynchronous connect operation, the behavior is undefined.
template<class CompletionToken>
DEDUCED async_wait(wait_type w, CompletionToken&& token);
51 Completion signature: void(error_code ec).
52 Effects: Initiates an asynchronous operation to wait for this socket to be ready to read, ready to write,
or to have error conditions pending, as if by POSIX poll.
53 When there are multiple outstanding asynchronous wait operations on this socket with the same
wait_type value, all of these operations complete when this socket enters the corresponding ready
state. The order of invocation of the completion handlers for these operations is unspecified.
54 Error conditions:
(54.1) — errc::bad_file_descriptor — if is_open() is false.
§ 18.6.4
c ISO/IEC 2018 – All rights reserved 131
Dxxxx
template<class Protocol>
class basic_datagram_socket : public basic_socket<Protocol>
{
public:
// types:
~basic_datagram_socket();
basic_datagram_socket& operator=(const basic_datagram_socket&) = delete;
basic_datagram_socket& operator=(basic_datagram_socket&& rhs);
template<class OtherProtocol>
basic_datagram_socket& operator=(basic_datagram_socket<OtherProtocol>&& rhs);
template<class MutableBufferSequence>
size_t receive(const MutableBufferSequence& buffers);
template<class MutableBufferSequence>
size_t receive(const MutableBufferSequence& buffers,
error_code& ec);
template<class MutableBufferSequence>
size_t receive(const MutableBufferSequence& buffers,
socket_base::message_flags flags);
template<class MutableBufferSequence>
size_t receive(const MutableBufferSequence& buffers,
socket_base::message_flags flags, error_code& ec);
§ 18.7
c ISO/IEC 2018 – All rights reserved 132
Dxxxx
CompletionToken&& token);
template<class MutableBufferSequence>
size_t receive_from(const MutableBufferSequence& buffers,
endpoint_type& sender);
template<class MutableBufferSequence>
size_t receive_from(const MutableBufferSequence& buffers,
endpoint_type& sender, error_code& ec);
template<class MutableBufferSequence>
size_t receive_from(const MutableBufferSequence& buffers,
endpoint_type& sender,
socket_base::message_flags flags);
template<class MutableBufferSequence>
size_t receive_from(const MutableBufferSequence& buffers,
endpoint_type& sender,
socket_base::message_flags flags,
error_code& ec);
template<class ConstBufferSequence>
size_t send(const ConstBufferSequence& buffers);
template<class ConstBufferSequence>
size_t send(const ConstBufferSequence& buffers, error_code& ec);
template<class ConstBufferSequence>
size_t send(const ConstBufferSequence& buffers,
socket_base::message_flags flags);
template<class ConstBufferSequence>
size_t send(const ConstBufferSequence& buffers,
socket_base::message_flags flags, error_code& ec);
§ 18.7
c ISO/IEC 2018 – All rights reserved 133
Dxxxx
template<class ConstBufferSequence>
size_t send_to(const ConstBufferSequence& buffers,
const endpoint_type& recipient);
template<class ConstBufferSequence>
size_t send_to(const ConstBufferSequence& buffers,
const endpoint_type& recipient, error_code& ec);
template<class ConstBufferSequence>
size_t send_to(const ConstBufferSequence& buffers,
const endpoint_type& recipient,
socket_base::message_flags flags);
template<class ConstBufferSequence>
size_t send_to(const ConstBufferSequence& buffers,
const endpoint_type& recipient,
socket_base::message_flags flags, error_code& ec);
} // inline namespace v1
} // namespace net
} // namespace experimental
} // namespace std
2 Instances of class template basic_datagram_socket meet the requirements of Destructible (C++ 2014
[destructible]), MoveConstructible (C++ 2014 [moveconstructible]), and MoveAssignable (C++ 2014 [move-
assignable]).
3 If a program performs a synchronous operation on this socket, other than close, cancel, shutdown, send,
or send_to, while there is an outstanding asynchronous read operation, the behavior is undefined.
4 If a program performs a synchronous operation on this socket, other than close, cancel, shutdown, receive,
or receive_from, while there is an outstanding asynchronous write operation, the behavior is undefined.
5 When an operation has its effects specified as if by passing the result of native_handle() to a POSIX
function, then the operation fails with error condition errc::bad_file_descriptor if is_open() == false
at the point in the effects when the POSIX function is called.
6 If native_handle_type and basic_socket<Protocol>::native_handle_type are both defined then they
name the same type.
§ 18.7.1
c ISO/IEC 2018 – All rights reserved 134
Dxxxx
basic_datagram_socket(basic_datagram_socket&& rhs);
5 Effects: Move constructs an object of class basic_datagram_socket<Protocol>, initializing the base
class with basic_socket<Protocol>(std::move(rhs)).
template<class OtherProtocol>
basic_datagram_socket(basic_datagram_socket<OtherProtocol>&& rhs);
6 Requires: OtherProtocol is implicitly convertible to Protocol.
7 Effects: Move constructs an object of class basic_datagram_socket<Protocol>, initializing the base
class with basic_socket<Protocol>(std::move(rhs)).
8 Remarks: This constructor shall not participate in overload resolution unless OtherProtocol is implicitly
convertible to Protocol.
template<class OtherProtocol>
basic_datagram_socket& operator=(basic_datagram_socket<OtherProtocol>&& rhs);
3 Requires: OtherProtocol is implicitly convertible to Protocol.
4 Effects: Equivalent to basic_socket<Protocol>::operator=(std::move(rhs)).
5 Returns: *this.
6 Remarks: This assignment operator shall not participate in overload resolution unless OtherProtocol
is implicitly convertible to Protocol.
template<class MutableBufferSequence>
size_t receive(const MutableBufferSequence& buffers,
socket_base::message_flags flags);
template<class MutableBufferSequence>
size_t receive(const MutableBufferSequence& buffers,
socket_base::message_flags flags, error_code& ec);
§ 18.7.3
c ISO/IEC 2018 – All rights reserved 135
Dxxxx
§ 18.7.3
c ISO/IEC 2018 – All rights reserved 136
Dxxxx
template<class MutableBufferSequence>
size_t receive_from(const MutableBufferSequence& buffers,
endpoint_type& sender);
template<class MutableBufferSequence>
size_t receive_from(const MutableBufferSequence& buffers,
endpoint_type& sender, error_code& ec);
12 Returns: receive_from(buffers, sender, socket_base::message_flags(), ec).
template<class MutableBufferSequence>
size_t receive_from(const MutableBufferSequence& buffers,
endpoint_type& sender,
socket_base::message_flags flags);
template<class MutableBufferSequence>
size_t receive_from(const MutableBufferSequence& buffers,
endpoint_type& sender,
socket_base::message_flags flags,
error_code& ec);
13 A read operation (16.2.5).
14 Effects: Constructs an array iov of POSIX type struct iovec and length iovlen, corresponding to
buffers, and reads data from this socket as if by POSIX:
msghdr message;
message.msg_name = sender.data();
message.msg_namelen = sender.capacity();
message.msg_iov = iov;
message.msg_iovlen = iovlen;
message.msg_control = nullptr;
message.msg_controllen = 0;
message.msg_flags = 0;
ssize_t result = recvmsg(native_handle(), &message, static_cast<int>(flags));
if (result >= 0)
sender.resize(message.msg_namelen);
§ 18.7.3
c ISO/IEC 2018 – All rights reserved 137
Dxxxx
template<class ConstBufferSequence>
size_t send(const ConstBufferSequence& buffers);
template<class ConstBufferSequence>
size_t send(const ConstBufferSequence& buffers, error_code& ec);
24 Returns: send(buffers, socket_base::message_flags(), ec).
template<class ConstBufferSequence>
size_t send(const ConstBufferSequence& buffers,
socket_base::message_flags flags);
template<class ConstBufferSequence>
size_t send(const ConstBufferSequence& buffers,
socket_base::message_flags flags, error_code& ec);
25 A write operation (16.2.5).
26 Effects: Constructs an array iov of POSIX type struct iovec and length iovlen, corresponding to
buffers, and writes data to this socket as if by POSIX:
msghdr message;
message.msg_name = nullptr;
message.msg_namelen = 0;
message.msg_iov = iov;
message.msg_iovlen = iovlen;
message.msg_control = nullptr;
message.msg_controllen = 0;
message.msg_flags = 0;
sendmsg(native_handle(), &message, static_cast<int>(flags));
§ 18.7.3
c ISO/IEC 2018 – All rights reserved 138
Dxxxx
template<class ConstBufferSequence>
size_t send_to(const ConstBufferSequence& buffers,
const endpoint_type& recipient);
template<class ConstBufferSequence>
size_t send_to(const ConstBufferSequence& buffers,
const endpoint_type& recipient, error_code& ec);
33 Returns: send_to(buffers, recipient, socket_base::message_flags(), ec).
template<class ConstBufferSequence>
size_t send_to(const ConstBufferSequence& buffers,
const endpoint_type& recipient,
socket_base::message_flags flags);
template<class ConstBufferSequence>
size_t send_to(const ConstBufferSequence& buffers,
const endpoint_type& recipient,
socket_base::message_flags flags, error_code& ec);
34 A write operation (16.2.5).
35 Effects: Constructs an array iov of POSIX type struct iovec and length iovlen, corresponding to
buffers, and writes data to this socket as if by POSIX:
msghdr message;
message.msg_name = recipient.data();
message.msg_namelen = recipient.size();
message.msg_iov = iov;
§ 18.7.3
c ISO/IEC 2018 – All rights reserved 139
Dxxxx
message.msg_iovlen = iovlen;
message.msg_control = nullptr;
message.msg_controllen = 0;
message.msg_flags = 0;
sendmsg(native_handle(), &message, static_cast<int>(flags));
template<class Protocol>
class basic_stream_socket : public basic_socket<Protocol>
{
public:
§ 18.8
c ISO/IEC 2018 – All rights reserved 140
Dxxxx
// types:
~basic_stream_socket();
basic_stream_socket& operator=(const basic_stream_socket&) = delete;
basic_stream_socket& operator=(basic_stream_socket&& rhs);
template<class OtherProtocol>
basic_stream_socket& operator=(basic_stream_socket<OtherProtocol>&& rhs);
template<class MutableBufferSequence>
size_t receive(const MutableBufferSequence& buffers);
template<class MutableBufferSequence>
size_t receive(const MutableBufferSequence& buffers,
error_code& ec);
template<class MutableBufferSequence>
size_t receive(const MutableBufferSequence& buffers,
socket_base::message_flags flags);
template<class MutableBufferSequence>
size_t receive(const MutableBufferSequence& buffers,
socket_base::message_flags flags, error_code& ec);
template<class ConstBufferSequence>
size_t send(const ConstBufferSequence& buffers);
template<class ConstBufferSequence>
size_t send(const ConstBufferSequence& buffers, error_code& ec);
template<class ConstBufferSequence>
§ 18.8
c ISO/IEC 2018 – All rights reserved 141
Dxxxx
template<class MutableBufferSequence>
size_t read_some(const MutableBufferSequence& buffers);
template<class MutableBufferSequence>
size_t read_some(const MutableBufferSequence& buffers,
error_code& ec);
template<class ConstBufferSequence>
size_t write_some(const ConstBufferSequence& buffers);
template<class ConstBufferSequence>
size_t write_some(const ConstBufferSequence& buffers,
error_code& ec);
} // inline namespace v1
} // namespace net
} // namespace experimental
} // namespace std
2 Instances of class template basic_stream_socket meet the requirements of Destructible (C++ 2014
[destructible]), MoveConstructible (C++ 2014 [moveconstructible]), MoveAssignable (C++ 2014 [move-
assignable]), SyncReadStream (17.1.1), SyncWriteStream (17.1.3), AsyncReadStream (17.1.2), and AsyncWriteStream (17.1.4)
3 If a program performs a synchronous operation on this socket, other than close, cancel, shutdown, or send,
while there is an outstanding asynchronous read operation, the behavior is undefined.
4 If a program performs a synchronous operation on this socket, other than close, cancel, shutdown, or
receive, while there is an outstanding asynchronous write operation, the behavior is undefined.
5 When an operation has its effects specified as if by passing the result of native_handle() to a POSIX
function, then the operation fails with error condition errc::bad_file_descriptor if is_open() == false
at the point in the effects when the POSIX function is called.
6 If native_handle_type and basic_socket<Protocol>::native_handle_type are both defined then they
name the same type.
§ 18.8
c ISO/IEC 2018 – All rights reserved 142
Dxxxx
basic_stream_socket(basic_stream_socket&& rhs);
5 Effects: Move constructs an object of class basic_stream_socket<Protocol>, initializing the base
class with basic_socket<Protocol>(std::move(rhs)).
template<class OtherProtocol>
basic_stream_socket(basic_stream_socket<OtherProtocol>&& rhs);
6 Requires: OtherProtocol is implicitly convertible to Protocol.
7 Effects: Move constructs an object of class basic_stream_socket<Protocol>, initializing the base
class with basic_socket<Protocol>(std::move(rhs)).
8 Remarks: This constructor shall not participate in overload resolution unless OtherProtocol is implicitly
convertible to Protocol.
template<class OtherProtocol>
basic_stream_socket& operator=(basic_stream_socket<OtherProtocol>&& rhs);
3 Requires: OtherProtocol is implicitly convertible to Protocol.
4 Effects: Equivalent to basic_socket<Protocol>::operator=(std::move(rhs)).
5 Returns: *this.
6 Remarks: This assignment operator shall not participate in overload resolution unless OtherProtocol
is implicitly convertible to Protocol.
§ 18.8.3
c ISO/IEC 2018 – All rights reserved 143
Dxxxx
template<class MutableBufferSequence>
size_t receive(const MutableBufferSequence& buffers,
socket_base::message_flags flags);
template<class MutableBufferSequence>
size_t receive(const MutableBufferSequence& buffers,
socket_base::message_flags flags, error_code& ec);
2 A read operation (16.2.5).
3 Effects: If buffer_size(buffers) == 0, returns immediately with no error. Otherwise, constructs
an array iov of POSIX type struct iovec and length iovlen, corresponding to buffers, and reads
data from this socket as if by POSIX:
msghdr message;
message.msg_name = nullptr;
message.msg_namelen = 0;
message.msg_iov = iov;
message.msg_iovlen = iovlen;
message.msg_control = nullptr;
message.msg_controllen = 0;
message.msg_flags = 0;
recvmsg(native_handle(), &message, static_cast<int>(flags));
4 Returns: On success, the number of bytes received. Otherwise 0.
5 Error conditions:
(5.1) — stream_errc::eof — if there is no data to be received and the peer performed an orderly
shutdown.
§ 18.8.3
c ISO/IEC 2018 – All rights reserved 144
Dxxxx
template<class ConstBufferSequence>
size_t send(const ConstBufferSequence& buffers);
template<class ConstBufferSequence>
size_t send(const ConstBufferSequence& buffers, error_code& ec);
12 Returns: send(buffers, socket_base::message_flags(), ec).
template<class ConstBufferSequence>
size_t send(const ConstBufferSequence& buffers,
socket_base::message_flags flags);
template<class ConstBufferSequence>
size_t send(const ConstBufferSequence& buffers,
socket_base::message_flags flags, error_code& ec);
13 A write operation (16.2.5).
14 Effects: If buffer_size(buffers) == 0, returns immediately with no error. Otherwise, constructs
an array iov of POSIX type struct iovec and length iovlen, corresponding to buffers, and writes
data to this socket as if by POSIX:
msghdr message;
message.msg_name = nullptr;
message.msg_namelen = 0;
message.msg_iov = iov;
message.msg_iovlen = iovlen;
message.msg_control = nullptr;
message.msg_controllen = 0;
message.msg_flags = 0;
sendmsg(native_handle(), &message, static_cast<int>(flags));
§ 18.8.3
c ISO/IEC 2018 – All rights reserved 145
Dxxxx
msghdr message;
message.msg_name = nullptr;
message.msg_namelen = 0;
message.msg_iov = iov;
message.msg_iovlen = iovlen;
message.msg_control = nullptr;
message.msg_controllen = 0;
message.msg_flags = 0;
sendmsg(native_handle(), &message, static_cast<int>(flags));
template<class MutableBufferSequence>
size_t read_some(const MutableBufferSequence& buffers);
template<class MutableBufferSequence>
size_t read_some(const MutableBufferSequence& buffers,
error_code& ec);
21 Returns: receive(buffers, ec).
template<class ConstBufferSequence>
size_t write_some(const ConstBufferSequence& buffers);
template<class ConstBufferSequence>
size_t write_some(const ConstBufferSequence& buffers,
error_code& ec);
23 Returns: send(buffers, ec).
template<class AcceptableProtocol>
class basic_socket_acceptor : public socket_base
{
public:
// types:
§ 18.9
c ISO/IEC 2018 – All rights reserved 146
Dxxxx
~basic_socket_acceptor();
basic_socket_acceptor& operator=(const basic_socket_acceptor&) = delete;
basic_socket_acceptor& operator=(basic_socket_acceptor&& rhs);
template<class OtherProtocol>
basic_socket_acceptor& operator=(basic_socket_acceptor<OtherProtocol>&& rhs);
void close();
void close(error_code& ec);
void cancel();
void cancel(error_code& ec);
template<class SettableSocketOption>
void set_option(const SettableSocketOption& option);
template<class SettableSocketOption>
void set_option(const SettableSocketOption& option, error_code& ec);
§ 18.9
c ISO/IEC 2018 – All rights reserved 147
Dxxxx
template<class GettableSocketOption>
void get_option(GettableSocketOption& option) const;
template<class GettableSocketOption>
void get_option(GettableSocketOption& option, error_code& ec) const;
template<class IoControlCommand>
void io_control(IoControlCommand& command);
template<class IoControlCommand>
void io_control(IoControlCommand& command, error_code& ec);
socket_type accept();
socket_type accept(error_code& ec);
socket_type accept(io_context& ctx);
socket_type accept(io_context& ctx, error_code& ec);
template<class CompletionToken>
DEDUCED async_accept(CompletionToken&& token);
template<class CompletionToken>
DEDUCED async_accept(io_context& ctx, CompletionToken&& token);
template<class CompletionToken>
DEDUCED async_accept(endpoint_type& endpoint,
CompletionToken&& token);
template<class CompletionToken>
DEDUCED async_accept(io_context& ctx, endpoint_type& endpoint,
CompletionToken&& token);
§ 18.9
c ISO/IEC 2018 – All rights reserved 148
Dxxxx
template<class CompletionToken>
DEDUCED async_wait(wait_type w, CompletionToken&& token);
private:
protocol_type protocol_; // exposition only
};
} // inline namespace v1
} // namespace net
} // namespace experimental
} // namespace std
2 Instances of class template basic_socket_acceptor meet the requirements of Destructible (C++ 2014
[destructible]), MoveConstructible (C++ 2014 [moveconstructible]), and MoveAssignable (C++ 2014 [move-
assignable]).
3 When there are multiple outstanding asynchronous accept operations the order in which the incoming
connections are dequeued, and the order of invocation of the completion handlers for these operations, is
unspecified.
4 When an operation has its effects specified as if by passing the result of native_handle() to a POSIX
function, then the operation fails with error condition errc::bad_file_descriptor if is_open() == false
at the point in the effects when the POSIX function is called.
§ 18.9.1
c ISO/IEC 2018 – All rights reserved 149
Dxxxx
5 Postconditions:
(5.1) — get_executor() == ctx.get_executor().
(5.2) — is_open() == true.
(5.3) — non_blocking() == false.
(5.4) — enable_connection_aborted() == false.
(5.5) — protocol_ == endpoint.protocol().
basic_socket_acceptor(basic_socket_acceptor&& rhs);
9 Effects: Move constructs an object of class basic_socket_acceptor<AcceptableProtocol> that refers
to the state originally represented by rhs.
10 Postconditions:
(10.1) — get_executor() == rhs.get_executor().
(10.2) — is_open() returns the same value as rhs.is_open() prior to the constructor invocation.
(10.3) — non_blocking() returns the same value as rhs.non_blocking() prior to the constructor invoca-
tion.
(10.4) — enable_connection_aborted() returns the same value as rhs.enable_connection_aborted()
prior to the constructor invocation.
(10.5) — native_handle() returns the same value as rhs.native_handle() prior to the constructor
invocation.
(10.6) — protocol_ is equal to the prior value of rhs.protocol_.
(10.7) — rhs.is_open() == false.
template<class OtherProtocol>
basic_socket_acceptor(basic_socket_acceptor<OtherProtocol>&& rhs);
11 Requires: OtherProtocol is implicitly convertible to Protocol.
12 Effects: Move constructs an object of class basic_socket_acceptor<AcceptableProtocol> that refers
to the state originally represented by rhs.
13 Postconditions:
(13.1) — get_executor() == rhs.get_executor().
§ 18.9.1
c ISO/IEC 2018 – All rights reserved 150
Dxxxx
(13.2) — is_open() returns the same value as rhs.is_open() prior to the constructor invocation.
(13.3) — non_blocking() returns the same value as rhs.non_blocking() prior to the constructor invoca-
tion.
(13.4) — enable_connection_aborted() returns the same value as rhs.enable_connection_aborted()
prior to the constructor invocation.
(13.5) — native_handle() returns the prior value of rhs.native_handle().
(13.6) — protocol_ is the result of converting the prior value of rhs.protocol_.
(13.7) — rhs.is_open() == false.
14 Remarks: This constructor shall not participate in overload resolution unless OtherProtocol is implicitly
convertible to Protocol.
template<class OtherProtocol>
basic_socket_acceptor& operator=(basic_socket_acceptor<OtherProtocol>&& rhs);
4 Requires: OtherProtocol is implicitly convertible to Protocol.
5 Effects: If is_open() is true, cancels all outstanding asynchronous operations associated with this
acceptor, and releases acceptor resources as if by POSIX close(native_handle()). Then moves into
*this the state originally represented by rhs. Completion handlers for canceled operations are passed
an error code ec such that ec == errc::operation_canceled yields true.
6 Postconditions:
§ 18.9.3
c ISO/IEC 2018 – All rights reserved 151
Dxxxx
native_handle_type native_handle();
2 Returns: The native representation of this acceptor.
4 Postconditions:
(4.1) — is_open() == true.
(4.2) — non_blocking() == false.
(4.3) — enable_connection_aborted() == false.
(4.4) — protocol_ == protocol.
5 Error conditions:
(5.1) — socket_errc::already_open — if is_open() is true.
§ 18.9.4
c ISO/IEC 2018 – All rights reserved 152
Dxxxx
native_handle_type release();
native_handle_type release(error_code& ec);
10 Requires: is_open() == true.
11 Effects: Cancels all outstanding asynchronous operations associated with this acceptor. Comple-
tion handlers for canceled asynchronous operations are passed an error code ec such that ec ==
errc::operation_canceled yields true.
12 Returns: The native representation of this acceptor.
13 Postconditions: is_open() == false.
14 Remarks: Since the native acceptor is not closed prior to returning it, the caller is responsible for
closing it.
void close();
void close(error_code& ec);
16 Effects: If is_open() is true, cancels all outstanding asynchronous operations associated with this
acceptor, and establishes the postcondition as if by POSIX close(native_handle()). Comple-
tion handlers for canceled asynchronous operations are passed an error code ec such that ec ==
errc::operation_canceled yields true.
17 Postconditions: is_open() == false.
void cancel();
void cancel(error_code& ec);
18 Effects: Cancels all outstanding asynchronous operations associated with this acceptor. Comple-
tion handlers for canceled asynchronous operations are passed an error code ec such that ec ==
errc::operation_canceled yields true.
19 Error conditions:
(19.1) — errc::bad_file_descriptor — if is_open() is false.
(19.2) — errc::operation_not_supported — current conditions do not permit cancelation. The condi-
tions under which cancelation of asynchronous operations is permitted are implementation-defined.
template<class SettableSocketOption>
void set_option(const SettableSocketOption& option);
template<class SettableSocketOption>
void set_option(const SettableSocketOption& option, error_code& ec);
20 Effects: Sets an option on this acceptor, as if by POSIX:
setsockopt(native_handle(), option.level(protocol_), option.name(protocol_),
option.data(protocol_), option.size(protocol_));
§ 18.9.4
c ISO/IEC 2018 – All rights reserved 153
Dxxxx
template<class GettableSocketOption>
void get_option(GettableSocketOption& option);
template<class GettableSocketOption>
void get_option(GettableSocketOption& option, error_code& ec);
21 Effects: Gets an option from this acceptor, as if by POSIX:
socklen_t option_len = option.size(protocol_);
int result = getsockopt(native_handle(), option.level(protocol_),
option.name(protocol_), option.data(protocol_),
&option_len);
if (result == 0)
option.resize(option_len);
template<class IoControlCommand>
void io_control(IoControlCommand& command);
template<class IoControlCommand>
void io_control(IoControlCommand& command, error_code& ec);
22 Effects: Executes an I/O control command on this acceptor, as if by POSIX:
ioctl(native_handle(), command.name(), command.data());
29 The native non-blocking mode has no effect on the behavior of the synchronous or asynchronous
operations specified in this clause.
30 Error conditions:
§ 18.9.4
c ISO/IEC 2018 – All rights reserved 154
Dxxxx
socket_type accept();
socket_type accept(error_code& ec);
§ 18.9.4
c ISO/IEC 2018 – All rights reserved 155
Dxxxx
template<class CompletionToken>
DEDUCED async_accept(CompletionToken&& token);
43 Returns:
async_accept(get_executor().context(), forward<CompletionToken>(token))
template<class CompletionToken>
DEDUCED async_accept(io_context& ctx, CompletionToken&& token);
44 Completion signature: void(error_code ec, socket_type s).
45 Effects: Initiates an asynchronous operation to extract a socket from the queue of pending connections
of the acceptor, as if by POSIX:
native_handle_type h = accept(native_handle(), nullptr, 0);
template<class CompletionToken>
DEDUCED async_accept(endpoint_type& endpoint,
CompletionToken&& token);
49 Returns:
async_accept(get_executor().context(), endpoint, forward<CompletionToken>(token))
template<class CompletionToken>
DEDUCED async_accept(io_context& ctx, endpoint_type& endpoint,
CompletionToken&& token);
§ 18.9.4
c ISO/IEC 2018 – All rights reserved 156
Dxxxx
template<class CompletionToken>
DEDUCED async_wait(wait_type w, CompletionToken&& token);
53 Completion signature: void(error_code ec).
54 Effects: Initiates an asynchronous operation to wait for the acceptor to have a queued incoming
connection, or to have error conditions pending, as if by POSIX poll.
55 When multiple asynchronous wait operations are initiated with the same wait_type value, all out-
standing operations complete when the acceptor enters the corresponding ready state. The order of
invocation of the completions handlers for these operations is unspecified.
56 Error conditions:
(56.1) — errc::bad_file_descriptor — if is_open() is false.
§ 18.9.4
c ISO/IEC 2018 – All rights reserved 157
Dxxxx
basic_socket_streambuf();
explicit basic_socket_streambuf(basic_stream_socket<protocol_type> s);
basic_socket_streambuf(const basic_socket_streambuf&) = delete;
basic_socket_streambuf(basic_socket_streambuf&& rhs);
virtual ~basic_socket_streambuf();
basic_socket_streambuf& operator=(const basic_socket_streambuf&) = delete;
basic_socket_streambuf& operator=(basic_socket_streambuf&& rhs);
// 19.1.2, members:
basic_socket_streambuf* close();
basic_socket<protocol_type>& socket();
error_code error() const;
§ 19.1
c ISO/IEC 2018 – All rights reserved 158
Dxxxx
protected:
// overridden virtual functions:
virtual int_type underflow() override;
virtual int_type pbackfail(int_type c = traits_type::eof()) override;
virtual int_type overflow(int_type c = traits_type::eof()) override;
virtual int sync() override;
virtual streambuf* setbuf(char_type* s, streamsize n) override;
private:
basic_stream_socket<protocol_type> socket_; // exposition only
error_code ec_; // exposition only
time_point expiry_; // exposition only
};
} // inline namespace v1
} // namespace net
} // namespace experimental
} // namespace std
3 Instances of class template basic_socket_streambuf meet the requirements of Destructible (C++ 2014
[destructible]), MoveConstructible (C++ 2014 [moveconstructible]), and MoveAssignable (C++ 2014 [move-
assignable]).
basic_socket_streambuf(basic_socket_streambuf&& rhs);
5 Effects: Move constructs from the rvalue rhs. It is implementation-defined whether the sequence
pointers in *this (eback(), gptr(), egptr(), pbase(), pptr(), epptr()) obtain the values which
rhs had. Whether they do or not, *this and rhs reference separate buffers (if any at all) after the
construction. Additionally *this references the socket which rhs did before the construction, and rhs
references no open socket after the construction.
6 Postconditions: Let rhs_p refer to the state of rhs just prior to this construction and let rhs_a refer
to the state of rhs just after this construction.
(6.1) — is_open() == rhs_p.is_open()
(6.2) — rhs_a.is_open() == false
(6.3) — error() == rhs_p.error()
(6.4) — !rhs_a.error()
(6.5) — expiry() == rhs_p.expiry()
(6.6) — rhs_a.expiry() == time_point::max()
§ 19.1.1
c ISO/IEC 2018 – All rights reserved 159
Dxxxx
virtual ~basic_socket_streambuf();
7 Effects: If a put area exists, calls overflow(traits_type::eof()) to flush characters. [ Note: The
socket is closed by the basic_stream_socket<protocol_type> destructor. — end note ]
template<class... Args>
basic_socket_streambuf* connect(Args&&... args);
3 Effects: Initializes the basic_socket_streambuf as required and closes the socket as if by call-
ing socket_.close(ec_). Obtains an endpoint sequence endpoints by performing protocol_-
type::resolver(ctx).resolve(forward<Args>(args)...), where ctx is an unspecified object of
class io_context. For each endpoint e in the sequence, closes and re-opens the socket by performing
socket_.close(ec_) and socket_.open(e.protocol(), ec_), then attempts to establish a connec-
tion as if by POSIX connect(socket_.native_handle(), static_cast<sockaddr*>(e.data()),
e.size()). ec_ is set to reflect the error code produced by the operation. If the operation does
not complete before the absolute timeout specified by expiry_, the socket is closed and ec_ is set to
errc::timed_out.
4 Returns: if !ec_, this; otherwise, a null pointer.
5 Remarks: This function shall not participate in overload resolution unless Protocol meets the require-
ments for an internet protocol (21.2.1).
§ 19.1.2
c ISO/IEC 2018 – All rights reserved 160
Dxxxx
basic_socket_streambuf* close();
6 Effects: If a put area exists, calls overflow(traits_type::eof()) to flush characters. Regardless
of whether the preceding call fails or throws an exception, the function closes the socket as if by
basic_socket<protocol_type>::close(ec_). If any of the calls made by the function fail, close
fails by returning a null pointer. If one of these calls throws an exception, the exception is caught and
rethrown after closing the socket.
7 Returns: this on success, a null pointer otherwise.
8 Postconditions: is_open() == false.
basic_socket<protocol_type>& socket();
9 Returns: socket_.
§ 19.1.3
c ISO/IEC 2018 – All rights reserved 161
Dxxxx
basic_socket_iostream();
explicit basic_socket_iostream(basic_stream_socket<protocol_type> s);
basic_socket_iostream(const basic_socket_iostream&) = delete;
§ 19.2
c ISO/IEC 2018 – All rights reserved 162
Dxxxx
basic_socket_iostream(basic_socket_iostream&& rhs);
template<class... Args>
explicit basic_socket_iostream(Args&&... args);
// 19.2.2, members:
void close();
basic_socket<protocol_type>& socket();
error_code error() const;
private:
basic_socket_streambuf<protocol_type, clock_type, wait_traits_type> sb_; // exposition only
};
} // inline namespace v1
} // namespace net
} // namespace experimental
} // namespace std
3 Instances of class template basic_socket_iostream meet the requirements of Destructible (C++ 2014
[destructible]), MoveConstructible (C++ 2014 [moveconstructible]), and MoveAssignable (C++ 2014 [move-
assignable]).
basic_socket_iostream(basic_socket_iostream&& rhs);
3 Effects: Move constructs from the rvalue rhs. This is accomplished by move constructing the base
class, and the contained basic_socket_streambuf. Next basic_iostream<char>::set_rdbuf(&sb_)
is called to install the contained basic_socket_streambuf.
template<class... Args>
explicit basic_socket_iostream(Args&&... args);
§ 19.2.1
c ISO/IEC 2018 – All rights reserved 163
Dxxxx
4 Effects: Initializes the base class as basic_iostream<char>(&sb_), value-initializes sb_, and performs
setf(std::ios_base::unitbuf). Then calls rdbuf()->connect(forward<Args>(args)...). If that
function returns a null pointer, calls setstate(failbit).
void close();
2 Effects: Calls rdbuf()->close(). If that function returns a null pointer, calls setstate(failbit)
(which may throw ios_base::failure).
basic_socket<protocol_type>& socket();
5 Returns: rdbuf()->socket().
§ 19.2.2
c ISO/IEC 2018 – All rights reserved 164
Dxxxx
§ 20.1
c ISO/IEC 2018 – All rights reserved 165
Dxxxx
§ 20.2
c ISO/IEC 2018 – All rights reserved 166
Dxxxx
§ 20.2
c ISO/IEC 2018 – All rights reserved 167
Dxxxx
class address;
class address_v4;
class address_v6;
class bad_address_cast;
§ 21.1
c ISO/IEC 2018 – All rights reserved 168
Dxxxx
§ 21.1
c ISO/IEC 2018 – All rights reserved 169
Dxxxx
class network_v4;
class network_v6;
template<class InternetProtocol>
class basic_endpoint;
§ 21.1
c ISO/IEC 2018 – All rights reserved 170
Dxxxx
template<class InternetProtocol>
class basic_resolver_entry;
template<class InternetProtocol>
bool operator==(const basic_resolver_entry<InternetProtocol>&,
const basic_resolver_entry<InternetProtocol>&);
template<class InternetProtocol>
bool operator!=(const basic_resolver_entry<InternetProtocol>&,
const basic_resolver_entry<InternetProtocol>&);
template<class InternetProtocol>
class basic_resolver_results;
template<class InternetProtocol>
bool operator==(const basic_resolver_results<InternetProtocol>&,
const basic_resolver_results<InternetProtocol>&);
template<class InternetProtocol>
bool operator!=(const basic_resolver_results<InternetProtocol>&,
const basic_resolver_results<InternetProtocol>&);
class resolver_base;
template<class InternetProtocol>
class basic_resolver;
string host_name();
string host_name(error_code&);
template<class Allocator>
basic_string<char, char_traits<char>, Allocator>
host_name(const Allocator&);
template<class Allocator>
basic_string<char, char_traits<char>, Allocator>
host_name(const Allocator&, error_code&);
§ 21.1
c ISO/IEC 2018 – All rights reserved 171
Dxxxx
class tcp;
class udp;
class v6_only;
namespace unicast {
class hops;
} // namespace unicast
namespace multicast {
class join_group;
class leave_group;
class outbound_interface;
class hops;
class enable_loopback;
} // namespace multicast
} // namespace ip
} // inline namespace v1
} // namespace net
} // namespace experimental
} // namespace std
§ 21.2.1
c ISO/IEC 2018 – All rights reserved 172
Dxxxx
3 In this document, types that satisfy the MulticastGroupSocketOption requirements are defined as follows.
class C
{
public:
// constructors:
explicit C (const address& multicast_group) noexcept;
explicit C (const address_v4& multicast_group,
const address_v4& network_interface = address_v4::any()) noexcept;
explicit C (const address_v6& multicast_group,
unsigned int network_interface = 0) noexcept;
};
§ 21.2.2
c ISO/IEC 2018 – All rights reserved 173
Dxxxx
{
public:
template<class Protocol> int level(const Protocol& p) const noexcept;
template<class Protocol> int name(const Protocol& p) const noexcept;
template<class Protocol> const void* data(const Protocol& p) const noexcept;
template<class Protocol> size_t size(const Protocol& p) const noexcept;
// remainder unchanged
private:
ip_mreq v4_value_; // exposition only
ipv6_mreq v6_value_; // exposition only
};
5 Let L and N identify the POSIX macros to be passed as the level and option_name arguments, respectively,
to POSIX setsockopt and getsockopt.
explicit C (const address& multicast_group) noexcept;
6 Effects: If multicast_group.is_v6() is true, calls C (multicast_group.to_v6()); otherwise, calls
C (multicast_group.to_v4()).
§ 21.3
c ISO/IEC 2018 – All rights reserved 174
Dxxxx
class address
{
public:
// 21.4.1, constructors:
constexpr address() noexcept;
constexpr address(const address& a) noexcept;
constexpr address(const address_v4& a) noexcept;
constexpr address(const address_v6& a) noexcept;
// 21.4.2, assignment:
address& operator=(const address& a) noexcept;
address& operator=(const address_v4& a) noexcept;
address& operator=(const address_v6& a) noexcept;
// 21.4.3, members:
constexpr bool is_v4() const noexcept;
constexpr bool is_v6() const noexcept;
constexpr address_v4 to_v4() const;
constexpr address_v6 to_v6() const;
constexpr bool is_unspecified() const noexcept;
constexpr bool is_loopback() const noexcept;
constexpr bool is_multicast() const noexcept;
template<class Allocator = allocator<char>>
basic_string<char, char_traits<char>, Allocator>
to_string(const Allocator& a = Allocator()) const;
private:
address_v4 v4_; // exposition only
address_v6 v6_; // exposition only
};
§ 21.4
c ISO/IEC 2018 – All rights reserved 175
Dxxxx
} // namespace ip
} // inline namespace v1
} // namespace net
} // namespace experimental
} // namespace std
2 address satisfies the requirements for Destructible (C++ 2014 [destructible]), CopyConstructible (C++
2014 [copyconstructible]), and CopyAssignable (C++ 2014 [copyassignable]).
§ 21.4.3
c ISO/IEC 2018 – All rights reserved 176
Dxxxx
§ 21.4.4
c ISO/IEC 2018 – All rights reserved 177
Dxxxx
2 Returns: a.
class address_v4
{
public:
// 21.5.1, types:
using uint_type = uint_least32_t;
struct bytes_type;
// 21.5.2, constructors:
§ 21.5
c ISO/IEC 2018 – All rights reserved 178
Dxxxx
// assignment:
address_v4& operator=(const address_v4& a) noexcept;
// 21.5.3, members:
constexpr bool is_unspecified() const noexcept;
constexpr bool is_loopback() const noexcept;
constexpr bool is_multicast() const noexcept;
constexpr bytes_type to_bytes() const noexcept;
constexpr uint_type to_uint() const noexcept;
template<class Allocator = allocator<char>>
basic_string<char, char_traits<char>, Allocator>
to_string(const Allocator& a = Allocator()) const;
} // namespace ip
} // inline namespace v1
} // namespace net
} // namespace experimental
} // namespace std
2 address_v4 satisfies the requirements for Destructible (C++ 2014 [destructible]), CopyConstructible
§ 21.5
c ISO/IEC 2018 – All rights reserved 179
Dxxxx
} // namespace ip
} // inline namespace v1
} // namespace net
} // namespace experimental
} // namespace std
§ 21.5.3
c ISO/IEC 2018 – All rights reserved 180
Dxxxx
§ 21.5.5
c ISO/IEC 2018 – All rights reserved 181
Dxxxx
class address_v6
{
public:
// 21.6.1, types:
struct bytes_type;
§ 21.6
c ISO/IEC 2018 – All rights reserved 182
Dxxxx
// 21.6.2, constructors:
constexpr address_v6() noexcept;
constexpr address_v6(const address_v6& a) noexcept;
constexpr address_v6(const bytes_type& bytes,
scope_id_type scope = 0);
// assignment:
address_v6& operator=(const address_v6& a) noexcept;
// 21.6.3, members:
void scope_id(scope_id_type id) noexcept;
constexpr scope_id_type scope_id() const noexcept;
constexpr bool is_unspecified() const noexcept;
constexpr bool is_loopback() const noexcept;
constexpr bool is_multicast() const noexcept;
constexpr bool is_link_local() const noexcept;
constexpr bool is_site_local() const noexcept;
constexpr bool is_v4_mapped() const noexcept;
constexpr bool is_multicast_node_local() const noexcept;
constexpr bool is_multicast_link_local() const noexcept;
constexpr bool is_multicast_site_local() const noexcept;
constexpr bool is_multicast_org_local() const noexcept;
constexpr bool is_multicast_global() const noexcept;
constexpr bytes_type to_bytes() const noexcept;
template<class Allocator = allocator<char>>
basic_string<char, char_traits<char>, Allocator>
to_string(const Allocator& a = Allocator()) const;
§ 21.6
c ISO/IEC 2018 – All rights reserved 183
Dxxxx
} // namespace ip
} // inline namespace v1
} // namespace net
} // namespace experimental
} // namespace std
2 address_v6 satisfies the requirements for Destructible (C++ 2014 [destructible]), CopyConstructible
(C++ 2014 [copyconstructible]), and CopyAssignable (C++ 2014 [copyassignable]).
3 [ Note: The implementations of the functions is_unspecified, is_loopback, is_multicast, is_link_-
local, is_site_local, is_v4_mapped, is_multicast_node_local, is_multicast_link_local, is_mul-
ticast_site_local, is_multicast_org_local and is_multicast_global are determined by [RFC4291].
— end note ]
} // namespace ip
} // inline namespace v1
} // namespace net
} // namespace experimental
} // namespace std
§ 21.6.3
c ISO/IEC 2018 – All rights reserved 184
Dxxxx
§ 21.6.3
c ISO/IEC 2018 – All rights reserved 185
Dxxxx
§ 21.6.5
c ISO/IEC 2018 – All rights reserved 186
Dxxxx
§ 21.7
c ISO/IEC 2018 – All rights reserved 187
Dxxxx
// constructor:
bad_address_cast() noexcept;
};
} // namespace ip
} // inline namespace v1
} // namespace net
} // namespace experimental
} // namespace std
bad_address_cast() noexcept;
2 Effects: constructs a bad_address_cast object.
3 Postconditions: what() returns an implementation-defined ntbs.
// constructors:
basic_address_iterator(const Address & a) noexcept;
// members:
reference operator*() const noexcept;
pointer operator->() const noexcept;
basic_address_iterator& operator++() noexcept;
basic_address_iterator operator++(int) noexcept;
basic_address_iterator& operator--() noexcept;
§ 21.9
c ISO/IEC 2018 – All rights reserved 188
Dxxxx
private:
Address address_; // exposition only
};
} // namespace ip
} // inline namespace v1
} // namespace net
} // namespace experimental
} // namespace std
2 Specializations of basic_address_iterator satisfy the requirements for input iterators (C++ 2014 [in-
put.iterators]).
basic_address_iterator(const Address & a) noexcept;
3 Effects: Initializes address_ with a.
§ 21.10
c ISO/IEC 2018 – All rights reserved 189
Dxxxx
namespace std {
namespace experimental {
namespace net {
inline namespace v1 {
namespace ip {
// constructors:
basic_address_range() noexcept;
basic_address_range(const Address & first,
const Address & last) noexcept;
// members:
iterator begin() const noexcept;
iterator end() const noexcept;
bool empty() const noexcept;
size_t size() const noexcept; // not always defined
iterator find(const Address & addr) const noexcept;
};
} // namespace ip
} // inline namespace v1
} // namespace net
} // namespace experimental
} // namespace std
2 Specializations of basic_address_range satisfy the requirements for Destructible (C++ 2014 [destructible]),
CopyConstructible (C++ 2014 [copyconstructible]), and CopyAssignable (C++ 2014 [copyassignable]).
basic_address_range() noexcept;
3 Effects: Constructs an object of type basic_address_range<Address > that represents an empty range.
§ 21.10
c ISO/IEC 2018 – All rights reserved 190
Dxxxx
class network_v4
{
public:
// 21.11.1, constructors:
constexpr network_v4() noexcept;
constexpr network_v4(const address_v4& addr, int prefix_len);
constexpr network_v4(const address_v4& addr, const address_v4& mask);
// 21.11.2, members:
constexpr address_v4 address() const noexcept;
constexpr int prefix_length() const noexcept;
constexpr address_v4 netmask() const noexcept;
constexpr address_v4 network() const noexcept;
constexpr address_v4 broadcast() const noexcept;
address_v4_range hosts() const noexcept;
constexpr network_v4 canonical() const noexcept;
constexpr bool is_host() const noexcept;
constexpr bool is_subnet_of(const network_v4& other) const noexcept;
template<class Allocator = allocator<char>>
basic_string<char, char_traits<char>, Allocator>
to_string(const Allocator& a = Allocator()) const;
};
§ 21.11
c ISO/IEC 2018 – All rights reserved 191
Dxxxx
} // namespace ip
} // inline namespace v1
} // namespace net
} // namespace experimental
} // namespace std
2 network_v4 satisfies the requirements for Destructible (C++ 2014 [destructible]), CopyConstructible
(C++ 2014 [copyconstructible]), and CopyAssignable (C++ 2014 [copyassignable]).
§ 21.11.2
c ISO/IEC 2018 – All rights reserved 192
Dxxxx
§ 21.11.4
c ISO/IEC 2018 – All rights reserved 193
Dxxxx
3 Returns: If str contains a value of the form address ’/’ prefix-length, a network_v4 object constructed
with the result of applying make_address_v4() to the address portion of the string, and the result of
converting prefix-length to an integer of type int. Otherwise returns network_v4() and sets ec to
reflect the error.
4 Error conditions:
(4.1) — errc::invalid_argument — if str is not a valid textual representation of an IPv4 address and
prefix length.
class network_v6
{
public:
// 21.12.1, constructors:
constexpr network_v6() noexcept;
constexpr network_v6(const address_v6& addr, int prefix_len);
// 21.12.2, members:
constexpr address_v6 address() const noexcept;
constexpr int prefix_length() const noexcept;
constexpr address_v6 network() const noexcept;
address_v6_range hosts() const noexcept;
constexpr network_v6 canonical() const noexcept;
constexpr bool is_host() const noexcept;
constexpr bool is_subnet_of(const network_v6& other) const noexcept;
template<class Allocator = allocator<char>>
basic_string<char, char_traits<char>, Allocator>
to_string(const Allocator& a = Allocator()) const;
};
§ 21.12
c ISO/IEC 2018 – All rights reserved 194
Dxxxx
} // namespace ip
} // inline namespace v1
} // namespace net
} // namespace experimental
} // namespace std
2 network_v6 satisfies the requirements for Destructible (C++ 2014 [destructible]), CopyConstructible
(C++ 2014 [copyconstructible]), and CopyAssignable (C++ 2014 [copyassignable]).
§ 21.12.2
c ISO/IEC 2018 – All rights reserved 195
Dxxxx
§ 21.13
c ISO/IEC 2018 – All rights reserved 196
Dxxxx
namespace std {
namespace experimental {
namespace net {
inline namespace v1 {
namespace ip {
template<class InternetProtocol>
class basic_endpoint
{
public:
// types:
using protocol_type = InternetProtocol;
// 21.13.1, constructors:
constexpr basic_endpoint() noexcept;
constexpr basic_endpoint(const protocol_type& proto,
port_type port_num) noexcept;
constexpr basic_endpoint(const ip::address& addr,
port_type port_num) noexcept;
// 21.13.2, members:
constexpr protocol_type protocol() const noexcept;
constexpr ip::address address() const noexcept;
void address(const ip::address& addr) noexcept;
constexpr port_type port() const noexcept;
void port(port_type port_num) noexcept;
};
} // namespace ip
§ 21.13
c ISO/IEC 2018 – All rights reserved 197
Dxxxx
} // inline namespace v1
} // namespace net
} // namespace experimental
} // namespace std
2 Instances of the basic_endpoint class template meet the requirements for an Endpoint (18.2.4).
3 Extensible implementations provide the following member functions:
namespace std {
namespace experimental {
namespace net {
inline namespace v1 {
namespace ip {
template<class InternetProtocol>
class basic_endpoint
{
public:
void* data() noexcept;
const void* data() const noexcept;
constexpr size_t size() const noexcept;
void resize(size_t s);
constexpr size_t capacity() const noexcept;
// remainder unchanged
private:
union
{
sockaddr_in v4_;
sockaddr_in6 v6_;
} data_; // exposition only
};
} // namespace ip
} // inline namespace v1
} // namespace net
} // namespace experimental
} // namespace std
§ 21.13.1
c ISO/IEC 2018 – All rights reserved 198
Dxxxx
template<class InternetProtocol>
constexpr bool operator!=(const basic_endpoint<InternetProtocol>& a,
const basic_endpoint<InternetProtocol>& b) noexcept;
2 Returns: !(a == b).
template<class InternetProtocol>
constexpr bool operator< (const basic_endpoint<InternetProtocol>& a,
const basic_endpoint<InternetProtocol>& b) noexcept;
3 Returns: tie(a.address(), a.port()) < tie(b.address(), b.port()).
template<class InternetProtocol>
constexpr bool operator> (const basic_endpoint<InternetProtocol>& a,
const basic_endpoint<InternetProtocol>& b) noexcept;
4 Returns: b < a.
template<class InternetProtocol>
constexpr bool operator<=(const basic_endpoint<InternetProtocol>& a,
const basic_endpoint<InternetProtocol>& b) noexcept;
5 Returns: !(b < a).
template<class InternetProtocol>
constexpr bool operator>=(const basic_endpoint<InternetProtocol>& a,
const basic_endpoint<InternetProtocol>& b) noexcept;
6 Returns: !(a < b).
§ 21.13.3
c ISO/IEC 2018 – All rights reserved 199
Dxxxx
2 Returns: os.
3 [ Note: The representation of the endpoint when it contains an IP version 6 address is based on [RFC2732].
— end note ]
§ 21.14
c ISO/IEC 2018 – All rights reserved 200
Dxxxx
template<class InternetProtocol>
class basic_resolver_entry
{
public:
// types:
using protocol_type = InternetProtocol;
using endpoint_type = typename InternetProtocol::endpoint;
// 21.14.1, constructors:
basic_resolver_entry();
basic_resolver_entry(const endpoint_type& ep,
string_view h,
string_view s);
// 21.14.2, members:
endpoint_type endpoint() const;
operator endpoint_type() const;
template<class Allocator = allocator<char>>
basic_string<char, char_traits<char>, Allocator>
host_name(const Allocator& a = Allocator()) const;
template<class Allocator = allocator<char>>
basic_string<char, char_traits<char>, Allocator>
service_name(const Allocator& a = Allocator()) const;
};
} // namespace ip
} // inline namespace v1
} // namespace net
} // namespace experimental
} // namespace std
§ 21.14.1
c ISO/IEC 2018 – All rights reserved 201
Dxxxx
template<class InternetProtocol>
bool operator!=(const basic_resolver_entry<InternetProtocol>& a,
const basic_resolver_entry<InternetProtocol>& b);
2 Returns: !(a == b).
template<class InternetProtocol>
class basic_resolver_results
{
public:
// types:
using protocol_type = InternetProtocol;
using endpoint_type = typename protocol_type::endpoint;
using value_type = basic_resolver_entry<protocol_type>;
using const_reference = const value_type&;
§ 21.15
c ISO/IEC 2018 – All rights reserved 202
Dxxxx
// 21.15.5, swap:
void swap(basic_resolver_results& that) noexcept;
};
} // namespace ip
} // inline namespace v1
} // namespace net
} // namespace experimental
} // namespace std
2 The class template basic_resolver_results satisfies the requirements of a sequence container (C++ 2014
[sequence.reqmts]), except that only the operations defined for const-qualified sequence containers are
supported. The class template basic_resolver_results supports forward iterators.
3 A default-constructed basic_resolver_results object is empty. A non-empty results object is obtained
only by calling a basic_resolver object’s wait or async_wait operations, or otherwise by copy construction,
move construction, assignment, or swap from another non-empty results object.
§ 21.15.1
c ISO/IEC 2018 – All rights reserved 203
Dxxxx
§ 21.15.5
c ISO/IEC 2018 – All rights reserved 204
Dxxxx
template<class InternetProtocol>
bool operator!=(const basic_resolver_results<InternetProtocol>& a,
const basic_resolver_results<InternetProtocol>& b);
2 Returns: !(a == b).
class resolver_base
{
public:
using flags = T1 ;
static const flags passive;
static const flags canonical_name;
static const flags numeric_host;
static const flags numeric_service;
static const flags v4_mapped;
static const flags all_matching;
static const flags address_configured;
protected:
resolver_base();
~resolver_base();
};
} // namespace ip
} // inline namespace v1
} // namespace net
} // namespace experimental
} // namespace std
1 resolver_base defines a bitmask type, flags, with the bitmask elements shown in Table 37.
§ 21.16
c ISO/IEC 2018 – All rights reserved 205
Dxxxx
template<class InternetProtocol>
class basic_resolver : public resolver_base
{
public:
// types:
~basic_resolver();
basic_resolver& operator=(const basic_resolver&) = delete;
basic_resolver& operator=(basic_resolver&& rhs);
§ 21.17
c ISO/IEC 2018 – All rights reserved 206
Dxxxx
void cancel();
template<class CompletionToken>
DEDUCED async_resolve(string_view host_name, string_view service_name,
CompletionToken&& token);
template<class CompletionToken>
DEDUCED async_resolve(string_view host_name, string_view service_name,
flags f, CompletionToken&& token);
template<class CompletionToken>
DEDUCED async_resolve(const protocol_type& protocol,
string_view host_name, string_view service_name,
CompletionToken&& token);
template<class CompletionToken>
DEDUCED async_resolve(const protocol_type& protocol,
string_view host_name, string_view service_name,
flags f, CompletionToken&& token);
template<class CompletionToken>
DEDUCED async_resolve(const endpoint_type& e,
CompletionToken&& token);
};
} // namespace ip
} // inline namespace v1
} // namespace net
} // namespace experimental
} // namespace std
§ 21.17
c ISO/IEC 2018 – All rights reserved 207
Dxxxx
void cancel();
2 Effects: Cancels all outstanding asynchronous resolve operations associated with *this. Completion
handlers for canceled operations are passed an error code ec such that ec == errc::operation_-
canceled yields true.
3 Remarks: Does not block (C++ 2014 [defns.block]) the calling thread pending completion of the canceled
operations.
§ 21.17.4
c ISO/IEC 2018 – All rights reserved 208
Dxxxx
addrinfo hints;
hints.ai_flags = static_cast<int>(f);
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = endpoint_type().protocol().type();
hints.ai_protocol = endpoint_type().protocol().protocol();
hints.ai_addr = nullptr;
hints.ai_addrlen = 0;
hints.ai_canonname = nullptr;
hints.ai_next = nullptr;
addrinfo* result = nullptr;
getaddrinfo(H, S, &hints, &result);
6 Returns: On success, a non-empty results object containing the results of the resolve operation.
Otherwise results_type().
template<class CompletionToken>
DEDUCED async_resolve(string_view host_name, string_view service_name,
CompletionToken&& token);
7 Returns:
async_resolve(host_name, service_name, resolver_base::flags(),
forward<CompletionToken>(token))
template<class CompletionToken>
DEDUCED async_resolve(string_view host_name, string_view service_name,
flags f, CompletionToken&& token);
8 Completion signature: void(error_code ec, results_type r).
9 Effects: If host_name.data() != nullptr, let H be an ntbs constructed from host_name; otherwise,
let H be nullptr. If service_name.data() != nullptr, let S be an ntbs constructed from service_-
name; otherwise, let S be nullptr. Initiates an asynchronous operation to resolve a host name and
service name, as if by POSIX:
addrinfo hints;
hints.ai_flags = static_cast<int>(f);
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = endpoint_type().protocol().type();
hints.ai_protocol = endpoint_type().protocol().protocol();
hints.ai_addr = nullptr;
hints.ai_addrlen = 0;
hints.ai_canonname = nullptr;
hints.ai_next = nullptr;
addrinfo* result = nullptr;
getaddrinfo(H, S, &hints, &result);
On success, r is a non-empty results object containing the results of the resolve operation. Otherwise,
r is results_type().
§ 21.17.4
c ISO/IEC 2018 – All rights reserved 209
Dxxxx
12 Returns: On success, a non-empty results object containing the results of the resolve operation.
Otherwise results_type().
template<class CompletionToken>
DEDUCED async_resolve(const protocol_type& protocol,
string_view host_name, string_view service_name,
CompletionToken&& token);
13 Returns:
async_resolve(protocol, host_name, service_name, resolver_base::flags(),
forward<CompletionToken>(token))
template<class CompletionToken>
DEDUCED async_resolve(const protocol& protocol,
string_view host_name, string_view service_name,
flags f, CompletionToken&& token);
14 Completion signature: void(error_code ec, results_type r).
15 Effects: If host_name.data() != nullptr, let H be an ntbs constructed from host_name; otherwise,
let H be nullptr. If service_name.data() != nullptr, let S be an ntbs constructed from service_-
name; otherwise, let S be nullptr. Initiates an asynchronous operation to resolve a host name and
service name, as if by POSIX:
addrinfo hints;
hints.ai_flags = static_cast<int>(f);
hints.ai_family = protocol.family();
hints.ai_socktype = protocol.type();
hints.ai_protocol = protocol.protocol();
hints.ai_addr = nullptr;
hints.ai_addrlen = 0;
hints.ai_canonname = nullptr;
hints.ai_next = nullptr;
addrinfo* result = nullptr;
getaddrinfo(H, S, &hints, &result);
§ 21.17.4
c ISO/IEC 2018 – All rights reserved 210
Dxxxx
On success, r is a non-empty results object containing the results of the resolve operation. Otherwise,
r is results_type().
17 Returns: On success, a results object with size() == 1 containing the results of the resolve operation.
Otherwise results_type().
template<class CompletionToken>
DEDUCED async_resolve(const endpoint_type& e,
CompletionToken&& token);
18 Completion signature: void(error_code ec, results_type r).
19 Effects: Let S1 and S2 be implementation-defined values that are sufficiently large to hold the host
name and service name respectively. Initiates an asynchronous operation to resolve an endpoint as if
by POSIX:
char host_name[S1];
char service_name[S2];
int flags = 0;
if (endpoint_type().protocol().type() == SOCK_DGRAM)
flags |= NI_DGRAM;
int result = getnameinfo((const sockaddr*)e.data(), e.size(),
host_name, S1,
service_name, S2,
flags);
if (result != 0)
{
flags |= NI_NUMERICSERV;
result = getnameinfo((const sockaddr*)e.data(), e.size(),
host_name, S1,
service_name, S2,
flags);
}
§ 21.17.4
c ISO/IEC 2018 – All rights reserved 211
Dxxxx
On success, r is a results object with size() == 1 containing the results of the resolve operation;
otherwise, r is results_type().
class tcp
{
public:
// types:
using endpoint = basic_endpoint<tcp>;
using resolver = basic_resolver<tcp>;
using socket = basic_stream_socket<tcp>;
using acceptor = basic_socket_acceptor<tcp>;
using iostream = basic_socket_iostream<tcp>;
class no_delay;
// static members:
static constexpr tcp v4() noexcept;
static constexpr tcp v6() noexcept;
tcp() = delete;
};
} // namespace ip
} // inline namespace v1
} // namespace net
} // namespace experimental
} // namespace std
§ 21.19
c ISO/IEC 2018 – All rights reserved 212
Dxxxx
class tcp
{
public:
constexpr int family() const noexcept;
constexpr int type() const noexcept;
constexpr int protocol() const noexcept;
// remainder unchanged
};
} // namespace ip
} // inline namespace v1
} // namespace net
} // namespace experimental
} // namespace std
4 The return values for these member functions are listed in Table 38.
5 [ Note: The constants AF_INET, AF_INET6 and SOCK_STREAM are defined in the POSIX <sys/socket.h>
header. The constant IPPROTO_TCP is defined in the POSIX <netinet/in.h> header. — end note ]
§ 21.20
c ISO/IEC 2018 – All rights reserved 213
Dxxxx
class udp
{
public:
// types:
using endpoint = basic_endpoint<udp>;
using resolver = basic_resolver<udp>;
using socket = basic_datagram_socket<udp>;
// static members:
static constexpr udp v4() noexcept;
static constexpr udp v6() noexcept;
udp() = delete;
};
} // namespace ip
} // inline namespace v1
} // namespace net
} // namespace experimental
} // namespace std
class udp
{
public:
constexpr int family() const noexcept;
constexpr int type() const noexcept;
constexpr int protocol() const noexcept;
// remainder unchanged
};
} // namespace ip
} // inline namespace v1
} // namespace net
} // namespace experimental
} // namespace std
4 The return values for these member functions are listed in Table 39.
§ 21.20
c ISO/IEC 2018 – All rights reserved 214
Dxxxx
5 [ Note: The constants AF_INET, AF_INET6 and SOCK_DGRAM are defined in the POSIX <sys/socket.h> header.
The constant IPPROTO_UDP is defined in the POSIX <netinet/in.h> header. — end note ]
C L N T Requirements,
definition or notes
ip::tcp:: IPPROTO_TCP TCP_NODELAY int Satisfies the
no_delay BooleanSocket-
Option (18.2.10) type
requirements.
Determines whether a
TCP socket will avoid
coalescing of small
segments. [ Note:
That is, setting this
option disables the
Nagle algorithm.
— end note ]
§ 21.21
c ISO/IEC 2018 – All rights reserved 215
Dxxxx
C L N T Requirements,
definition or notes
ip::v6_only IPPROTO_IPV6 IPV6_V6ONLY int Satisfies the
BooleanSocket-
Option (18.2.10) type
requirements.
Determines whether a
socket created for an
IPv6 protocol is
restricted to IPv6
communications only.
Implementations are
not required to
support setting the
v6_only option to
false, and the initial
value of the v6_only
option for a socket is
implementation-
defined. [ Note: As not
all operating systems
support dual stack IP
networking. Some
operating systems that
do provide dual stack
support offer a
configuration option to
disable it or to set the
initial value of the
v6_only socket option.
— end note ]
ip::unicast:: IPPROTO_IPV6 if F IPV6_UNICAST_- int Satisfies the
hops == AF_INET6, HOPS if F == IntegerSocket-
otherwise AF_INET6, Option (18.2.11) type
IPPROTO_IP otherwise IP_TTL requirements. Specifies
the default number of
hops (also known as
time-to-live or TTL)
on outbound
datagrams. The
constructor and
assignment operator
for the
ip::unicast::hops
class throw
out_of_range if the
int argument is not in
the range [0, 255].
§ 21.21
c ISO/IEC 2018 – All rights reserved 216
Dxxxx
C L N T Requirements,
definition or notes
ip::multicast:: IPPROTO_IPV6 if F IPV6_JOIN_GROUP ipv6_mreq if F Satisfies the
join_group == AF_INET6, if F == AF_INET6, == AF_INET6, MulticastGroupSock-
otherwise otherwise IP_- otherwise etOption (21.2.2)
IPPROTO_IP ADD_MEMBERSHIP ip_mreq type requirements.
Requests that the
socket join the
specified multicast
group.
ip::multicast:: IPPROTO_IPV6 if F IPV6_LEAVE_- ipv6_mreq if F Satisfies the
leave_group == AF_INET6, GROUP if F == == AF_INET6, MulticastGroupSock-
otherwise AF_INET6, otherwise etOption (21.2.2)
IPPROTO_IP otherwise IP_- ip_mreq type requirements.
DROP_MEMBERSHIP Requests that the
socket leave the
specified multicast
group.
ip::multicast:: IPPROTO_IPV6 if F IPV6_- unsigned int if Specifies the network
outbound_- == AF_INET6, MULTICAST_IF if F == AF_INET6, interface to use for
interface otherwise F == AF_INET6, otherwise outgoing multicast
(21.21.1) IPPROTO_IP otherwise in_addr datagrams.
IP_MULTICAST_IF
ip::multicast:: IPPROTO_IPV6 if F IPV6_- int Satisfies the
hops == AF_INET6, MULTICAST_HOPS IntegerSocket-
otherwise if F == AF_INET6, Option (18.2.11) type
IPPROTO_IP otherwise IP_- requirements. Specifies
MULTICAST_TTL the default number of
hops (also known as
time-to-live or TTL)
on outbound
datagrams. The
constructor and
assignment operator
for the
ip::multicast::hops
class throw
out_of_range if the
int argument is not in
the range [0, 255].
ip::multicast:: IPPROTO_IPV6 if F IPV6_- int Satisfies the
enable_- == AF_INET6, MULTICAST_LOOP BooleanSocket-
loopback otherwise if F == AF_INET6, Option (18.2.10) type
IPPROTO_IP otherwise IP_- requirements.
MULTICAST_LOOP Determines whether
multicast datagrams
are delivered back to
the local application.
§ 21.21
c ISO/IEC 2018 – All rights reserved 217
Dxxxx
class outbound_interface
{
public:
// constructors:
explicit outbound_interface(const address_v4& network_interface) noexcept;
explicit outbound_interface(unsigned int network_interface) noexcept;
};
} // namespace multicast
} // namespace ip
} // inline namespace v1
} // namespace net
} // namespace experimental
} // namespace std
2 outbound_interface satisfies the requirements for Destructible (C++ 2014 [destructible]), CopyConstructible
(C++ 2014 [copyconstructible]), CopyAssignable (C++ 2014 [copyassignable]), and SettableSocketOption (18.2.9).
3 Extensible implementations provide the following member functions:
namespace std {
namespace experimental {
namespace net {
inline namespace v1 {
namespace ip {
namespace multicast {
class outbound_interface
{
public:
template<class Protocol> int level(const Protocol& p) const noexcept;
template<class Protocol> int name(const Protocol& p) const noexcept;
template<class Protocol> const void* data(const Protocol& p) const noexcept;
template<class Protocol> size_t size(const Protocol& p) const noexcept;
// remainder unchanged
private:
in_addr v4_value_; // exposition only
unsigned int v6_value_; // exposition only
};
} // namespace multicast
} // namespace ip
} // inline namespace v1
} // namespace net
} // namespace experimental
§ 21.21.1
c ISO/IEC 2018 – All rights reserved 218
Dxxxx
} // namespace std
§ 21.21.1
c ISO/IEC 2018 – All rights reserved 219
Dxxxx
Index
Acceptable, 110 MulticastGroupSocketOption, 173
associated executor, 26 outbound_interface, 218
associated_allocator Protocol, 110
specialization for executor_binder, 39 tcp, 213
associated_executor udp, 214
specialization for executor_binder, 40
associator, 23 GettableSocketOption, 111
async_result
specialization for executor_binder, 38 host byte order, 3
specialization for packaged_task, 60
initiating function, 24
specialization for use_future_t, 58
deduction of return type, 25
asynchronous operation, 3, 82
lifetime of arguments, 25
asynchronous socket operations, 108
non-blocking requirements, 26
asynchronous wait operation, 71
production of return value, 25
AsyncReadStream, 93
IntegerSocketOption, 114
AsyncWriteStream, 94
InternetProtocol, 172
basic_endpoint IoControlCommand, 116
extensible implementation, 198
linger
BooleanSocketOption, 112
extensible implementation, 121
extensible implementation, 113, 115
MulticastGroupSocketOption, 173
completion handler, 24
extensible implementation, 173
completion signature, 24
mutable buffer sequence, 78
completion token, 24
CompletionCondition, 95 native handles, 108
composed asynchronous operation, 27 network byte order, 3
ConnectCondition, 116
constant buffer sequence, 79 orderly shutdown, 93
outbound_interface
definitions, 3 extensible implementation, 218
dynamic buffer, 80 outstanding work, 26, 62
Endpoint, 108 Protocol, 110
extensible implementation, 109 extensible implementation, 110
EndpointSequence, 109
error codes read operation, 82
resolver, 174 requirements
socket, 116 associated_allocator specializations, 30
stream, 82 associated_executor specializations, 35
ExecutionContext, 22 associator, 23
extensible implementation async_result specializations, 28
basic_endpoint, 198 AsyncReadStream, 93
BooleanSocketOption, 113, 115 AsyncWriteStream, 94
Endpoint, 109 CompletionCondition, 95
linger, 121 ConnectCondition, 116
Index
c ISO/IEC 2018 – All rights reserved 220
Dxxxx
ConstBufferSequence, 79
DynamicBuffer, 81
ExecutionContext, 22
InternetProtocol, 172
IoControlCommand, 116
MulticastGroupSocketOption, 173
MutableBufferSequence, 78
signature, 23
SyncReadStream, 93
SyncWriteStream, 94
WaitTraits, 68
run functions, 62
service, 22
SettableSocketOption, 112
signature requirements, 23
socket operations
asynchronous, 108
synchronous, 107
socket options, 119
synchronous operation, 3
synchronous socket operations, 107
SyncReadStream, 93
SyncWriteStream, 94
target
executor, 47
tcp
extensible implementation, 213
udp
extensible implementation, 214
uses-executor construction, 35
write operation, 82
Index
c ISO/IEC 2018 – All rights reserved 221
Dxxxx
on_work_started, 48 has_service, 33
operator bool, 49 host_name, 212
operator!=, 49
operator=, 47, 48 io_context, 61
operator==, 49 constructor, 62
post, 49 count_type, 62
swap, 48, 50 get_executor, 62
target, 49 poll, 64
target_type, 49 poll_one, 64
executor_arg, 34 restart, 64
executor_arg_t, 34 run, 62
executor_binder, 36 run_for, 63
constructor, 37 run_one, 63
get, 38 run_one_for, 63
get_executor, 38 run_one_until, 63
operator(), 38 run_until, 63
executor_work_guard, 40 stop, 64
constructor, 41 stopped, 64
destructor, 41 io_context::executor_type, 65
get_executor, 41 constructor, 65
owns_work, 42 context, 66
reset, 42 defer, 66
<experimental/buffer>, 73 dispatch, 66
<experimental/executor>, 16 on_work_finished, 66
<experimental/internet>, 168 on_work_started, 66
<experimental/io_context>, 61 operator!=, 66
<experimental/net>, 13 operator=, 66
<experimental/netfwd>, 14 operator==, 66
<experimental/socket>, 105 post, 66
<experimental/timer>, 67 running_in_this_thread, 66
expires_after is_const_buffer_sequence, 84
basic_waitable_timer, 71 is_const_buffer_sequence_v, 73
expires_at is_dynamic_buffer, 84
basic_waitable_timer, 71 is_dynamic_buffer_v, 73
expiry is_executor, 34
basic_waitable_timer, 71 is_executor_v, 16
is_link_local
get address_v6, 185
executor_binder, 38 is_loopback
get_allocator address, 177
use_future_t, 57 address_v4, 180
get_associated_allocator, 30 address_v6, 185
get_associated_executor, 36 is_multicast
get_executor, 93, 94 address, 177
basic_waitable_timer, 71 address_v4, 180
executor_binder, 38 address_v6, 185
executor_work_guard, 41 is_multicast_global
io_context, 62 address_v6, 186
system_context, 44 is_multicast_link_local
get_inner_executor address_v6, 185
strand, 56 is_multicast_node_local
system_executor, 43 io_context, 63
operator> run_until
address, 177 io_context, 63
address_v4, 181 running_in_this_thread
address_v6, 186 io_context::executor_type, 66
operator>= strand, 56
address, 178
address_v4, 181 scope_id
address_v6, 186 address_v6, 184
outbound_interface, 218 scope_id_type, 168
owns_work shutdown
executor_work_guard, 42 execution_context, 32
size
poll const_buffer, 84
io_context, 64 dynamic_string_buffer, 91
poll_one dynamic_vector_buffer, 89
io_context, 64 mutable_buffer, 83
port_type, 168 socket_base, 117
post, 51 socket_category, 116
executor, 49 socket_errc, 105
io_context::executor_type, 66 make_error_code, 117
strand, 56 make_error_condition, 117
system_executor, 43 stop
prepare io_context, 64
dynamic_string_buffer, 91 system_context, 44
dynamic_vector_buffer, 89 stopped
io_context, 64
read, 97, 98 system_context, 45
read_some, 93 strand, 53
read_until, 103 constructor, 54
rebind context, 56
use_future_t, 57 defer, 56
reset destructor, 56
executor_work_guard, 42 dispatch, 56
resolve_base, 205 get_inner_executor, 56
resolver_base, 205 on_work_finished, 56
resolver_category, 174 on_work_started, 56
resolver_errc, 168 operator!=, 57
make_error_code, 175 operator=, 55
make_error_condition, 175 operator==, 57
restart post, 56
io_context, 64 running_in_this_thread, 56
run stream_category, 82
io_context, 62 stream_errc, 73
run_for make_error_code, 82
io_context, 63 make_error_condition, 82
run_one swap
io_context, 63 executor, 48, 50
run_one_for system_context, 44
io_context, 63 destructor, 44
run_one_until get_executor, 44
target
executor, 49
target_type
executor, 49
tcp, 212
to_bytes
address_v4, 181
address_v6, 186
to_string
address, 177
address_v4, 181
address_v6, 186
to_uint
address_v4, 181
to_v4
address, 177
to_v6
address, 177
to_wait_duration
wait_traits, 68, 69
transfer_all, 95
transfer_at_least, 96
transfer_exactly, 96
udp, 213
use_future_t, 57
constructor, 57
get_allocator, 57
operator(), 58
rebind, 57
use_service, 32
uses_executor, 34
uses_executor_v, 16
v4_mapped, 168
v4_mapped_t, 168
wait
basic_waitable_timer, 71
wait_traits, 68