Class for TCP socket abstraction.
More...
#include <tcp_socket.h>
|
void | close () |
| Closes the connection to the socket. More...
|
|
std::string | getIP () const |
| Determines the local IP address of the currently configured socket. More...
|
|
int | getSocketFD () |
| Getter for the file descriptor of the socket. More...
|
|
SocketState | getState () |
| Getter for the state of the socket. More...
|
|
bool | read (char *character) |
| Reads one byte from the socket. More...
|
|
bool | read (uint8_t *buf, const size_t buf_len, size_t &read) |
| Reads data from the socket. More...
|
|
void | setReceiveTimeout (const timeval &timeout) |
| Setup Receive timeout used for this socket. More...
|
|
void | setReconnectionTime (std::chrono::seconds reconnection_time) |
| Set reconnection time, if the server is unavailable during connection this will set the time before trying connect to the server again. More...
|
|
| TCPSocket () |
| Creates a TCPSocket object. More...
|
|
bool | write (const uint8_t *buf, const size_t buf_len, size_t &written) |
| Writes to the socket. More...
|
|
virtual | ~TCPSocket () |
|
|
virtual bool | open (int socket_fd, struct sockaddr *address, size_t address_len) |
|
virtual void | setOptions (int socket_fd) |
|
bool | setup (std::string &host, int port) |
|
Class for TCP socket abstraction.
Definition at line 48 of file tcp_socket.h.
◆ TCPSocket()
urcl::comm::TCPSocket::TCPSocket |
( |
| ) |
|
◆ ~TCPSocket()
urcl::comm::TCPSocket::~TCPSocket |
( |
| ) |
|
|
virtual |
◆ close()
void urcl::comm::TCPSocket::close |
( |
| ) |
|
◆ getIP()
std::string urcl::comm::TCPSocket::getIP |
( |
| ) |
const |
Determines the local IP address of the currently configured socket.
- Returns
- The local IP address of the socket associated to the current file descriptor
Definition at line 126 of file tcp_socket.cpp.
◆ getSocketFD()
int urcl::comm::TCPSocket::getSocketFD |
( |
| ) |
|
|
inline |
Getter for the file descriptor of the socket.
- Returns
- The file descriptor of the socket
Definition at line 88 of file tcp_socket.h.
◆ getState()
Getter for the state of the socket.
- Returns
- Returns the current state of the socket
Definition at line 78 of file tcp_socket.h.
◆ open()
virtual bool urcl::comm::TCPSocket::open |
( |
int |
socket_fd, |
|
|
struct sockaddr * |
address, |
|
|
size_t |
address_len |
|
) |
| |
|
inlineprotectedvirtual |
◆ read() [1/2]
bool urcl::comm::TCPSocket::read |
( |
char * |
character | ) |
|
Reads one byte from the socket.
- Parameters
-
[out] | character | Target buffer |
- Returns
- True on success, false otherwise
Definition at line 143 of file tcp_socket.cpp.
◆ read() [2/2]
bool urcl::comm::TCPSocket::read |
( |
uint8_t * |
buf, |
|
|
const size_t |
buf_len, |
|
|
size_t & |
read |
|
) |
| |
Reads data from the socket.
- Parameters
-
[out] | buf | Buffer where the data shall be stored |
[in] | buf_len | Number of bytes allocated for the buffer |
[out] | read | Number of bytes actually read |
- Returns
- True on success, false otherwise
Definition at line 152 of file tcp_socket.cpp.
◆ setOptions()
void urcl::comm::TCPSocket::setOptions |
( |
int |
socket_fd | ) |
|
|
protectedvirtual |
◆ setReceiveTimeout()
void urcl::comm::TCPSocket::setReceiveTimeout |
( |
const timeval & |
timeout | ) |
|
Setup Receive timeout used for this socket.
- Parameters
-
timeout | Timeout used for setting things up |
Definition at line 203 of file tcp_socket.cpp.
◆ setReconnectionTime()
void urcl::comm::TCPSocket::setReconnectionTime |
( |
std::chrono::seconds |
reconnection_time | ) |
|
|
inline |
Set reconnection time, if the server is unavailable during connection this will set the time before trying connect to the server again.
- Parameters
-
reconnection_time | time in between connection attempts to the server |
Definition at line 149 of file tcp_socket.h.
◆ setup()
bool urcl::comm::TCPSocket::setup |
( |
std::string & |
host, |
|
|
int |
port |
|
) |
| |
|
protected |
◆ write()
bool urcl::comm::TCPSocket::write |
( |
const uint8_t * |
buf, |
|
|
const size_t |
buf_len, |
|
|
size_t & |
written |
|
) |
| |
Writes to the socket.
- Parameters
-
[in] | buf | Buffer of bytes to write |
[in] | buf_len | Number of bytes in the buffer |
[out] | written | Number of bytes actually written |
- Returns
- True on success, false otherwise
Definition at line 173 of file tcp_socket.cpp.
◆ reconnection_time_
std::chrono::seconds urcl::comm::TCPSocket::reconnection_time_ |
|
private |
◆ recv_timeout_
std::unique_ptr<timeval> urcl::comm::TCPSocket::recv_timeout_ |
|
protected |
◆ socket_fd_
std::atomic<int> urcl::comm::TCPSocket::socket_fd_ |
|
private |
◆ state_
The documentation for this class was generated from the following files:
ur_client_library
Author(s): Thomas Timm Andersen, Simon Rasmussen, Felix Exner, Lea Steffen, Tristan Schnell
autogenerated on Tue Jul 4 2023 02:09:47