21     : tcp_socket_{io_context.GetContext()},
 
   22       local_endpoint_{boost::asio::ip::make_address(local_ip_address), local_port_num} {}
 
   25     : tcp_socket_{std::move(socket)},
 
   26       local_endpoint_{tcp_socket_.local_endpoint()} {}
 
   35   tcp_socket_.open(local_endpoint_.protocol(), ec);
 
   36   if (ec.value() == boost::system::errc::success) {
 
   38     tcp_socket_.set_option(boost::asio::socket_base::reuse_address{
true});
 
   40     tcp_socket_.non_blocking(
false);
 
   42     tcp_socket_.bind(local_endpoint_, ec);
 
   44     if (ec.value() == boost::system::errc::success) {
 
   45       local_endpoint_ = tcp_socket_.local_endpoint();
 
   48           FILE_NAME, __LINE__, __func__, [
this](std::stringstream &msg) {
 
   49             Tcp::endpoint 
const endpoint_{tcp_socket_.local_endpoint()};
 
   50             msg << 
"Tcp Socket opened and bound to " 
   51                 << 
"<" << endpoint_.address().to_string() << 
"," << endpoint_.port() << 
">";
 
   53       result.EmplaceValue();
 
   57           FILE_NAME, __LINE__, __func__, [ec](std::stringstream &msg) {
 
   58             msg << 
"Tcp Socket binding failed with message: " << ec.message();
 
   60       result.EmplaceError(SocketError::kBindingFailed);
 
   64         FILE_NAME, __LINE__, __func__, [ec](std::stringstream &msg) {
 
   65           msg << 
"Tcp Socket opening failed with error: " << ec.message();
 
   67     result.EmplaceError(SocketError::kOpenFailed);
 
   73     std::string_view host_ip_address, std::uint16_t host_port_num) noexcept {
 
   79       Tcp::endpoint(TcpIpAddress::from_string(std::string{host_ip_address}), host_port_num), ec);
 
   80   if (ec.value() == boost::system::errc::success) {
 
   82         FILE_NAME, __LINE__, __func__, [
this](std::stringstream &msg) {
 
   83           Tcp::endpoint 
const endpoint_{tcp_socket_.remote_endpoint()};
 
   84           msg << 
"Tcp Socket connected to host " 
   85               << 
"<" << endpoint_.address().to_string() << 
"," << endpoint_.port() << 
">";
 
   87     result.EmplaceValue();
 
   90         FILE_NAME, __LINE__, __func__, [ec](std::stringstream &msg) {
 
   91           msg << 
"Tcp Socket connect to host failed with error: " << ec.message();
 
  103   if (ec.value() == boost::system::errc::success) {
 
  105     result.EmplaceValue();
 
  108         FILE_NAME, __LINE__, __func__, [ec](std::stringstream &msg) {
 
  109           msg << 
"Tcp Socket disconnection from host failed with error: " << ec.message();
 
  122       boost::asio::buffer(tcp_message->GetPayload().data(), tcp_message->GetPayload().size()), ec);
 
  124   if (ec.value() == boost::system::errc::success) {
 
  126         FILE_NAME, __LINE__, __func__, [
this](std::stringstream &msg) {
 
  127           Tcp::endpoint 
const endpoint_{tcp_socket_.remote_endpoint()};
 
  128           msg << 
"Tcp message sent to " 
  129               << 
"<" << endpoint_.address().to_string() << 
"," << endpoint_.port() << 
">";
 
  131     result.EmplaceValue();
 
  134         FILE_NAME, __LINE__, __func__, [ec](std::stringstream &msg) {
 
  135           msg << 
"Tcp message sending failed with error: " << ec.message();
 
  144   tcp_socket_.shutdown(boost::asio::socket_base::shutdown_receive);
 
  146   result.EmplaceValue();
 
  160   if (ec.value() == boost::system::errc::success) {
 
  162     std::uint32_t 
const read_next_bytes{[&rx_buffer]() noexcept -> std::uint32_t {
 
  163       return static_cast<std::uint32_t
>(
 
  164           (
static_cast<std::uint32_t
>(rx_buffer[4u] << 24u) & 0xFF000000) |
 
  165           (
static_cast<std::uint32_t
>(rx_buffer[5u] << 16u) & 0x00FF0000) |
 
  166           (
static_cast<std::uint32_t
>(rx_buffer[6u] << 8u) & 0x0000FF00) |
 
  167           (
static_cast<std::uint32_t
>(rx_buffer[7u] & 0x000000FF)));
 
  170     if (read_next_bytes != 0u) {
 
  177       Tcp::endpoint 
const remote_endpoint{
tcp_socket_.remote_endpoint()};
 
  179           remote_endpoint.address().to_string(), remote_endpoint.port(), std::move(rx_buffer))};
 
  181           FILE_NAME, __LINE__, __func__, [&remote_endpoint](std::stringstream &msg) {
 
  182             msg << 
"Tcp Message received from " 
  183                 << 
"<" << remote_endpoint.address().to_string() << 
"," << remote_endpoint.port()
 
  186       result.EmplaceValue(std::move(tcp_rx_message));
 
  190           [](std::stringstream &msg) { msg << 
"Tcp Message read ignored as header size is zero"; });
 
  192   } 
else if (ec.value() == boost::asio::error::eof) {
 
  195         [ec](std::stringstream &msg) { msg << 
"Remote Disconnected with: " << ec.message(); });
 
  198         FILE_NAME, __LINE__, __func__, [ec](std::stringstream &msg) {
 
  199           msg << 
"Remote Disconnected with undefined error: " << ec.message();
 
static auto GetLibBoostLogger() noexcept -> LibBoostLogger &
 
std::vector< std::uint8_t > BufferType
Type alias for underlying buffer.
 
Wrapper class to hold boost io context required for io object( sockets)
 
Class used to create a tcp socket for handling transmission and reception of tcp message from driver.
 
TcpSocket(std::string_view local_ip_address, std::uint16_t local_port_num, IoContext &io_context) noexcept
Constructs an instance of TcpSocket.
 
core_type::Result< void, SocketError > Connect(std::string_view host_ip_address, std::uint16_t host_port_num) noexcept
Function to connect to remote ip address and port number.
 
boost_support::message::tcp::TcpMessagePtr TcpMessagePtr
Type alias for Tcp message pointer.
 
SocketError
Socket error code.
 
core_type::Result< void, SocketError > Close() noexcept
Function to destroy the socket.
 
core_type::Result< TcpMessagePtr, SocketError > Read() noexcept
Function to read message from socket.
 
core_type::Result< void, SocketError > Disconnect() noexcept
Function to Disconnect from host.
 
boost_support::message::tcp::TcpMessageConstPtr TcpMessageConstPtr
Type alias for Tcp message const pointer.
 
Tcp::socket Socket
Type alias for tcp socket.
 
core_type::Result< void, SocketError > Transmit(TcpMessageConstPtr tcp_message) noexcept
Function to trigger transmission.
 
~TcpSocket() noexcept
Destruct an instance of TcpSocket.
 
Socket tcp_socket_
Store the underlying tcp socket.
 
boost::system::error_code TcpErrorCodeType
Type alias for tcp error codes.
 
Class type to contains a value (of type ValueType), or an error (of type ErrorType)
 
constexpr std::uint8_t kDoipheadrSize
Doip HeaderSize.
 
core_type::Result< T, E > Result
Class type to contains a value (of type ValueType), or an error (of type ErrorType)