Public Member Functions | Protected Member Functions | Protected Attributes | Private Attributes | List of all members
urcl::comm::TCPSocket Class Reference

Class for TCP socket abstraction. More...

#include <tcp_socket.h>

Inheritance diagram for urcl::comm::TCPSocket:
Inheritance graph
[legend]

Public Member Functions

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...
 
 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 ()
 

Protected Member Functions

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)
 

Protected Attributes

std::unique_ptr< timeval > recv_timeout_
 

Private Attributes

std::atomic< int > socket_fd_
 
std::atomic< SocketStatestate_
 

Detailed Description

Class for TCP socket abstraction.

Definition at line 48 of file tcp_socket.h.

Constructor & Destructor Documentation

urcl::comm::TCPSocket::TCPSocket ( )

Creates a TCPSocket object.

Definition at line 36 of file tcp_socket.cpp.

urcl::comm::TCPSocket::~TCPSocket ( )
virtual

Definition at line 39 of file tcp_socket.cpp.

Member Function Documentation

void urcl::comm::TCPSocket::close ( )

Closes the connection to the socket.

Definition at line 110 of file tcp_socket.cpp.

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 120 of file tcp_socket.cpp.

int urcl::comm::TCPSocket::getSocketFD ( )
inline

Getter for the file descriptor of the socket.

Returns
The file descriptor of the socket

Definition at line 87 of file tcp_socket.h.

SocketState urcl::comm::TCPSocket::getState ( )
inline

Getter for the state of the socket.

Returns
Returns the current state of the socket

Definition at line 77 of file tcp_socket.h.

virtual bool urcl::comm::TCPSocket::open ( int  socket_fd,
struct sockaddr *  address,
size_t  address_len 
)
inlineprotectedvirtual
bool urcl::comm::TCPSocket::read ( char *  character)

Reads one byte from the socket.

Parameters
[out]characterTarget buffer
Returns
True on success, false otherwise

Definition at line 137 of file tcp_socket.cpp.

bool urcl::comm::TCPSocket::read ( uint8_t *  buf,
const size_t  buf_len,
size_t &  read 
)

Reads data from the socket.

Parameters
[out]bufBuffer where the data shall be stored
[in]buf_lenNumber of bytes allocated for the buffer
[out]readNumber of bytes actually read
Returns
True on success, false otherwise

Definition at line 146 of file tcp_socket.cpp.

void urcl::comm::TCPSocket::setOptions ( int  socket_fd)
protectedvirtual

Definition at line 44 of file tcp_socket.cpp.

void urcl::comm::TCPSocket::setReceiveTimeout ( const timeval &  timeout)

Setup Receive timeout used for this socket.

Parameters
timeoutTimeout used for setting things up

Definition at line 197 of file tcp_socket.cpp.

bool urcl::comm::TCPSocket::setup ( std::string &  host,
int  port 
)
protected

Definition at line 56 of file tcp_socket.cpp.

bool urcl::comm::TCPSocket::write ( const uint8_t *  buf,
const size_t  buf_len,
size_t &  written 
)

Writes to the socket.

Parameters
[in]bufBuffer of bytes to write
[in]buf_lenNumber of bytes in the buffer
[out]writtenNumber of bytes actually written
Returns
True on success, false otherwise

Definition at line 167 of file tcp_socket.cpp.

Member Data Documentation

std::unique_ptr<timeval> urcl::comm::TCPSocket::recv_timeout_
protected

Definition at line 63 of file tcp_socket.h.

std::atomic<int> urcl::comm::TCPSocket::socket_fd_
private

Definition at line 51 of file tcp_socket.h.

std::atomic<SocketState> urcl::comm::TCPSocket::state_
private

Definition at line 52 of file tcp_socket.h.


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 Sun May 9 2021 02:16:26