#include <tcp_connection.h>
|
static std::map< int, std::string > | type_to_name_map_ |
|
|
enum | State { NOT_STARTED = 0,
RUNNING = 1,
STOPPED = 2
} |
|
enum | SocketType { CLIENT = 0,
SERVER = 1
} |
|
|
State | state_ |
|
SocketType | socket_type_ |
|
std::shared_ptr< std::thread > | tcp_background_thread_ |
|
int | tcp_socket_ |
|
int | server_listen_socket_ |
|
uint64_t | msg_buf_size_ |
|
uint64_t | msg_length_buf_size_ |
|
std::shared_ptr< SafeQueue > | incoming_queue_ |
|
std::shared_ptr< SafeQueue > | outgoing_queue_ |
|
std::string | host_ |
|
std::string | port_ |
|
TCPConnection is used to pass data using Win-Sockets between the environment simulation and the TcpIoDevice object. It runs in a different thread and uses SafeQueues to pass data between the IODevice and the socket connection.
Definition at line 167 of file tcp_connection.h.
◆ TCPConnection()
tcp_io_device::TCPConnection::TCPConnection |
( |
std::shared_ptr< SafeQueue > |
receive_queue, |
|
|
std::shared_ptr< SafeQueue > |
send_queue, |
|
|
uint64_t |
msg_length_buf_size |
|
) |
| |
Constructor for the TCPConnection used in a seperate thread to communicate with the environment simulation
- Parameters
-
receive_queue | The queue used to pass incoming messages to the TcpIoDevice. |
send_queue | The queue used to pass outgoing messages from the TcpIoDevice. |
msg_length_buf_size | The number of bytes used to store the message length of the serialized protobuf message (should be 8) |
◆ establishConnection()
int tcp_io_device::TCPConnection::establishConnection |
( |
std::string |
host, |
|
|
std::string |
port |
|
) |
| |
Opens a socket to connect to a client on the passed port.
- Parameters
-
host | The host address used to communicate with the server. |
port | The port used to communicate with the server. |
- Returns
- 0 for success, nonzero for error.
◆ isRunning()
bool tcp_io_device::TCPConnection::isRunning |
( |
| ) |
|
|
inline |
◆ listenAndAwaitConnection()
int tcp_io_device::TCPConnection::listenAndAwaitConnection |
( |
std::string |
port | ) |
|
Listen on the passed port and wait for a client to connect.
- Parameters
-
port | The port used to communicate with the client. |
- Returns
- 0 for success, nonzero for error.
◆ receiveIsReady()
static int tcp_io_device::TCPConnection::receiveIsReady |
( |
int |
fd | ) |
|
|
static |
Check the socket if there is incoming data ready. This does not block.
- Parameters
-
fd | The socket file descriptor. |
- Returns
- 1 if data is ready, 0 if no data is ready, -1 for error.
◆ receiveMessage()
std::unique_ptr<TCPMessage> tcp_io_device::TCPConnection::receiveMessage |
( |
| ) |
|
|
protected |
Method to receive data from the socket and parse them into a TCPMessage
- Returns
- A unique_ptr to a TCPMessage for enqueuing it into the receive_queue_.
◆ sendMessage()
int tcp_io_device::TCPConnection::sendMessage |
( |
std::unique_ptr< TCPMessage > |
msg | ) |
|
|
protected |
Converts a message to a byte-stream and sends it to the client.
- Parameters
-
- Returns
- The number of bytes sent. If <= 0 an error occured while sending the message.
◆ start()
void tcp_io_device::TCPConnection::start |
( |
| ) |
|
Starts the communication between environment simulation and the AERA TCPConnection.
◆ stop()
void tcp_io_device::TCPConnection::stop |
( |
| ) |
|
◆ tcpBackgroundHandler()
void tcp_io_device::TCPConnection::tcpBackgroundHandler |
( |
| ) |
|
|
protected |
Handles the TCP connection in the background by checking for new outgoing and incoming messages, dequeueing and enqueueing the SafeQueues, respectively. Repeatedly checks for new messages on the socket and parses them to TCPMessage objects. Takes TCPMessage objects from the outgoing_queue_ and parses them into a byte-stream to send to the client.
The documentation for this class was generated from the following file: