Add socket() accessor to iostreams. Make basic_socket_streambuf::error() public.

The public inheritance of basic_socket_streambuf<> from basic_socket<> has been
deprecated. A reference to the underlying socket can now be obtained via the
basic_socket_iostream::socket() or basic_socket_streambuf::socket() member
functions.

The basic_socket_streambuf::puberror() function has been deprecated. The
basic_socket_streambuf::error() function should be used instead.
This commit is contained in:
Christopher Kohlhoff 2016-08-11 09:43:39 +10:00
parent 9fb2d82fbe
commit f932359a47
4 changed files with 31 additions and 14 deletions

View File

@ -218,6 +218,12 @@ public:
TimeTraits ASIO_SVC_TARG1>::streambuf_);
}
/// Get a reference to the underlying socket.
basic_socket<Protocol ASIO_SVC_TARG>& socket()
{
return rdbuf()->socket();
}
/// Get the last error associated with the stream.
/**
* @return An \c error_code corresponding to the last error from the stream.
@ -232,7 +238,7 @@ public:
*/
const asio::error_code& error() const
{
return rdbuf()->puberror();
return rdbuf()->error();
}
#if !defined(ASIO_NO_DEPRECATED)

View File

@ -101,7 +101,11 @@ template <typename Protocol
class basic_socket_streambuf
: public std::streambuf,
private detail::socket_streambuf_base,
#if defined(ASIO_NO_DEPRECATED) || defined(GENERATING_DOCUMENTATION)
private basic_socket<Protocol ASIO_SVC_TARG>
#else // defined(ASIO_NO_DEPRECATED) || defined(GENERATING_DOCUMENTATION)
public basic_socket<Protocol ASIO_SVC_TARG>
#endif // defined(ASIO_NO_DEPRECATED) || defined(GENERATING_DOCUMENTATION)
{
private:
// These typedefs are intended keep this class's implementation independent
@ -229,7 +233,25 @@ public:
return !ec_ ? this : 0;
}
/// Get a reference to the underlying socket.
basic_socket<Protocol ASIO_SVC_TARG>& socket()
{
return *this;
}
/// Get the last error associated with the stream buffer.
/**
* @return An \c error_code corresponding to the last error from the stream
* buffer.
*/
const asio::error_code& error() const
{
return ec_;
}
#if !defined(ASIO_NO_DEPRECATED)
/// (Deprecated: Use error().) Get the last error associated with the stream
/// buffer.
/**
* @return An \c error_code corresponding to the last error from the stream
* buffer.
@ -239,7 +261,6 @@ public:
return error();
}
#if !defined(ASIO_NO_DEPRECATED)
/// (Deprecated: Use expiry().) Get the stream buffer's expiry time as an
/// absolute time.
/**
@ -469,16 +490,6 @@ protected:
return 0;
}
/// Get the last error associated with the stream buffer.
/**
* @return An \c error_code corresponding to the last error from the stream
* buffer.
*/
virtual const asio::error_code& error() const
{
return ec_;
}
private:
void init_buffers()
{

View File

@ -28,7 +28,7 @@ simple servers. For example:
for (;;)
{
ip::tcp::iostream stream;
acceptor.accept(*stream.rdbuf());
acceptor.accept(stream.socket());
...
}

View File

@ -35,7 +35,7 @@ int main()
{
tcp::iostream stream;
asio::error_code ec;
acceptor.accept(*stream.rdbuf(), ec);
acceptor.accept(stream.socket(), ec);
if (!ec)
{
stream << make_daytime_string();