Single TCP/IP connection manager. More...
#include <transport/transport.hh>

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 | DisconnectShutdown (event::ConnectionPtr _subscriber) |
| Unregister 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... | |
Single TCP/IP connection manager.
| typedef boost::function<void(const ConnectionPtr&)> gazebo::transport::Connection::AcceptCallback |
The signature of a connection accept callback.
| typedef boost::function<void(const std::string &_data)> gazebo::transport::Connection::ReadCallback |
The signature of a connection read callback.
| gazebo::transport::Connection::Connection | ( | ) |
Constructor.
|
virtual |
Destructor.
|
inline |
Peform an asyncronous read param[in] _handler Callback to invoke on received data.
References gzerr, and HEADER_LENGTH.
| void gazebo::transport::Connection::Cancel | ( | ) |
Cancel all async operations on an open socket.
| bool gazebo::transport::Connection::Connect | ( | const std::string & | _host, |
| unsigned int | _port | ||
| ) |
Connect to a remote host.
| [in] | _host | The host to connect to |
| [in] | _port | The port to connect to |
|
inline |
Register a function to be called when the connection is shut down.
| [in] | _subscriber | Function to be called |
References gazebo::shutdown().
|
inline |
Unregister a function to be called when the connection is shut down.
| [in] | _subscriber | Handle previously returned by ConnectToShutdown() |
References gazebo::shutdown().
| void gazebo::transport::Connection::EnqueueMsg | ( | const std::string & | _buffer, |
| boost::function< void(uint32_t)> | _cb, | ||
| uint32_t | _id, | ||
| bool | _force = false |
||
| ) |
Write data to the socket.
| [in] | _buffer | Data to write |
| [in] | _force | If true, block until the data has been written to the socket, otherwise just enqueue the data for asynchronous write |
| [in] | _cb | If non-null, callback to be invoked after transmission is complete. |
| [in] | _id | ID associated with the message data. |
| void gazebo::transport::Connection::EnqueueMsg | ( | const std::string & | _buffer, |
| bool | _force = false |
||
| ) |
Write data to the socket.
| [in] | _buffer | Data to write |
| [in] | _force | If true, block until the data has been written to the socket, otherwise just enqueue the data for asynchronous write |
| unsigned int gazebo::transport::Connection::GetId | ( | ) | const |
Get the ID of the connection.
| std::string gazebo::transport::Connection::GetIPWhiteList | ( | ) | const |
Get the IP white list, from GAZEBO_IP_WHITE_LIST environment variable.
| std::string gazebo::transport::Connection::GetLocalAddress | ( | ) | const |
Get the local address of this connection.
|
static |
Get the local hostname.
| unsigned int gazebo::transport::Connection::GetLocalPort | ( | ) | const |
Get the port of this connection.
| std::string gazebo::transport::Connection::GetLocalURI | ( | ) | const |
Get the local URI.
| std::string gazebo::transport::Connection::GetRemoteAddress | ( | ) | const |
Get the remote address.
| std::string gazebo::transport::Connection::GetRemoteHostname | ( | ) | const |
Get the remote hostname.
| unsigned int gazebo::transport::Connection::GetRemotePort | ( | ) | const |
Get the remote port number.
| std::string gazebo::transport::Connection::GetRemoteURI | ( | ) | const |
Get the remote URI.
| bool gazebo::transport::Connection::IsOpen | ( | ) | const |
Is the connection open?
| void gazebo::transport::Connection::Listen | ( | unsigned int | _port, |
| const AcceptCallback & | _acceptCB | ||
| ) |
Start a server that listens on a port.
| [in] | _port | The port to listen on |
| [in] | _acceptCB | The callback to invoke when a new connection has been accepted |
| void gazebo::transport::Connection::ProcessWriteQueue | ( | bool | _blocking = false | ) |
Handle on-write callbacks.
| bool gazebo::transport::Connection::Read | ( | std::string & | _data | ) |
Read data from the socket.
| [out] | _data | Destination for data that is read |
| void gazebo::transport::Connection::Shutdown | ( | ) |
Shutdown the socket.
| void gazebo::transport::Connection::StartRead | ( | const ReadCallback & | _cb | ) |
Start a thread that reads from the connection and passes new message to the ReadCallback.
| [in] | _cb | The callback to invoke when a new message is received |
| void gazebo::transport::Connection::StopRead | ( | ) |
Stop the read loop.
|
static |
Return true if the _ip is a valid.
| [in] | _ip | Dotted quad to validate. |