Public Member Functions | Static Public Member Functions | List of all members
ndn::TcpTransportLite Class Reference
Inheritance diagram for ndn::TcpTransportLite:
ndn_TcpTransport

Public Member Functions

 TcpTransportLite (DynamicUInt8ArrayLite &buffer)
 Create a TcpTransport with default values for no connection yet and to use the given DynamicUInt8ArrayLite buffer for the ElementReader. More...
 
ndn_Error isLocal (const char *host, bool &result)
 Determine whether this transport connecting to the host is to a node on the current machine; results are not cached. More...
 
ndn_Error connect (const char *host, unsigned short port, ElementListenerLite &elementListener)
 Connect with TCP to the host:port. More...
 
ndn_Error send (const uint8_t *data, size_t dataLength)
 Send data to the socket. More...
 
ndn_Error processEvents (uint8_t *buffer, size_t bufferLength)
 Process any data to receive. More...
 
ndn_Error close ()
 Close the socket. More...
 

Static Public Member Functions

static TcpTransportLitedownCast (ndn_TcpTransport &transport)
 Downcast the reference to the ndn_TcpTransport struct to a TcpTransportLite. More...
 
static const TcpTransportLitedownCast (const ndn_TcpTransport &transport)
 

Constructor & Destructor Documentation

ndn::TcpTransportLite::TcpTransportLite ( DynamicUInt8ArrayLite buffer)

Create a TcpTransport with default values for no connection yet and to use the given DynamicUInt8ArrayLite buffer for the ElementReader.

Note that the ElementReader is not valid until you call connect.

Parameters
bufferA DynamicUInt8ArrayLite which is used to save data before calling the elementListener (see connect). The object must remain valid during the entire life of this object. If the reallocFunction given to buffer's constructor is 0, then its array must be large enough to save a full element, perhaps MAX_NDN_PACKET_SIZE bytes.

Member Function Documentation

ndn_Error ndn::TcpTransportLite::close ( )

Close the socket.

Returns
0 for success, else an error code.
ndn_Error ndn::TcpTransportLite::connect ( const char *  host,
unsigned short  port,
ElementListenerLite elementListener 
)

Connect with TCP to the host:port.

Parameters
hostThe host to connect to.
portThe port to connect to.
elementListenerThe ElementListenerLite whose onReceivedElement callback is called by processEvents. The elementListener must remain valid during the life of this object or until replaced by the next call to connect.
Returns
0 for success, else an error code.
static TcpTransportLite& ndn::TcpTransportLite::downCast ( ndn_TcpTransport transport)
inlinestatic

Downcast the reference to the ndn_TcpTransport struct to a TcpTransportLite.

Parameters
transportA reference to the ndn_TcpTransport struct.
Returns
The same reference as TcpTransportLite.
ndn_Error ndn::TcpTransportLite::isLocal ( const char *  host,
bool &  result 
)

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

According to http://redmine.named-data.net/projects/nfd/wiki/ScopeControl#local-face, TCP transports with a loopback address are local. If host is 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
hostThe host to check.
resultSet result to true if the host is local, false if not.
Returns
0 for success, else an error code.
ndn_Error ndn::TcpTransportLite::processEvents ( uint8_t *  buffer,
size_t  bufferLength 
)

Process any data to receive.

For each element received, call (*elementListener->onReceivedElement)(element, elementLength) for the elementListener in the elementReader given to connect(). This is non-blocking and will return immediately if there is no data to receive.

Parameters
bufferA pointer to a buffer for receiving data. Note that this is only for temporary use and is not the way that this function supplies data. It supplies the data by calling the onReceivedElement callback.
bufferLengthThe size of buffer. The buffer should be as large as resources permit up to MAX_NDN_PACKET_SIZE, but smaller sizes will work however may be less efficient due to multiple calls to socket receive and more processing by the ElementReader.
Returns
0 for success, else an error code.
ndn_Error ndn::TcpTransportLite::send ( const uint8_t *  data,
size_t  dataLength 
)

Send data to the socket.

Parameters
dataA pointer to the buffer of data to send.
dataLengthThe number of bytes in data.
Returns
0 for success, else an error code.

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