Diag-Client-Lib
Public Types | Public Member Functions | Private Types | Private Attributes | List of all members
boost_support::server::tls::TlsAcceptor< TlsVersion >::TlsAcceptorImpl Class Referencefinal
Collaboration diagram for boost_support::server::tls::TlsAcceptor< TlsVersion >::TlsAcceptorImpl:
Collaboration graph
[legend]

Public Types

using TlsSocket = socket::tls::TlsSocket
 Type alias for tcp secured socket. More...
 
using TlsContext = socket::tls::TlsContext
 Type alias for tls context. More...
 

Public Member Functions

 TlsAcceptorImpl (std::string_view acceptor_name, std::string_view local_ip_address, std::uint16_t local_port_num, std::uint8_t maximum_connection, TlsVersion tls_version, std::string_view certificate_path, std::string_view private_key_path) noexcept
 Constructs an instance of Acceptor. More...
 
std::optional< TlsServerGetTlsServer () noexcept
 Get a tls server ready to communicate. More...
 

Private Types

using Acceptor = boost::asio::ip::tcp::acceptor
 Type alias for tcp acceptor. More...
 

Private Attributes

boost::asio::io_context io_context_
 Store the io context. More...
 
TlsContext tls_context_
 Store the tls context. More...
 
std::uint16_t server_count_
 Keeps the count of server created. More...
 
std::string acceptor_name_
 Store the name of the acceptor. More...
 
Acceptor acceptor_
 Store the tcp acceptor. More...
 

Detailed Description

template<typename TlsVersion>
class boost_support::server::tls::TlsAcceptor< TlsVersion >::TlsAcceptorImpl

Definition at line 44 of file tls_acceptor.cpp.

Member Typedef Documentation

◆ Acceptor

template<typename TlsVersion >
using boost_support::server::tls::TlsAcceptor< TlsVersion >::TlsAcceptorImpl::Acceptor = boost::asio::ip::tcp::acceptor
private

Type alias for tcp acceptor.

Definition at line 117 of file tls_acceptor.cpp.

◆ TlsContext

Type alias for tls context.

Definition at line 54 of file tls_acceptor.cpp.

◆ TlsSocket

template<typename TlsVersion >
using boost_support::server::tls::TlsAcceptor< TlsVersion >::TlsAcceptorImpl::TlsSocket = socket::tls::TlsSocket

Type alias for tcp secured socket.

Definition at line 49 of file tls_acceptor.cpp.

Constructor & Destructor Documentation

◆ TlsAcceptorImpl()

template<typename TlsVersion >
boost_support::server::tls::TlsAcceptor< TlsVersion >::TlsAcceptorImpl::TlsAcceptorImpl ( std::string_view  acceptor_name,
std::string_view  local_ip_address,
std::uint16_t  local_port_num,
std::uint8_t  maximum_connection,
TlsVersion  tls_version,
std::string_view  certificate_path,
std::string_view  private_key_path 
)
inlinenoexcept

Constructs an instance of Acceptor.

Tcp connection shall be accepted on this ip address and port

Parameters
[in]local_ip_addressThe local ip address
[in]local_port_numThe local port number
[in]maximum_connectionThe maximum number of accepted connection

Definition at line 67 of file tls_acceptor.cpp.

71  : io_context_{},
72  tls_context_{std::forward<TlsVersion>(tls_version), certificate_path, private_key_path},
73  server_count_{0u},
74  acceptor_name_{acceptor_name},
76  Tcp::endpoint(TcpIpAddress::from_string(std::string{local_ip_address}.c_str()),
77  local_port_num)} {
78  acceptor_.listen(maximum_connection);
79  }
std::uint16_t server_count_
Keeps the count of server created.
boost::asio::io_context io_context_
Store the io context.
std::string acceptor_name_
Store the name of the acceptor.

Member Function Documentation

◆ GetTlsServer()

template<typename TlsVersion >
std::optional<TlsServer> boost_support::server::tls::TlsAcceptor< TlsVersion >::TlsAcceptorImpl::GetTlsServer ( )
inlinenoexcept

Get a tls server ready to communicate.

This blocks until new server is created

Returns
Tcp server object on success, else nothing

Definition at line 86 of file tls_acceptor.cpp.

86  {
87  using TcpErrorCodeType = boost::system::error_code;
88  std::optional<TlsServer> tls_server{};
89  TcpErrorCodeType ec{};
90  Tcp::endpoint endpoint{};
91 
92  // blocking accept
93  TlsSocket::TcpSocket accepted_socket{acceptor_.accept(endpoint, ec)};
94  if (ec.value() == boost::system::errc::success) {
95  tls_server.emplace(CreateServerName(acceptor_name_, server_count_),
96  TlsSocket{std::move(accepted_socket), tls_context_});
98  FILE_NAME, __LINE__, __func__, [&endpoint](std::stringstream &msg) {
99  msg << "Tls socket connection received from client "
100  << "<" << endpoint.address().to_string() << "," << endpoint.port() << ">";
101  });
102  // increment the server count
103  server_count_++;
104  } else {
106  FILE_NAME, __LINE__, __func__, [ec](std::stringstream &msg) {
107  msg << "Tcp socket accept failed with error: " << ec.message();
108  });
109  }
110  return tls_server;
111  }
static auto GetLibBoostLogger() noexcept -> LibBoostLogger &
Definition: logger.h:20
socket::tls::TlsSocket TlsSocket
Type alias for tcp secured socket.
Tcp::socket TcpSocket
Type alias for tcp socket.
Definition: tls_socket.h:61
#define FILE_NAME
Definition: file_path.h:14
std::string CreateServerName(std::string_view server_name, std::uint16_t server_count)
Function to create server name.

References boost_support::server::tls::anonymous_namespace{tls_acceptor.cpp}::CreateServerName(), FILE_NAME, and boost_support::common::logger::LibBoostLogger::GetLibBoostLogger().

Here is the call graph for this function:

Member Data Documentation

◆ acceptor_

template<typename TlsVersion >
Acceptor boost_support::server::tls::TlsAcceptor< TlsVersion >::TlsAcceptorImpl::acceptor_
private

Store the tcp acceptor.

Definition at line 142 of file tls_acceptor.cpp.

◆ acceptor_name_

template<typename TlsVersion >
std::string boost_support::server::tls::TlsAcceptor< TlsVersion >::TlsAcceptorImpl::acceptor_name_
private

Store the name of the acceptor.

Definition at line 137 of file tls_acceptor.cpp.

◆ io_context_

template<typename TlsVersion >
boost::asio::io_context boost_support::server::tls::TlsAcceptor< TlsVersion >::TlsAcceptorImpl::io_context_
private

Store the io context.

Definition at line 122 of file tls_acceptor.cpp.

◆ server_count_

template<typename TlsVersion >
std::uint16_t boost_support::server::tls::TlsAcceptor< TlsVersion >::TlsAcceptorImpl::server_count_
private

Keeps the count of server created.

Definition at line 132 of file tls_acceptor.cpp.

◆ tls_context_

template<typename TlsVersion >
TlsContext boost_support::server::tls::TlsAcceptor< TlsVersion >::TlsAcceptorImpl::tls_context_
private

Store the tls context.

Definition at line 127 of file tls_acceptor.cpp.


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