Class TcpInterface

Inheritance Relationships

Base Type

Class Documentation

class TcpInterface : public network_bridge::NetworkInterface

Represents a TCP network interface.

The TcpInterface class is a concrete implementation of the NetworkInterface abstract class. It provides functionality for opening, closing, receiving and writing data to a TCP interface. It also handles receiving data asynchronously and provides error handling capabilities.

Public Functions

inline TcpInterface()
inline virtual ~TcpInterface()
virtual bool has_failed() const override

Checks if the network connection has failed.

This method should be implemented by derived classes and return true if the connection needs to be reinitialised

virtual bool is_ready() const override

Checks if the network connection is ready.

This method should be implemented by derived classes and return true when the connection has been opened and has not failed

virtual void open() override

Opens the network connection.

This method should be implemented by derived classes to establish the network connection. Should handle all network setup, including sockets, starting threads, etc

virtual void close() override

Closes the network connection.

This method should be implemented by derived classes to close the network connection. Cleanly stop threads, close sockets, etc.

virtual void write(const std::vector<uint8_t> &data) override

Writes data to the network.

This method should be implemented by derived classes to send data over the network.

Parameters:

data – The data to be written.

Protected Functions

virtual void initialize_() override

Initializes interface by loading parameters.

Called from NetworkInterface::initialize()

void load_parameters()
void setup_server()
void setup_client()
void start_receive()
void receive(const boost::system::error_code &error, size_t rlen)
void receive_thread()
void error_handler(const boost::system::error_code &ec, const std::string &error_message, bool fatal = false)

Handles errors from the UDP interface.

Parameters:
  • ec – The error code from the operation.

  • error_message – The error message to log.

  • fatal – Whether the error is fatal.