Classes | Public Member Functions | List of all members
ndn::AsyncTcpTransport Class Reference

AsyncTcpTransport extends Transport for async communication over TCP using Boost's asio io_service. More...

#include <async-tcp-transport.hpp>

Inheritance diagram for ndn::AsyncTcpTransport:
ndn::Transport

Classes

class  ConnectionInfo
 An AsyncTcpTransport::ConnectionInfo extends Transport::ConnectionInfo to hold the host and port info for the TCP connection. More...
 

Public Member Functions

 AsyncTcpTransport (boost::asio::io_service &ioService)
 Create an AsyncTcpTransport in the unconnected state. More...
 
virtual bool isLocal (const Transport::ConnectionInfo &connectionInfo)
 Determine whether this transport connecting according to connectionInfo is to a node on the current machine; results are cached. More...
 
virtual bool isAsync ()
 Override to return true since connect needs to use the onConnected callback. More...
 
virtual void connect (const Transport::ConnectionInfo &connectionInfo, ElementListener &elementListener, const OnConnected &onConnected)
 Connect according to the info in connectionInfo, and use elementListener. More...
 
virtual void send (const uint8_t *data, size_t dataLength)
 Send data to the host. More...
 
virtual void processEvents ()
 Do nothing since the asio io_service reads the socket.
 
virtual bool getIsConnected ()
 
virtual void close ()
 Close the connection to the host.
 
- Public Member Functions inherited from ndn::Transport
void send (const std::vector< uint8_t > &data)
 

Additional Inherited Members

- Public Types inherited from ndn::Transport
typedef func_lib::function< void()> OnConnected
 

Detailed Description

AsyncTcpTransport extends Transport for async communication over TCP using Boost's asio io_service.

This only uses asio for communication. To make this thread-safe, you must dispatch calls to send(), etc. to the io_service, as is done by ThreadsafeFace. To use this, you do not need to call processEvents.

Constructor & Destructor Documentation

ndn::AsyncTcpTransport::AsyncTcpTransport ( boost::asio::io_service &  ioService)

Create an AsyncTcpTransport in the unconnected state.

This will use the ioService to create the connection and communicate asynchronously.

Parameters
ioServiceThe asio io_service. It is the responsibility of the application to start and stop the service.

Member Function Documentation

virtual void ndn::AsyncTcpTransport::connect ( const Transport::ConnectionInfo connectionInfo,
ElementListener elementListener,
const OnConnected &  onConnected 
)
virtual

Connect according to the info in connectionInfo, and use elementListener.

To be thread-safe, this must be called from a dispatch to the ioService which was given to the constructor, as is done by ThreadsafeFace.

Parameters
connectionInfoA reference to an AsyncTcpTransport::ConnectionInfo.
elementListenerNot a shared_ptr because we assume that it will remain valid during the life of this object.
onConnectedThis calls onConnected() when the connection is established.

Reimplemented from ndn::Transport.

virtual bool ndn::AsyncTcpTransport::isAsync ( )
virtual

Override to return true since connect needs to use the onConnected callback.

Returns
True.

Reimplemented from ndn::Transport.

virtual bool ndn::AsyncTcpTransport::isLocal ( const Transport::ConnectionInfo connectionInfo)
virtual

Determine whether this transport connecting according to connectionInfo is to a node on the current machine; results are cached.

According to http://redmine.named-data.net/projects/nfd/wiki/ScopeControl#local-face, TCP transports with a loopback address are local. If connectionInfo contains a host name, this will do a blocking DNS lookup; otherwise this will parse the IP address and examine the first octet to determine if it is a loopback address (e.g. the first IPv4 octet is 127 or IPv6 is "::1").

Parameters
connectionInfoA TcpTransport.ConnectionInfo with the host to check.
Returns
True if the host is local, false if not.

Reimplemented from ndn::Transport.

virtual void ndn::AsyncTcpTransport::send ( const uint8_t *  data,
size_t  dataLength 
)
virtual

Send data to the host.

To be thread-safe, this must be called from a dispatch to the ioService which was given to the constructor, as is done by ThreadsafeFace.

Parameters
dataA pointer to the buffer of data to send.
dataLengthThe number of bytes in data.

Reimplemented from ndn::Transport.


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