libjmmcg
release_579_6_g8cffd
A C++ library containing an eclectic mix of useful, advanced components.
|
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_ |
A simple TCP/IP socket wrapper using boost::asio.
Definition at line 36 of file socket_wrapper_asio.hpp.
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.
using jmmcg::LIBJMMCG_VER_NAMESPACE::socket::asio::socket_wrapper< LkT >::socket_priority = socket::socket_priority |
Definition at line 39 of file socket_wrapper_asio.hpp.
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.
using jmmcg::LIBJMMCG_VER_NAMESPACE::socket::asio::socket_wrapper< LkT >::write_lock_t = LkT |
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.
Definition at line 46 of file socket_wrapper_asio.hpp.
|
inlineexplicit |
Wrap a TCP socket using the TCP/IP protocol.
io_context | The 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().
|
inlineexplicit |
Wrap a TCP socket using the TCP/IP protocol.
socket | The socket to be taken control of. |
Definition at line 40 of file socket_wrapper_asio_impl.hpp.
|
inline |
Definition at line 194 of file socket_wrapper_asio_impl.hpp.
|
inline |
Definition at line 46 of file socket_wrapper_asio_impl.hpp.
|
inline |
Definition at line 188 of file socket_wrapper_asio_impl.hpp.
|
inlinenoexcept |
Read the whole message from the socket in one go.
dest | The 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.
|
inlinenoexcept |
Definition at line 149 of file socket_wrapper_asio_impl.hpp.
|
inlinenoexcept |
Read the whole message from the socket in one go.
dest | The 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.
|
inline |
Definition at line 23 of file socket_wrapper_asio_impl.hpp.
|
inlinenoexcept |
Definition at line 202 of file socket_wrapper_asio_impl.hpp.
|
inlinenoexcept |
Write the whole message to the socket in one go.
message | The 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_.
|
inlinenoexcept |
Write the whole message to the socket in one go.
message | The 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_.
|
mutableprotected |
Definition at line 105 of file socket_wrapper_asio.hpp.
Referenced by jmmcg::LIBJMMCG_VER_NAMESPACE::socket::asio::socket_wrapper< LkT >::write().