Template Class stream_socket

Inheritance Relationships

Base Type

Class Documentation

template<typename Protocol>
class stream_client::stream_socket : public stream_client::base_socket<boost::asio::basic_stream_socket<Protocol>>

Stream socket client for arbitrary plain (no encryption) protocol.

This class wraps boost::asio::basic_stream_socket to make it timeout-blocked: all read/write operations has timeout/deadline option.

Note

Not thread-safe, multi-thread rw access may mess up your data stream and/or timeout handling.

tparam Protocol

Type of protocol to use, see boost::asio::basic_stream_socket.

Public Functions

stream_socket(const stream_socket<Protocol> &other) = delete

Copy constructor is not permitted.

stream_socket<Protocol> &operator=(const stream_socket<Protocol> &other) = delete

Copy assignment is not permitted.

stream_socket(stream_socket<Protocol> &&other) = default

Move constructor.

stream_socket<Protocol> &operator=(stream_socket<Protocol> &&other) = default

Move assignment.

virtual ~stream_socket() = default

Destructor.

boost::system::error_code close()

Close the socket.

Wraps boost::asio::basic_stream_socket::shutdown and close. This function is used to close the socket. Any send or receive operations will be canceled immediately, and will complete with the boost::asio::error::operation_aborted error.

Returns

What error occurred, if any.

template<typename ConstBufferSequence, typename Time>
std::size_t send(const ConstBufferSequence &buffers, boost::system::error_code &ec, const Time &timeout_or_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, typename Time>
std::size_t send(const ConstBufferSequence &buffers, const Time &timeout_or_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_t send(const ConstBufferSequence &buffers, boost::system::error_code &ec)

Alias to send() using current I/O timeout value.

template<typename ConstBufferSequence>
inline std::size_t send(const ConstBufferSequence &buffers)

Alias to send() using current I/O timeout value.

template<typename MutableBufferSequence, typename Time>
std::size_t receive(const MutableBufferSequence &buffers, boost::system::error_code &ec, const Time &timeout_or_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, typename Time>
std::size_t receive(const MutableBufferSequence &buffers, const Time &timeout_or_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_t receive(const MutableBufferSequence &buffers, boost::system::error_code &ec)

Alias to receive() using current I/O timeout value.

template<typename MutableBufferSequence>
inline std::size_t receive(const MutableBufferSequence &buffers)

Alias to receive() using current I/O timeout value.

template<typename ConstBufferSequence, typename Time>
std::size_t write_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, typename Time>
std::size_t write_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_t write_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_t write_some(const ConstBufferSequence &buffers)

Alias to write_some() using current I/O timeout value.

template<typename MutableBufferSequence, typename Time>
std::size_t read_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, typename Time>
std::size_t read_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_t read_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_t read_some(const MutableBufferSequence &buffers)

Alias to read_some() using current I/O timeout value.