19 Socket iostreams [socket.iostreams]

19.1 Class template basic_socket_streambuf [socket.streambuf]

19.1.3 basic_socket_streambuf overridden virtual functions [socket.streambuf.virt]

virtual int_type underflow() override;

Effects: Behaves according to the description of basic_streambuf<char>::underflow(), with the specialization that a sequence of characters is read from the input sequence as if by POSIX recvmsg, and 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: traits_type::to_int_type(*gptr()) to indicate success, and traits_type::eof() to indicate failure.

virtual int_type pbackfail(int_type c = traits_type::eof()) override;

Effects: Puts back the character designated by c to the input sequence, if possible, in one of three ways:

  • If traits_type::eq_int_type(c, traits_type::eof()) returns false, and if the function makes a putback position available, and if traits_type::eq(traits_type::to_char_type(c), gptr()[-1]) returns true, decrements the next pointer for the input sequence, gptr().

    Returns: c.

  • If traits_type::eq_int_type(c, traits_type::eof()) returns false, and if the function makes a putback position available, and if the function is permitted to assign to the putback position, decrements the next pointer for the input sequence, and stores c there.

    Returns: c.

  • If traits_type::eq_int_type(c, traits_type::eof()) returns true, and if either the input sequence has a putback position available or the function makes a putback position available, decrements the next pointer for the input sequence, gptr().

    Returns: traits_type::not_eof(c).

Returns: As specified above, or traits_type::eof() to indicate failure.

Remarks: The function does not put back a character directly to the input sequence. If the function can succeed in more than one of these ways, it is unspecified which way is chosen. The function can alter the number of putback positions available as a result of any call.

virtual int_type overflow(int_type c = traits_type::eof()) override;

Effects: Behaves according to the description of basic_streambuf<char>::overflow(c), except that the behavior of “consuming characters” is performed by output of the characters to the socket as if by one or more calls to POSIX sendmsg, and 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: traits_type::not_eof(c) to indicate success, and traits_type::eof() to indicate failure.

virtual int sync() override;

Effects: If a put area exists, calls overflow(traits_type::eof()) to flush characters.

virtual streambuf* setbuf(char_type* s, streamsize n) override;

Effects: If setbuf(nullptr, 0) is called on a stream before any I/O has occurred on that stream, the stream becomes unbuffered. Otherwise the results are unspecified. “Unbuffered” means that pbase() and pptr() always return null and output to the socket should appear as soon as possible.