The class template basic_socket_iostream<Protocol, Clock, WaitTraits> supports reading and writing on sockets. It uses a basic_socket_streambuf<Protocol, Clock, WaitTraits> object to control the associated sequences.
[ Note: This class is intended for sending and receiving bytes, not characters. Any conversion from characters to bytes, and vice versa, occurs elsewhere. — end note ]
namespace std { namespace experimental { namespace net { inline namespace v1 { template<class Protocol, class Clock, class WaitTraits> class basic_socket_iostream : public basic_iostream<char> { public: // types: using protocol_type = Protocol; using endpoint_type = typename protocol_type::endpoint; using clock_type = Clock; using time_point = typename clock_type::time_point; using duration = typename clock_type::duration; using wait_traits_type = WaitTraits; // [socket.iostream.cons], construct / copy / destroy: basic_socket_iostream(); explicit basic_socket_iostream(basic_stream_socket<protocol_type> s); basic_socket_iostream(const basic_socket_iostream&) = delete; basic_socket_iostream(basic_socket_iostream&& rhs); template<class... Args> explicit basic_socket_iostream(Args&&... args); basic_socket_iostream& operator=(const basic_socket_iostream&) = delete; basic_socket_iostream& operator=(basic_socket_iostream&& rhs); // [socket.iostream.members], members: template<class... Args> void connect(Args&&... args); void close(); basic_socket_streambuf<protocol_type, clock_type, wait_traits_type>* rdbuf() const; basic_socket<protocol_type>& socket(); error_code error() const; time_point expiry() const; void expires_at(const time_point& t); void expires_after(const duration& d); private: basic_socket_streambuf<protocol_type, clock_type, wait_traits_type> sb_; // exposition only }; } // inline namespace v1 } // namespace net } // namespace experimental } // namespace std
Instances of class template basic_socket_iostream meet the requirements of Destructible (C++ 2014 [destructible]), MoveConstructible (C++ 2014 [moveconstructible]), and MoveAssignable (C++ 2014 [moveassignable]).
basic_socket_iostream();
Effects: Initializes the base class as basic_iostream<char>(&sb_), value-initializes sb_, and performs setf(std::ios_base::unitbuf).
explicit basic_socket_iostream(basic_stream_socket<protocol_type> s);
Effects: Initializes the base class as basic_iostream<char>(&sb_), initializes sb_ with std::move(s), and performs setf(std::ios_base::unitbuf).
basic_socket_iostream(basic_socket_iostream&& rhs);
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);
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).
basic_socket_iostream& operator=(basic_socket_iostream&& rhs);
Effects: Move assigns the base and members of *this from the base and corresponding members of rhs.
Returns: *this.
template<class... Args>
void connect(Args&&... args);
Effects: Calls rdbuf()->connect(forward<Args>(args)...). If that function returns a null pointer, calls setstate(failbit) (which may throw ios_base::failure).
void close();
Effects: Calls rdbuf()->close(). If that function returns a null pointer, calls setstate(failbit) (which may throw ios_base::failure).
basic_socket_streambuf<protocol_type, clock_type, wait_traits_type>* rdbuf() const;
Let SB be the type basic_socket_streambuf<protocol_type, clock_type, wait_traits_type>.
Returns: const_cast<SB*>(addressof(sb_)).
basic_socket<protocol_type>& socket();
Returns: rdbuf()->socket().
error_code error() const;
Returns: rdbuf()->error().
time_point expiry() const;
Returns: rdbuf()->expiry().
void expires_at(const time_point& t);
Effects: Equivalent to rdbuf()->expires_at(t).
void expires_after(const duration& d);
Effects: Equivalent to rdbuf()->expires_after(d).