19 Socket iostreams [socket.iostreams]

19.1 Class template basic_socket_streambuf [socket.streambuf]

19.1.2 basic_socket_streambuf members [socket.streambuf.members]

basic_socket_streambuf* connect(const endpoint_type& e);

Effects: Initializes the basic_socket_streambuf as required, closes and re-opens the socket by performing socket_.close(ec_) and socket_.open(e.protocol(), ec_), then attempts to establish a connection 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.

Returns: if !ec_, this; otherwise, a null pointer.

template<class... Args> basic_socket_streambuf* connect(Args&&... args);

Effects: Initializes the basic_socket_streambuf as required and closes the socket as if by calling 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 connection 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.

Returns: if !ec_, this; otherwise, a null pointer.

Remarks: This function shall not participate in overload resolution unless Protocol meets the requirements for an internet protocol ([internet.reqmts.protocol]).

basic_socket_streambuf* close();

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.

Returns: this on success, a null pointer otherwise.

Postconditions: is_open() == false.

basic_socket<protocol_type>& socket();

Returns: socket_.

error_code error() const;

Returns: ec_.

time_point expiry() const;

Returns: expiry_.

void expires_at(const time_point& t);

Postconditions: expiry_ == t.

void expires_after(const duration& d);

Effects: Equivalent to expires_at(clock_type::now() + d).