12 #include <boost/asio.hpp>
24 using Tcp = boost::asio::ip::tcp;
34 std::string
CreateServerName(std::string_view server_name, std::uint16_t server_count) {
35 std::string final_server_name{server_name};
36 final_server_name.append(std::to_string(server_count));
37 return final_server_name;
59 TcpAcceptorImpl(std::string_view acceptor_name, std::string_view local_ip_address,
60 std::uint16_t local_port_num, std::uint8_t maximum_connection) noexcept
65 Tcp::endpoint(TcpIpAddress::from_string(std::string{local_ip_address}.c_str()),
77 std::optional<TcpServer> tcp_server{};
79 Tcp::endpoint endpoint{};
83 if (ec.value() == boost::system::errc::success) {
87 FILE_NAME, __LINE__, __func__, [&endpoint](std::stringstream &msg) {
88 msg <<
"Tcp socket connection received from client "
89 <<
"<" << endpoint.address().to_string() <<
"," << endpoint.port() <<
">";
95 FILE_NAME, __LINE__, __func__, [ec](std::stringstream &msg) {
96 msg <<
"Tcp socket accept failed with error: " << ec.message();
130 std::uint16_t local_port_num, std::uint8_t maximum_connection) noexcept
131 : tcp_acceptor_impl_{std::make_unique<TcpAcceptorImpl>(acceptor_name, local_ip_address,
132 local_port_num, maximum_connection)} {}
static auto GetLibBoostLogger() noexcept -> LibBoostLogger &
Acceptor acceptor_
Store the tcp acceptor.
std::uint16_t server_count_
Keeps the count of server created.
std::optional< TcpServer > GetTcpServer() noexcept
Get a tcp server ready to communicate.
std::string acceptor_name_
Store the name of the acceptor.
boost::asio::ip::tcp::acceptor Acceptor
Type alias for tcp acceptor.
TcpAcceptorImpl(std::string_view acceptor_name, std::string_view local_ip_address, std::uint16_t local_port_num, std::uint8_t maximum_connection) noexcept
Constructs an instance of Acceptor.
boost::asio::io_context io_context_
Store the io context.
The acceptor to create new tcp servers.
TcpAcceptor(std::string_view acceptor_name, std::string_view local_ip_address, std::uint16_t local_port_num, std::uint8_t maximum_connection) noexcept
Constructs an instance of Acceptor.
std::optional< TcpServer > GetTcpServer() noexcept
Get a tcp server ready to communicate.
~TcpAcceptor() noexcept
Destruct an instance of TcpAcceptor.
Server that manages unsecured/ secured tcp connection.
Class used to create a tcp socket for handling transmission and reception of tcp message from driver.
Tcp::socket Socket
Type alias for tcp socket.
std::string CreateServerName(std::string_view server_name, std::uint16_t server_count)
Function to create server name.
boost::asio::ip::address TcpIpAddress
Type alias for tcp ip address.
boost::asio::ip::tcp Tcp
Type alias for tcp protocol.
boost::system::error_code TcpErrorCodeType