Loading...
Searching...
No Matches
tls_socket.hpp
Go to the documentation of this file.
/*
restinio
*/
#pragma once
#include <restinio/asio_include.hpp>
#if !defined(RESTINIO_USE_BOOST_ASIO)
#include <asio/ssl.hpp>
#else
#include <boost/asio/ssl.hpp>
#endif
namespace restinio
{
namespace impl
{
//
// tls_socket_t
//
class tls_socket_t
{
public:
using socket_t = asio_ns::ssl::stream< asio_ns::ip::tcp::socket >;
using context_handle_t = std::shared_ptr< asio_ns::ssl::context >;
// Needed for asio >= 1.16.0 (starting with boost-1.72.0)
#if RESTINIO_ASIO_VERSION >= 101600
using executor_type = default_asio_executor;
#endif
tls_socket_t( const tls_socket_t & ) = delete;
tls_socket_t & operator = ( const tls_socket_t & ) = delete;
tls_socket_t(
asio_ns::io_context & io_context,
context_handle_t tls_context )
: m_context{ std::move( tls_context ) }
, m_socket{ std::make_unique< socket_t >( io_context, *m_context ) }
{}
tls_socket_t( tls_socket_t && ) = default;
tls_socket_t & operator = ( tls_socket_t && ) = default;
void
swap( tls_socket_t & sock )
{
std::swap( m_context, sock.m_context );
std::swap( m_socket, sock.m_socket );
}
auto &
lowest_layer()
{
return m_socket->lowest_layer();
}
const auto &
lowest_layer() const
{
return m_socket->lowest_layer();
}
socket_t &
asio_ssl_stream()
{
return *m_socket;
}
const socket_t &
asio_ssl_stream() const
{
return *m_socket;
}
auto
get_executor()
{
return this->lowest_layer().get_executor();
}
auto
remote_endpoint() const
{
return this->lowest_layer().remote_endpoint();
}
auto
is_open() const
{
return this->lowest_layer().is_open();
}
template< typename... Args >
void
cancel( Args &&... args )
{
this->lowest_layer().cancel( std::forward< Args >( args )... );
}
template< typename... Args >
auto
async_read_some( Args &&... args )
{
return m_socket->async_read_some( std::forward< Args >( args )... );
}
template< typename... Args >
auto
async_write_some( Args &&... args )
{
return m_socket->async_write_some( std::forward< Args >( args )... );
}
template< typename... Args >
void
shutdown( Args &&... args )
{
this->lowest_layer().shutdown( std::forward< Args >( args )... );
}
template< typename... Args >
void
close( Args &&... args )
{
this->lowest_layer().close( std::forward< Args >( args )... );
}
template< typename... Args >
auto
async_handshake( Args &&... args )
{
return m_socket->async_handshake( std::forward< Args >( args )... );
}
private:
context_handle_t m_context;
std::unique_ptr< socket_t > m_socket;
};
} /* namespace impl */
} /* namespace restinio */
asio_include.hpp
restinio::impl::tls_socket_t
Socket adapter for asio::ssl::stream< asio::ip::tcp::socket >.
Definition: tls_socket.hpp:37
restinio::impl::tls_socket_t::m_socket
std::unique_ptr< socket_t > m_socket
Definition: tls_socket.hpp:169
restinio::impl::tls_socket_t::tls_socket_t
tls_socket_t(tls_socket_t &&)=default
restinio::impl::tls_socket_t::async_write_some
auto async_write_some(Args &&... args)
Definition: tls_socket.hpp:141
restinio::impl::tls_socket_t::tls_socket_t
tls_socket_t(const tls_socket_t &)=delete
restinio::impl::tls_socket_t::shutdown
void shutdown(Args &&... args)
Definition: tls_socket.hpp:148
restinio::impl::tls_socket_t::get_executor
auto get_executor()
Definition: tls_socket.hpp:108
restinio::impl::tls_socket_t::asio_ssl_stream
const socket_t & asio_ssl_stream() const
Get an access to underlying Asio's socket.
Definition: tls_socket.hpp:102
restinio::impl::tls_socket_t::socket_t
asio_ns::ssl::stream< asio_ns::ip::tcp::socket > socket_t
Definition: tls_socket.hpp:39
restinio::impl::tls_socket_t::tls_socket_t
tls_socket_t(asio_ns::io_context &io_context, context_handle_t tls_context)
Definition: tls_socket.hpp:48
restinio::impl::tls_socket_t::is_open
auto is_open() const
Definition: tls_socket.hpp:120
restinio::impl::tls_socket_t::operator=
tls_socket_t & operator=(const tls_socket_t &)=delete
restinio::impl::tls_socket_t::async_read_some
auto async_read_some(Args &&... args)
Definition: tls_socket.hpp:134
restinio::impl::tls_socket_t::remote_endpoint
auto remote_endpoint() const
Definition: tls_socket.hpp:114
restinio::impl::tls_socket_t::m_context
context_handle_t m_context
Definition: tls_socket.hpp:168
restinio::impl::tls_socket_t::async_handshake
auto async_handshake(Args &&... args)
Definition: tls_socket.hpp:162
restinio::impl::tls_socket_t::context_handle_t
std::shared_ptr< asio_ns::ssl::context > context_handle_t
Definition: tls_socket.hpp:40
restinio::impl::tls_socket_t::cancel
void cancel(Args &&... args)
Definition: tls_socket.hpp:127
restinio::impl::tls_socket_t::asio_ssl_stream
socket_t & asio_ssl_stream()
Get an access to underlying Asio's socket.
Definition: tls_socket.hpp:87
restinio::impl::tls_socket_t::lowest_layer
auto & lowest_layer()
Definition: tls_socket.hpp:66
restinio::impl::tls_socket_t::close
void close(Args &&... args)
Definition: tls_socket.hpp:155
restinio::impl::tls_socket_t::lowest_layer
const auto & lowest_layer() const
Definition: tls_socket.hpp:72
restinio::impl::tls_socket_t::swap
void swap(tls_socket_t &sock)
Definition: tls_socket.hpp:59
restinio
Definition: asio_include.hpp:21
restinio::default_asio_executor
asio_ns::executor default_asio_executor
Definition: asio_include.hpp:224
std
STL namespace.