18 Sockets [socket]

18.6 Class template basic_socket [socket.basic]

18.6.1 basic_socket constructors [socket.basic.cons]

explicit basic_socket(io_context& ctx);

Postconditions:

  • get_executor() == ctx.get_executor().

  • is_open() == false.

basic_socket(io_context& ctx, const protocol_type& protocol);

Effects: Opens this socket as if by calling open(protocol).

Postconditions:

  • get_executor() == ctx.get_executor().

  • is_open() == true.

  • non_blocking() == false.

  • protocol_ == protocol.

basic_socket(io_context& ctx, const endpoint_type& endpoint);

Effects: Opens and binds this socket as if by calling:

open(endpoint.protocol());
bind(endpoint);

Postconditions:

  • get_executor() == ctx.get_executor().

  • is_open() == true.

  • non_blocking() == false.

  • protocol_ == endpoint.protocol().

basic_socket(io_context& ctx, const protocol_type& protocol, const native_handle_type& native_socket);

Requires: native_socket is a native handle to an open socket.

Effects: Assigns the existing native socket into this socket as if by calling assign(protocol, native_socket).

Postconditions:

  • get_executor() == ctx.get_executor().

  • is_open() == true.

  • non_blocking() == false.

  • protocol_ == protocol.

basic_socket(basic_socket&& rhs);

Effects: Move constructs an object of class basic_socket<Protocol> that refers to the state originally represented by rhs.

Postconditions:

  • get_executor() == rhs.get_executor().

  • is_open() returns the same value as rhs.is_open() prior to the constructor invocation.

  • non_blocking() returns the same value as rhs.non_blocking() prior to the constructor invocation.

  • native_handle() returns the prior value of rhs.native_handle().

  • protocol_ is the prior value of rhs.protocol_.

  • rhs.is_open() == false.

template<class OtherProtocol> basic_socket(basic_socket<OtherProtocol>&& rhs);

Requires: OtherProtocol is implicitly convertible to Protocol.

Effects: Move constructs an object of class basic_socket<Protocol> that refers to the state originally represented by rhs.

Postconditions:

  • get_executor() == rhs.get_executor().

  • is_open() returns the same value as rhs.is_open() prior to the constructor invocation.

  • non_blocking() returns the same value as rhs.non_blocking() prior to the constructor invocation.

  • native_handle() returns the prior value of rhs.native_handle().

  • protocol_ is the result of converting the prior value of rhs.protocol_.

  • rhs.is_open() == false.

Remarks: This constructor shall not participate in overload resolution unless OtherProtocol is implicitly convertible to Protocol.