DUNE: Uniform Navigational Environment  2022.04.1
Simulators::EvoSimulator::SafeTCPSocket Struct Reference

Detailed Description

TCPSocket wraper for the specific usecase.

Public Member Functions

 SafeTCPSocket (Tasks::Task *a_task, std::string a_name)
 
 SafeTCPSocket (Tasks::Task *a_task, std::string a_name, TCPSocket *a_sock)
 
 ~SafeTCPSocket ()
 
void startListen (uint16_t a_port, Address a_address, bool reuse, int backlog)
 
void connect (Address a_address, uint16_t a_port)
 
void reconnect ()
 
SafeTCPSocketaccept (std::string a_name)
 
bool poll (double timeout)
 
size_t read (uint8_t *data, size_t length)
 
size_t write (const char *data, size_t length)
 
size_t write (const uint8_t *data, size_t length)
 
size_t writeString (const std::string str)
 

Public Attributes

Tasks::Task * task
 
TCPSocket * sock
 
std::string name
 
uint16_t port
 
Address address
 

Constructor & Destructor Documentation

◆ SafeTCPSocket() [1/2]

Simulators::EvoSimulator::SafeTCPSocket::SafeTCPSocket ( Tasks::Task *  a_task,
std::string  a_name 
)
inline

Constructor for new socket.

Referenced by accept(), and Simulators::EvoSimulator::Task::onResourceAcquisition().

◆ SafeTCPSocket() [2/2]

Simulators::EvoSimulator::SafeTCPSocket::SafeTCPSocket ( Tasks::Task *  a_task,
std::string  a_name,
TCPSocket *  a_sock 
)
inline

Constructor for existing socket.

◆ ~SafeTCPSocket()

Simulators::EvoSimulator::SafeTCPSocket::~SafeTCPSocket ( )
inline

Destructor.

References sock.

Member Function Documentation

◆ accept()

SafeTCPSocket* Simulators::EvoSimulator::SafeTCPSocket::accept ( std::string  a_name)
inline

Accept connection from outside socket.

Parameters
[in]a_namename of new SafeTCPSocket
Returns
Safe

References SafeTCPSocket().

Referenced by Simulators::EvoSimulator::Task::checkSocket().

◆ connect()

void Simulators::EvoSimulator::SafeTCPSocket::connect ( Address  a_address,
uint16_t  a_port 
)
inline

Connect socket to remote port.

Parameters
[in]a_addressaddress of remote socket
[in]a_portport of remote socket

References port.

Referenced by Simulators::EvoSimulator::Task::checkReset(), Simulators::EvoSimulator::Task::onResourceAcquisition(), and reconnect().

◆ poll()

bool Simulators::EvoSimulator::SafeTCPSocket::poll ( double  timeout)
inline

Poll socket for reading.

Parameters
[in]timeouttime it waits for socket in seconds
Returns
true if there is something to read, false otherwise

Referenced by Simulators::EvoSimulator::Task::checkSocket(), Simulators::EvoSimulator::Task::transport(), and Simulators::EvoSimulator::Task::waitReply().

◆ read()

size_t Simulators::EvoSimulator::SafeTCPSocket::read ( uint8_t *  data,
size_t  length 
)
inline

Read from socket to buffer.

Parameters
[in]databuffer
[in]lengthnumber of bytes to read
Returns
number of bytes read

References reconnect().

Referenced by Simulators::EvoSimulator::Task::transport(), and Simulators::EvoSimulator::Task::waitReply().

◆ reconnect()

void Simulators::EvoSimulator::SafeTCPSocket::reconnect ( )
inline

Attempt reconnection to saved socket address.

References connect().

Referenced by read(), write(), and writeString().

◆ startListen()

void Simulators::EvoSimulator::SafeTCPSocket::startListen ( uint16_t  a_port,
Address  a_address,
bool  reuse,
int  backlog 
)
inline

Socket starts listening for connection requests.

Parameters
[in]a_portport to bind socket
[in]a_addressaddress to bind socket
[in]reuseflag to allow reuse of address
[in]backlognumber of connections allowed

Referenced by Simulators::EvoSimulator::Task::onResourceAcquisition().

◆ write() [1/2]

size_t Simulators::EvoSimulator::SafeTCPSocket::write ( const char *  data,
size_t  length 
)
inline

Write to socket.

Parameters
[in]datadata buffer
[in]lenghtnumber of bytes to write
Returns
number of bytes written

References reconnect().

Referenced by Simulators::EvoSimulator::Task::transport().

◆ write() [2/2]

size_t Simulators::EvoSimulator::SafeTCPSocket::write ( const uint8_t *  data,
size_t  length 
)
inline

Write to socket.

Parameters
[in]datadata buffer
[in]lenghtnumber of bytes to write
Returns
number of bytes written

References reconnect().

◆ writeString()

size_t Simulators::EvoSimulator::SafeTCPSocket::writeString ( const std::string  str)
inline

Write string to socket.

Parameters
[in]strstring to write
Returns
number of bytes written

References reconnect().

Referenced by Simulators::EvoSimulator::Task::sendSetting(), and Simulators::EvoSimulator::Task::updateState().

Member Data Documentation

◆ address

Address Simulators::EvoSimulator::SafeTCPSocket::address

Address used in case of connection.

Referenced by Simulators::EvoSimulator::Task::autoAssign().

◆ name

std::string Simulators::EvoSimulator::SafeTCPSocket::name

◆ port

uint16_t Simulators::EvoSimulator::SafeTCPSocket::port

Port used in case of connection.

Referenced by connect().

◆ sock

TCPSocket* Simulators::EvoSimulator::SafeTCPSocket::sock

◆ task

Tasks::Task* Simulators::EvoSimulator::SafeTCPSocket::task

Handle to task using the wraper.

Collaboration diagram for Simulators::EvoSimulator::SafeTCPSocket:
Collaboration graph