Connection Class Reference

Single TCP/IP connection manager. More...

#include <transport/transport.hh>

Inherits enable_shared_from_this< Connection >.

Public Types

typedef boost::function< void(const ConnectionPtr &)> AcceptCallback
 The signature of a connection accept callback. More...
 
typedef boost::function< void(const std::string &_data)> ReadCallback
 The signature of a connection read callback. More...
 

Public Member Functions

 Connection ()
 Constructor. More...
 
virtual ~Connection ()
 Destructor. More...
 
template<typename Handler >
void AsyncRead (Handler _handler)
 Peform an asyncronous read param[in] _handler Callback to invoke on received data. More...
 
void Cancel ()
 Cancel all async operations on an open socket. More...
 
bool Connect (const std::string &_host, unsigned int _port)
 Connect to a remote host. More...
 
event::ConnectionPtr ConnectToShutdown (boost::function< void()> _subscriber)
 Register a function to be called when the connection is shut down. More...
 
void EnqueueMsg (const std::string &_buffer, boost::function< void(uint32_t)> _cb, uint32_t _id, bool _force=false)
 Write data to the socket. More...
 
void EnqueueMsg (const std::string &_buffer, bool _force=false)
 Write data to the socket. More...
 
unsigned int GetId () const
 Get the ID of the connection. More...
 
std::string GetIPWhiteList () const
 Get the IP white list, from GAZEBO_IP_WHITE_LIST environment variable. More...
 
std::string GetLocalAddress () const
 Get the local address of this connection. More...
 
unsigned int GetLocalPort () const
 Get the port of this connection. More...
 
std::string GetLocalURI () const
 Get the local URI. More...
 
std::string GetRemoteAddress () const
 Get the remote address. More...
 
std::string GetRemoteHostname () const
 Get the remote hostname. More...
 
unsigned int GetRemotePort () const
 Get the remote port number. More...
 
std::string GetRemoteURI () const
 Get the remote URI. More...
 
bool IsOpen () const
 Is the connection open? More...
 
void Listen (unsigned int _port, const AcceptCallback &_acceptCB)
 Start a server that listens on a port. More...
 
void ProcessWriteQueue (bool _blocking=false)
 Handle on-write callbacks. More...
 
bool Read (std::string &_data)
 Read data from the socket. More...
 
void Shutdown ()
 Shutdown the socket. More...
 
void StartRead (const ReadCallback &_cb)
 Start a thread that reads from the connection and passes new message to the ReadCallback. More...
 
void StopRead ()
 Stop the read loop. More...
 

Static Public Member Functions

static std::string GetLocalHostname ()
 Get the local hostname. More...
 
static bool ValidateIP (const std::string &_ip)
 Return true if the _ip is a valid. More...
 

Detailed Description

Single TCP/IP connection manager.

Member Typedef Documentation

◆ AcceptCallback

typedef boost::function<void(const ConnectionPtr&)> AcceptCallback

The signature of a connection accept callback.

◆ ReadCallback

typedef boost::function<void(const std::string &_data)> ReadCallback

The signature of a connection read callback.

Constructor & Destructor Documentation

◆ Connection()

Constructor.

◆ ~Connection()

virtual ~Connection ( )
virtual

Destructor.

Member Function Documentation

◆ AsyncRead()

void AsyncRead ( Handler  _handler)
inline

Peform an asyncronous read param[in] _handler Callback to invoke on received data.

References gzerr, HEADER_LENGTH, gazebo::transport::is_stopped(), and gazebo::common::weakBind().

◆ Cancel()

void Cancel ( )

Cancel all async operations on an open socket.

◆ Connect()

bool Connect ( const std::string &  _host,
unsigned int  _port 
)

Connect to a remote host.

Parameters
[in]_hostThe host to connect to
[in]_portThe port to connect to
Returns
true if connection succeeded, false otherwise

◆ ConnectToShutdown()

event::ConnectionPtr ConnectToShutdown ( boost::function< void()>  _subscriber)
inline

Register a function to be called when the connection is shut down.

Parameters
[in]_subscriberFunction to be called
Returns
Handle that can be used to unregister the function

References gazebo::shutdown().

◆ EnqueueMsg() [1/2]

void EnqueueMsg ( const std::string &  _buffer,
boost::function< void(uint32_t)>  _cb,
uint32_t  _id,
bool  _force = false 
)

Write data to the socket.

Parameters
[in]_bufferData to write
[in]_forceIf true, block until the data has been written to the socket, otherwise just enqueue the data for asynchronous write
[in]_cbIf non-null, callback to be invoked after transmission is complete.
[in]_idID associated with the message data.

◆ EnqueueMsg() [2/2]

void EnqueueMsg ( const std::string &  _buffer,
bool  _force = false 
)

Write data to the socket.

Parameters
[in]_bufferData to write
[in]_forceIf true, block until the data has been written to the socket, otherwise just enqueue the data for asynchronous write

◆ GetId()

unsigned int GetId ( ) const

Get the ID of the connection.

Returns
The connection's unique ID.

◆ GetIPWhiteList()

std::string GetIPWhiteList ( ) const

Get the IP white list, from GAZEBO_IP_WHITE_LIST environment variable.

Returns
GAZEBO_IP_WHITE_LIST

◆ GetLocalAddress()

std::string GetLocalAddress ( ) const

Get the local address of this connection.

Returns
The local address

◆ GetLocalHostname()

static std::string GetLocalHostname ( )
static

Get the local hostname.

Returns
The local hostname

◆ GetLocalPort()

unsigned int GetLocalPort ( ) const

Get the port of this connection.

Returns
The local port

◆ GetLocalURI()

std::string GetLocalURI ( ) const

Get the local URI.

Returns
The local URI

◆ GetRemoteAddress()

std::string GetRemoteAddress ( ) const

Get the remote address.

Returns
The remote address

◆ GetRemoteHostname()

std::string GetRemoteHostname ( ) const

Get the remote hostname.

Returns
The remote hostname

◆ GetRemotePort()

unsigned int GetRemotePort ( ) const

Get the remote port number.

Returns
The remote port

◆ GetRemoteURI()

std::string GetRemoteURI ( ) const

Get the remote URI.

Returns
The remote URI

◆ IsOpen()

bool IsOpen ( ) const

Is the connection open?

Returns
true if the connection is open; false otherwise

◆ Listen()

void Listen ( unsigned int  _port,
const AcceptCallback _acceptCB 
)

Start a server that listens on a port.

Parameters
[in]_portThe port to listen on
[in]_acceptCBThe callback to invoke when a new connection has been accepted

◆ ProcessWriteQueue()

void ProcessWriteQueue ( bool  _blocking = false)

Handle on-write callbacks.

◆ Read()

bool Read ( std::string &  _data)

Read data from the socket.

Parameters
[out]_dataDestination for data that is read
Returns
true if data was successfully read, false otherwise

◆ Shutdown()

void Shutdown ( )

Shutdown the socket.

◆ StartRead()

void StartRead ( const ReadCallback _cb)

Start a thread that reads from the connection and passes new message to the ReadCallback.

Parameters
[in]_cbThe callback to invoke when a new message is received

◆ StopRead()

void StopRead ( )

Stop the read loop.

◆ ValidateIP()

static bool ValidateIP ( const std::string &  _ip)
static

Return true if the _ip is a valid.

Parameters
[in]_ipDotted quad to validate.
Returns
True if the _ip is a valid.

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