libjmmcg  release_579_6_g8cffd
A C++ library containing an eclectic mix of useful, advanced components.
jmmcg::LIBJMMCG_VER_NAMESPACE::socket::asio::socket_wrapper< LkT > Class Template Reference

A simple TCP/IP socket wrapper using boost::asio. More...

#include <socket_wrapper_asio.hpp>

Public Types

using socket_t = boost::asio::ip::tcp::socket
 
using socket_priority = socket::socket_priority
 
using write_lock_t = LkT
 The lock-type to use to ensure that the underlying ::write()s occur atomically. More...
 
using atomic_t = typename write_lock_t::atomic_t
 

Public Member Functions

 socket_wrapper (boost::asio::io_context &io_context)
 Wrap a TCP socket using the TCP/IP protocol. More...
 
 socket_wrapper (socket_t &&socket)
 Wrap a TCP socket using the TCP/IP protocol. More...
 
void connect (boost::asio::ip::tcp::endpoint const &endpoint)
 
template<class MsgT >
void write (MsgT const &message) noexcept(false)
 Write the whole message to the socket in one go. More...
 
template<class V , std::size_t N>
void write (std::array< V, N > const &message) noexcept(false)
 Write the whole message to the socket in one go. More...
 
template<class MsgT >
void read (MsgT &dest) noexcept(false)
 Read the whole message from the socket in one go. More...
 
template<class V , std::size_t SrcSz>
void read (V(&dest)[SrcSz]) noexcept(false)
 Read the whole message from the socket in one go. More...
 
template<class MsgDetails , class V , std::size_t N>
bool read (std::array< V, N > &buff) noexcept(false)
 
bool is_open () const
 
void close ()
 
void set_options (std::size_t, std::size_t max_message_size, unsigned short timeout, socket_priority priority, std::size_t incoming_cpu)
 
std::string to_string () const noexcept(false)
 

Protected Attributes

atomic_t mutex_
 

Detailed Description

template<class LkT>
class jmmcg::LIBJMMCG_VER_NAMESPACE::socket::asio::socket_wrapper< LkT >

A simple TCP/IP socket wrapper using boost::asio.

Developed from:

Definition at line 36 of file socket_wrapper_asio.hpp.

Member Typedef Documentation

◆ atomic_t

template<class LkT >
using jmmcg::LIBJMMCG_VER_NAMESPACE::socket::asio::socket_wrapper< LkT >::atomic_t = typename write_lock_t::atomic_t

Definition at line 47 of file socket_wrapper_asio.hpp.

◆ socket_priority

◆ socket_t

template<class LkT >
using jmmcg::LIBJMMCG_VER_NAMESPACE::socket::asio::socket_wrapper< LkT >::socket_t = boost::asio::ip::tcp::socket

Definition at line 38 of file socket_wrapper_asio.hpp.

◆ write_lock_t

The lock-type to use to ensure that the underlying ::write()s occur atomically.

The calls to the underlying socket ::write() may occur multiple times when under extreme load. This lock is used to ensure that the calls to write() occur atomically with respect to multiple threads.

See also
::write()

Definition at line 46 of file socket_wrapper_asio.hpp.

Constructor & Destructor Documentation

◆ socket_wrapper() [1/2]

template<class LkT >
jmmcg::LIBJMMCG_VER_NAMESPACE::socket::asio::socket_wrapper< LkT >::socket_wrapper ( boost::asio::io_context &  io_context)
inlineexplicit

Wrap a TCP socket using the TCP/IP protocol.

Parameters
io_contextThe I/O context that underlies the socket.

Definition at line 34 of file socket_wrapper_asio_impl.hpp.

References jmmcg::LIBJMMCG_VER_NAMESPACE::socket::asio::socket_wrapper< LkT >::socket_wrapper().

Referenced by jmmcg::LIBJMMCG_VER_NAMESPACE::socket::asio::socket_wrapper< LkT >::socket_wrapper().

◆ socket_wrapper() [2/2]

template<class LkT >
jmmcg::LIBJMMCG_VER_NAMESPACE::socket::asio::socket_wrapper< LkT >::socket_wrapper ( socket_t &&  socket)
inlineexplicit

Wrap a TCP socket using the TCP/IP protocol.

Parameters
socketThe socket to be taken control of.

Definition at line 40 of file socket_wrapper_asio_impl.hpp.

Member Function Documentation

◆ close()

template<class LkT >
void jmmcg::LIBJMMCG_VER_NAMESPACE::socket::asio::socket_wrapper< LkT >::close
inline

Definition at line 194 of file socket_wrapper_asio_impl.hpp.

◆ connect()

template<class LkT >
void jmmcg::LIBJMMCG_VER_NAMESPACE::socket::asio::socket_wrapper< LkT >::connect ( boost::asio::ip::tcp::endpoint const &  endpoint)
inline

Definition at line 46 of file socket_wrapper_asio_impl.hpp.

◆ is_open()

template<class LkT >
bool jmmcg::LIBJMMCG_VER_NAMESPACE::socket::asio::socket_wrapper< LkT >::is_open
inline

Definition at line 188 of file socket_wrapper_asio_impl.hpp.

◆ read() [1/3]

template<class LkT >
template<class MsgT >
void jmmcg::LIBJMMCG_VER_NAMESPACE::socket::asio::socket_wrapper< LkT >::read ( MsgT &  dest)
inlinenoexcept

Read the whole message from the socket in one go.

Parameters
destThe message will be placed into this buffer, which may be grown to accommodate the message.

Definition at line 93 of file socket_wrapper_asio_impl.hpp.

◆ read() [2/3]

template<class LkT >
template<class MsgDetails , class V , std::size_t N>
bool jmmcg::LIBJMMCG_VER_NAMESPACE::socket::asio::socket_wrapper< LkT >::read ( std::array< V, N > &  buff)
inlinenoexcept

Definition at line 149 of file socket_wrapper_asio_impl.hpp.

◆ read() [3/3]

template<class LkT >
template<class V , std::size_t SrcSz>
void jmmcg::LIBJMMCG_VER_NAMESPACE::socket::asio::socket_wrapper< LkT >::read ( V(&)  dest[SrcSz])
inlinenoexcept

Read the whole message from the socket in one go.

Parameters
destThe message will be placed into this stack-based buffer, which must be sufficiently large to accommodate the message read, otherwise UB will result.

Definition at line 136 of file socket_wrapper_asio_impl.hpp.

◆ set_options()

template<class LkT >
void jmmcg::LIBJMMCG_VER_NAMESPACE::socket::asio::socket_wrapper< LkT >::set_options ( std::size_t  ,
std::size_t  max_message_size,
unsigned short  timeout,
socket_priority  priority,
std::size_t  incoming_cpu 
)
inline

Definition at line 23 of file socket_wrapper_asio_impl.hpp.

◆ to_string()

template<class LkT >
std::string jmmcg::LIBJMMCG_VER_NAMESPACE::socket::asio::socket_wrapper< LkT >::to_string
inlinenoexcept

Definition at line 202 of file socket_wrapper_asio_impl.hpp.

◆ write() [1/2]

template<class LkT >
template<class MsgT >
void jmmcg::LIBJMMCG_VER_NAMESPACE::socket::asio::socket_wrapper< LkT >::write ( MsgT const &  message)
inlinenoexcept

Write the whole message to the socket in one go.

Parameters
messageThe message to write, that must be as-if a POD.

Definition at line 52 of file socket_wrapper_asio_impl.hpp.

References jmmcg::LIBJMMCG_VER_NAMESPACE::socket::asio::socket_wrapper< LkT >::mutex_.

◆ write() [2/2]

template<class LkT >
template<class V , std::size_t N>
void jmmcg::LIBJMMCG_VER_NAMESPACE::socket::asio::socket_wrapper< LkT >::write ( std::array< V, N > const &  message)
inlinenoexcept

Write the whole message to the socket in one go.

Parameters
messageThe message to write, that must be as-if a POD.

Definition at line 79 of file socket_wrapper_asio_impl.hpp.

References jmmcg::LIBJMMCG_VER_NAMESPACE::socket::asio::socket_wrapper< LkT >::mutex_.

Member Data Documentation

◆ mutex_


The documentation for this class was generated from the following files: