Template Class stream_socket¶
Defined in File ssl_stream_socket.hpp
Class Documentation¶
-
template<typename
Socket
>
classstream_client::ssl
::
stream_socket
¶ SSL stream layer.
This class wraps usage of boost::asio::ssl::context over boost::asio::ssl::stream<Socket>.
Note
Not thread-safe, multi-thread rw access may mess up your data stream and/or timeout handling.
- tparam Socket
Type of underlying stream socket to use.
Public Types
-
using
protocol_type
= typename next_layer_type::protocol_type¶
-
using
lowest_layer_type
= typename next_layer_type::lowest_layer_type¶
-
using
ssl_layer_type
= typename boost::asio::ssl::stream<next_layer_type>¶
-
using
endpoint_type
= typename next_layer_type::endpoint_type¶
-
using
clock_type
= typename next_layer_type::clock_type¶
-
using
time_duration_type
= typename next_layer_type::time_duration_type¶
-
using
time_point_type
= typename next_layer_type::time_point_type¶
-
using
next_layer_config
= const typename next_layer_type::config¶
Public Functions
-
stream_socket
(const endpoint_type &peer_endpoint, time_duration_type connect_timeout, time_duration_type operation_timeout, const std::string &upstream_host, bool rfc2818_handshake = true)¶ Parametrized constructor.
Constructs SSL stream connected to
peer_endpoint
. This operation blocks until stream is constructed orconnect_timeout
time elapsed.- Parameters
[in] peer_endpoint – Remote endpoint to connect.
[in] connect_timeout – Timeout for connection operation.
[in] operation_timeout – Subsequent I/O operation default timeout.
[in] upstream_host – Hostname to check SSL-cretificate against.
- Throws
boost::system::system_error – Thrown on failure.
-
stream_socket
(const stream_socket<Socket> &other) = delete¶ Copy constructor is not permitted.
-
stream_socket<Socket> &
operator=
(const stream_socket<Socket> &other) = delete¶ Copy assignment is not permitted.
-
stream_socket
(stream_socket<Socket> &&other) = default¶ Move constructor.
-
stream_socket<Socket> &
operator=
(stream_socket<Socket> &&other) = default¶ Move assignment.
-
virtual
~stream_socket
() = default¶ Destructor.
-
boost::system::error_code
close
()¶ Perform SSL shutdown.
Reception of close_notify constrained with default I/O timeout of
next_layer_type
.- Returns
What error occurred, if any.
-
inline void
close
(boost::system::error_code &ec)¶ Perform SSL shutdown.
Reception of close_notify constrained with default I/O timeout of
next_layer_type
.- Parameters
[in] ec – Set to indicate what error occurred, if any.
-
template<typename
Time
>
boost::system::error_codehandshake
(boost::system::error_code &ec, const Time &timeout_or_deadline)¶ Perform SSL handshaking.
This function is used to perform SSL handshaking on the stream. The call will block until handshaking is complete or an error occurs.
- Template Parameters
Time – Type of
timeout_or_deadline
, either time_duration_type or time_point_type.- Parameters
[out] ec – Set to indicate what error occurred, if any.
[in] timeout_or_deadline – Expiration time-point or duration.
- Returns
Value of the error occurred, if any (same as
ec
).
-
template<typename
Time
>
voidhandshake
(const Time &timeout_or_deadline)¶ Perform SSL handshaking.
This function is used to perform SSL handshaking on the stream. The call will block until handshaking is complete or an error occurs.
- Template Parameters
Time – Type of
timeout_or_deadline
, either time_duration_type or time_point_type.- Parameters
[in] timeout_or_deadline – Expiration time-point or duration.
- Throws
boost::system::system_error – Thrown on failure.
-
inline void
handshake
()¶ Alias to handshake() using current connection timeout value.
-
template<typename
ConstBufferSequence
>
std::size_tsend
(const ConstBufferSequence &buffers, boost::system::error_code &ec, const time_point_type &deadline)¶ Send data through the stream.
The call will block until one of the following conditions is true:
All of the data in the supplied buffers has been written.
An error or timeout occurred.
- Template Parameters
ConstBufferSequence – Type of buffers, see boost::asio::buffer.
Time – Type of
timeout_or_deadline
, either time_duration_type or time_point_type.
- Parameters
[in] buffers – One or more buffers containing the data to be written.
[in] timeout_or_deadline – Expiration time-point or duration.
[out] ec – Set to indicate what error occurred, if any.
- Returns
The number of bytes transferred.
-
template<typename
ConstBufferSequence
>
std::size_tsend
(const ConstBufferSequence &buffers, const time_point_type &deadline)¶ Send data through the stream.
The call will block until one of the following conditions is true:
All of the data in the supplied buffers has been written.
An error or timeout occurred.
- Template Parameters
ConstBufferSequence – Type of buffers, see boost::asio::buffer.
Time – Type of
timeout_or_deadline
, either time_duration_type or time_point_type.
- Parameters
[in] buffers – One or more buffers containing the data to be written.
[in] timeout_or_deadline – Expiration time-point or duration.
- Throws
boost::system::system_error – Thrown on failure.
- Returns
The number of bytes transferred.
-
template<typename
ConstBufferSequence
>
inline std::size_tsend
(const ConstBufferSequence &buffers, boost::system::error_code &ec, const time_duration_type &timeout)¶ Alias to send() using timeout.
-
template<typename
ConstBufferSequence
>
inline std::size_tsend
(const ConstBufferSequence &buffers, const time_duration_type &timeout)¶ Alias to send() using timeout.
-
template<typename
ConstBufferSequence
>
inline std::size_tsend
(const ConstBufferSequence &buffers, boost::system::error_code &ec)¶ Alias to send() using current I/O timeout value.
-
template<typename
ConstBufferSequence
>
inline std::size_tsend
(const ConstBufferSequence &buffers)¶ Alias to send() using current I/O timeout value.
-
template<typename
MutableBufferSequence
>
std::size_treceive
(const MutableBufferSequence &buffers, boost::system::error_code &ec, const time_point_type &deadline)¶ Receive data through the stream.
The call will block until one of the following conditions is true:
The supplied buffers are full.
An error or timeout occurred.
- Template Parameters
MutableBufferSequence – Type of buffers, see boost::asio::buffer.
Time – Type of
timeout_or_deadline
, either time_duration_type or time_point_type.
- Parameters
[in] buffers – One or more buffers into which the data will be received.
[in] timeout_or_deadline – Expiration time-point or duration.
[out] ec – Set to indicate what error occurred, if any.
- Returns
The number of bytes received.
-
template<typename
MutableBufferSequence
>
std::size_treceive
(const MutableBufferSequence &buffers, const time_point_type &deadline)¶ Receive data through the stream.
The call will block until one of the following conditions is true:
The supplied buffers are full.
An error or timeout occurred.
- Template Parameters
MutableBufferSequence – Type of buffers, see boost::asio::buffer.
Time – Type of
timeout_or_deadline
, either time_duration_type or time_point_type.
- Parameters
[in] buffers – One or more buffers into which the data will be received.
[in] timeout_or_deadline – Expiration time-point or duration.
- Throws
boost::system::system_error – Thrown on failure.
- Returns
The number of bytes received.
-
template<typename
MutableBufferSequence
>
inline std::size_treceive
(const MutableBufferSequence &buffers, boost::system::error_code &ec, const time_duration_type &timeout)¶ Alias to send() using timeout.
-
template<typename
MutableBufferSequence
>
inline std::size_treceive
(const MutableBufferSequence &buffers, const time_duration_type &timeout)¶ Alias to send() using timeout.
-
template<typename
MutableBufferSequence
>
inline std::size_treceive
(const MutableBufferSequence &buffers, boost::system::error_code &ec)¶ Alias to receive() using current I/O timeout value.
-
template<typename
MutableBufferSequence
>
inline std::size_treceive
(const MutableBufferSequence &buffers)¶ Alias to receive() using current I/O timeout value.
-
template<typename
ConstBufferSequence
, typenameTime
>
std::size_twrite_some
(const ConstBufferSequence &buffers, boost::system::error_code &ec, const Time &timeout_or_deadline)¶ Send some data on the stream.
The call will block until one or more bytes of the data has been sent successfully, or an until error occurs.
- Template Parameters
ConstBufferSequence – Type of buffers, see boost::asio::buffer.
Time – Type of
timeout_or_deadline
, either time_duration_type or time_point_type.
- Parameters
[in] buffers – One or more buffers containing the data to be written.
[in] timeout_or_deadline – Expiration time-point or duration.
[out] ec – Set to indicate what error occurred, if any.
- Returns
The number of bytes sent. Returns 0 if an error occurred.
-
template<typename
ConstBufferSequence
, typenameTime
>
std::size_twrite_some
(const ConstBufferSequence &buffers, const Time &timeout_or_deadline)¶ Send some data on the stream.
The call will block until one or more bytes of the data has been sent successfully, or an until error occurs.
- Template Parameters
ConstBufferSequence – Type of buffers, see boost::asio::buffer.
Time – Type of
timeout_or_deadline
, either time_duration_type or time_point_type.
- Parameters
[in] buffers – One or more buffers containing the data to be written.
[in] timeout_or_deadline – Expiration time-point or duration.
- Throws
boost::system::system_error – Thrown on failure.
- Returns
The number of bytes sent.
-
template<typename
ConstBufferSequence
>
inline std::size_twrite_some
(const ConstBufferSequence &buffers, boost::system::error_code &ec)¶ Alias to write_some() using current I/O timeout value.
-
template<typename
ConstBufferSequence
>
inline std::size_twrite_some
(const ConstBufferSequence &buffers)¶ Alias to write_some() using current I/O timeout value.
-
template<typename
MutableBufferSequence
, typenameTime
>
std::size_tread_some
(const MutableBufferSequence &buffers, boost::system::error_code &ec, const Time &timeout_or_deadline)¶ Receive some data on the stream.
The call will block until one or more bytes of data has been received successfully, or until an error occurs.
- Template Parameters
MutableBufferSequence – Type of buffers, see boost::asio::buffer.
Time – Type of
timeout_or_deadline
, either time_duration_type or time_point_type.
- Parameters
[in] buffers – One or more buffers into which the data will be received.
[in] timeout_or_deadline – Expiration time-point or duration.
[out] ec – Set to indicate what error occurred, if any.
- Returns
The number of bytes received. Returns 0 if an error occurred.
-
template<typename
MutableBufferSequence
, typenameTime
>
std::size_tread_some
(const MutableBufferSequence &buffers, const Time &timeout_or_deadline)¶ Receive some data on the stream.
The call will block until one or more bytes of data has been received successfully, or until an error occurs.
- Template Parameters
MutableBufferSequence – Type of buffers, see boost::asio::buffer.
Time – Type of
timeout_or_deadline
, either time_duration_type or time_point_type.
- Parameters
[in] buffers – One or more buffers into which the data will be received.
[in] timeout_or_deadline – Expiration time-point or duration.
- Throws
boost::system::system_error – Thrown on failure.
- Returns
The number of bytes received.
-
template<typename
MutableBufferSequence
>
inline std::size_tread_some
(const MutableBufferSequence &buffers, boost::system::error_code &ec)¶ Alias to read_some() using current I/O timeout value.
-
template<typename
MutableBufferSequence
>
inline std::size_tread_some
(const MutableBufferSequence &buffers)¶ Alias to read_some() using current I/O timeout value.
-
inline const boost::asio::ssl::context &
ssl_context
() const¶ Get a const reference to the associated boost::asio::ssl::context.
- Returns
This function returns a const reference to the ssl context.
-
inline boost::asio::ssl::context &
ssl_context
()¶ Get a reference to the associated boost::asio::ssl::context.
- Returns
This function returns a reference to the ssl context.
-
inline const ssl_layer_type &
ssl_layer
() const¶ Get a const reference to the underlying boost::asio::ssl::stream.
- Returns
This function returns a const reference to the underlying boost::asio::ssl::stream.
-
inline ssl_layer_type &
ssl_layer
()¶ Get a reference to the underlying boost::asio::ssl::stream.
- Returns
This function returns a reference to the underlying boost::asio::ssl::stream.
-
inline const next_layer_type &
next_layer
() const¶ Get a const reference to the underlying stream of type
Socket
.- Returns
This function returns a const reference to the underlying stream.
-
inline next_layer_type &
next_layer
()¶ Get a reference to the underlying stream of type
Socket
.- Returns
This function returns a reference to the underlying stream.
-
inline const lowest_layer_type &
lowest_layer
() const¶ Get a const reference to the lowest layer.
This function returns a reference to the lowest layer in a stack of layers, basically an instance of boost::asio::basic_stream_socket.
- Returns
A const reference to the lowest layer in the stack of layers.
-
inline lowest_layer_type &
lowest_layer
()¶ Get a reference to the lowest layer.
This function returns a reference to the lowest layer in a stack of layers, basically an instance of boost::asio::basic_stream_socket.
- Returns
A reference to the lowest layer in the stack of layers.
-
inline native_handle_type
native_handle
()¶ Get the underlying implementation in the native type.
This function may be used to obtain the underlying implementation of the context. This is intended to allow access to context functionality that is not otherwise provided.
- Returns
A reference to the lowest layer in the stack of layers.
-
inline const time_duration_type &
connection_timeout
() const¶ Get connection timeout.
This function used to get connection timeout used at construction.
- Returns
A const reference to the connection timeout.
-
inline const time_duration_type &
io_timeout
() const¶ Get I/O operations timeout.
This function used to get current value for I/O timeout.
- Returns
A const reference to the timeout.
-
inline time_duration_type
io_timeout
(time_duration_type new_io_timeout)¶ Set I/O operations timeout.
This function used to set new value for I/O timeout.
- Returns
Previous timeout value.
-
inline bool
io_timeout_enabled
() const¶ Get current status of I/O timeout.
This function used to check if I/O timeout enabled or not.
- Returns
A boolean state of the timeout.
-
inline bool
io_timeout_enabled
(bool new_mode)¶ Set current status of I/O timeout.
This function used to enable or disable I/O timeout. If it’s disabled, rw functions without explicit timeout value will use indefinite timeout (blocking mode),
- Returns
Previous state of the timeout.
-
inline bool
is_open
() const¶ Determine whether the underlying stream is open.