Public Types | Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes | List of all members
roswrap::TransportTCP Class Reference

TCPROS transport. More...

#include <transport_tcp.h>

Inheritance diagram for roswrap::TransportTCP:
Inheritance graph
[legend]

Public Types

typedef std::function< void(const TransportTCPPtr &)> AcceptCallback
 
enum  Flags { SYNCHRONOUS = 1<<0 }
 
- Public Types inherited from roswrap::Transport
typedef std::function< void(const TransportPtr &)> Callback
 

Public Member Functions

TransportTCPPtr accept ()
 Accept a connection on a server socket. Blocks until a connection is available. More...
 
virtual void close ()
 Close this transport. Once this call has returned, writing on this transport should always return an error. More...
 
bool connect (const std::string &host, int port)
 Connect to a remote host. More...
 
virtual void disableRead ()
 Disable reading on this transport. Allows derived classes to, for example, disable read polling for asynchronous sockets. More...
 
virtual void disableWrite ()
 Disable writing on this transport. Allows derived classes to, for example, disable write polling for asynchronous sockets. More...
 
virtual void enableRead ()
 Enable reading on this transport. Allows derived classes to, for example, enable read polling for asynchronous sockets. More...
 
virtual void enableWrite ()
 Enable writing on this transport. Allows derived classes to, for example, enable write polling for asynchronous sockets. More...
 
std::string getClientURI ()
 Returns the URI of the remote host. More...
 
const std::string & getConnectedHost ()
 
int getConnectedPort ()
 
int getLocalPort ()
 
int getServerPort ()
 Returns the port this transport is listening on. More...
 
virtual std::string getTransportInfo ()
 Returns a string description of both the type of transport and who the transport is connected to. More...
 
virtual const char * getType ()
 Return a string that details the type of transport (Eg. TCPROS) More...
 
bool listen (int port, int backlog, const AcceptCallback &accept_cb)
 Start a server socket and listen on a port. More...
 
virtual void parseHeader (const Header &header)
 Provides an opportunity for transport-specific options to come in through the header. More...
 
virtual int32_t read (uint8_t *buffer, uint32_t size)
 Read a number of bytes into the supplied buffer. Not guaranteed to actually read that number of bytes. More...
 
void setKeepAlive (bool use, uint32_t idle, uint32_t interval, uint32_t count)
 
void setNoDelay (bool nodelay)
 
 TransportTCP (PollSet *poll_set, int flags=0)
 
virtual int32_t write (uint8_t *buffer, uint32_t size)
 Write a number of bytes from the supplied buffer. Not guaranteed to actually write that number of bytes. More...
 
virtual ~TransportTCP ()
 
- Public Member Functions inherited from roswrap::Transport
virtual bool requiresHeader ()
 Returns a boolean to indicate if the transport mechanism is reliable or not. More...
 
void setDisconnectCallback (const Callback &cb)
 Set the function to call when this transport has disconnected, either through a call to close(). Or a disconnect from the remote host. More...
 
void setReadCallback (const Callback &cb)
 Set the function to call when there is data available to be read by this transport. More...
 
void setWriteCallback (const Callback &cb)
 Set the function to call when there is space available to write on this transport. More...
 
 Transport ()
 
virtual ~Transport ()
 

Static Public Attributes

static bool s_use_ipv6_
 
static bool s_use_keepalive_
 

Private Member Functions

bool initializeSocket ()
 Initializes the assigned socket – sets it to non-blocking and enables reading. More...
 
bool setNonBlocking ()
 
bool setSocket (int sock)
 Set the socket to be used by this transport. More...
 
void socketUpdate (int events)
 

Private Attributes

AcceptCallback accept_cb_
 
std::string cached_remote_host_
 
boost::recursive_mutex close_mutex_
 
bool closed_
 
std::string connected_host_
 
int connected_port_
 
bool expecting_read_
 
bool expecting_write_
 
int flags_
 
bool is_server_
 
socklen_t la_len_
 
sockaddr_storage local_address_
 
int local_port_
 
PollSetpoll_set_
 
socklen_t sa_len_
 
sockaddr_storage server_address_
 
int server_port_
 
socket_fd_t sock_
 

Additional Inherited Members

- Protected Member Functions inherited from roswrap::Transport
bool isHostAllowed (const std::string &host) const
 returns true if the transport is allowed to connect to the host passed to it. More...
 
bool isOnlyLocalhostAllowed () const
 returns true if this transport is only allowed to talk to localhost More...
 
- Protected Attributes inherited from roswrap::Transport
Callback disconnect_cb_
 
Callback read_cb_
 
Callback write_cb_
 

Detailed Description

TCPROS transport.

Definition at line 57 of file transport_tcp.h.

Member Typedef Documentation

◆ AcceptCallback

Definition at line 85 of file transport_tcp.h.

Member Enumeration Documentation

◆ Flags

Enumerator
SYNCHRONOUS 

Definition at line 64 of file transport_tcp.h.

Constructor & Destructor Documentation

◆ TransportTCP()

roswrap::TransportTCP::TransportTCP ( PollSet poll_set,
int  flags = 0 
)

◆ ~TransportTCP()

virtual roswrap::TransportTCP::~TransportTCP ( )
virtual

Member Function Documentation

◆ accept()

TransportTCPPtr roswrap::TransportTCP::accept ( )

Accept a connection on a server socket. Blocks until a connection is available.

◆ close()

virtual void roswrap::TransportTCP::close ( )
virtual

Close this transport. Once this call has returned, writing on this transport should always return an error.

Implements roswrap::Transport.

◆ connect()

bool roswrap::TransportTCP::connect ( const std::string &  host,
int  port 
)

Connect to a remote host.

Parameters
hostThe hostname/IP to connect to
portThe port to connect to
Returns
Whether or not the connection was successful

◆ disableRead()

virtual void roswrap::TransportTCP::disableRead ( )
virtual

Disable reading on this transport. Allows derived classes to, for example, disable read polling for asynchronous sockets.

Implements roswrap::Transport.

◆ disableWrite()

virtual void roswrap::TransportTCP::disableWrite ( )
virtual

Disable writing on this transport. Allows derived classes to, for example, disable write polling for asynchronous sockets.

Implements roswrap::Transport.

◆ enableRead()

virtual void roswrap::TransportTCP::enableRead ( )
virtual

Enable reading on this transport. Allows derived classes to, for example, enable read polling for asynchronous sockets.

Implements roswrap::Transport.

◆ enableWrite()

virtual void roswrap::TransportTCP::enableWrite ( )
virtual

Enable writing on this transport. Allows derived classes to, for example, enable write polling for asynchronous sockets.

Implements roswrap::Transport.

◆ getClientURI()

std::string roswrap::TransportTCP::getClientURI ( )

Returns the URI of the remote host.

◆ getConnectedHost()

const std::string& roswrap::TransportTCP::getConnectedHost ( )
inline

Definition at line 106 of file transport_tcp.h.

◆ getConnectedPort()

int roswrap::TransportTCP::getConnectedPort ( )
inline

Definition at line 107 of file transport_tcp.h.

◆ getLocalPort()

int roswrap::TransportTCP::getLocalPort ( )
inline

Definition at line 101 of file transport_tcp.h.

◆ getServerPort()

int roswrap::TransportTCP::getServerPort ( )
inline

Returns the port this transport is listening on.

Definition at line 100 of file transport_tcp.h.

◆ getTransportInfo()

virtual std::string roswrap::TransportTCP::getTransportInfo ( )
virtual

Returns a string description of both the type of transport and who the transport is connected to.

Implements roswrap::Transport.

◆ getType()

virtual const char* roswrap::TransportTCP::getType ( )
inlinevirtual

Return a string that details the type of transport (Eg. TCPROS)

Returns
The stringified transport type

Implements roswrap::Transport.

Definition at line 124 of file transport_tcp.h.

◆ initializeSocket()

bool roswrap::TransportTCP::initializeSocket ( )
private

Initializes the assigned socket – sets it to non-blocking and enables reading.

◆ listen()

bool roswrap::TransportTCP::listen ( int  port,
int  backlog,
const AcceptCallback accept_cb 
)

Start a server socket and listen on a port.

Parameters
portThe port to listen on
backlogdefines the maximum length for the queue of pending connections. Identical to the backlog parameter to the ::listen function
accept_cbThe function to call when a client socket has connected

◆ parseHeader()

virtual void roswrap::TransportTCP::parseHeader ( const Header header)
virtual

Provides an opportunity for transport-specific options to come in through the header.

Reimplemented from roswrap::Transport.

◆ read()

virtual int32_t roswrap::TransportTCP::read ( uint8_t *  buffer,
uint32_t  size 
)
virtual

Read a number of bytes into the supplied buffer. Not guaranteed to actually read that number of bytes.

Parameters
bufferBuffer to read from
sizeSize, in bytes, to read
Returns
The number of bytes actually read, or -1 if there was an error

Implements roswrap::Transport.

◆ setKeepAlive()

void roswrap::TransportTCP::setKeepAlive ( bool  use,
uint32_t  idle,
uint32_t  interval,
uint32_t  count 
)

◆ setNoDelay()

void roswrap::TransportTCP::setNoDelay ( bool  nodelay)

◆ setNonBlocking()

bool roswrap::TransportTCP::setNonBlocking ( )
private

◆ setSocket()

bool roswrap::TransportTCP::setSocket ( int  sock)
private

Set the socket to be used by this transport.

Parameters
sockA valid TCP socket
Returns
Whether setting the socket was successful

◆ socketUpdate()

void roswrap::TransportTCP::socketUpdate ( int  events)
private

◆ write()

virtual int32_t roswrap::TransportTCP::write ( uint8_t *  buffer,
uint32_t  size 
)
virtual

Write a number of bytes from the supplied buffer. Not guaranteed to actually write that number of bytes.

Parameters
bufferBuffer to write from
sizeSize, in bytes, to write
Returns
The number of bytes actually written, or -1 if there was an error

Implements roswrap::Transport.

Member Data Documentation

◆ accept_cb_

AcceptCallback roswrap::TransportTCP::accept_cb_
private

Definition at line 158 of file transport_tcp.h.

◆ cached_remote_host_

std::string roswrap::TransportTCP::cached_remote_host_
private

Definition at line 160 of file transport_tcp.h.

◆ close_mutex_

boost::recursive_mutex roswrap::TransportTCP::close_mutex_
private

Definition at line 145 of file transport_tcp.h.

◆ closed_

bool roswrap::TransportTCP::closed_
private

Definition at line 144 of file transport_tcp.h.

◆ connected_host_

std::string roswrap::TransportTCP::connected_host_
private

Definition at line 165 of file transport_tcp.h.

◆ connected_port_

int roswrap::TransportTCP::connected_port_
private

Definition at line 166 of file transport_tcp.h.

◆ expecting_read_

bool roswrap::TransportTCP::expecting_read_
private

Definition at line 147 of file transport_tcp.h.

◆ expecting_write_

bool roswrap::TransportTCP::expecting_write_
private

Definition at line 148 of file transport_tcp.h.

◆ flags_

int roswrap::TransportTCP::flags_
private

Definition at line 163 of file transport_tcp.h.

◆ is_server_

bool roswrap::TransportTCP::is_server_
private

Definition at line 150 of file transport_tcp.h.

◆ la_len_

socklen_t roswrap::TransportTCP::la_len_
private

Definition at line 154 of file transport_tcp.h.

◆ local_address_

sockaddr_storage roswrap::TransportTCP::local_address_
private

Definition at line 153 of file transport_tcp.h.

◆ local_port_

int roswrap::TransportTCP::local_port_
private

Definition at line 157 of file transport_tcp.h.

◆ poll_set_

PollSet* roswrap::TransportTCP::poll_set_
private

Definition at line 162 of file transport_tcp.h.

◆ s_use_ipv6_

bool roswrap::TransportTCP::s_use_ipv6_
static

Definition at line 61 of file transport_tcp.h.

◆ s_use_keepalive_

bool roswrap::TransportTCP::s_use_keepalive_
static

Definition at line 60 of file transport_tcp.h.

◆ sa_len_

socklen_t roswrap::TransportTCP::sa_len_
private

Definition at line 152 of file transport_tcp.h.

◆ server_address_

sockaddr_storage roswrap::TransportTCP::server_address_
private

Definition at line 151 of file transport_tcp.h.

◆ server_port_

int roswrap::TransportTCP::server_port_
private

Definition at line 156 of file transport_tcp.h.

◆ sock_

socket_fd_t roswrap::TransportTCP::sock_
private

Definition at line 143 of file transport_tcp.h.


The documentation for this class was generated from the following file:


sick_scan_xd
Author(s): Michael Lehning , Jochen Sprickerhof , Martin Günther
autogenerated on Fri Oct 25 2024 02:47:15