ndn::TcpTransport Class Reference

a transport using TCP socket More...

#include <tcp-transport.hpp>

+ Inheritance diagram for ndn::TcpTransport:
+ Collaboration diagram for ndn::TcpTransport:

Public Types

typedef function< void()> ErrorCallback
 
typedef function< void(const Block &wire)> ReceiveCallback
 

Public Member Functions

 TcpTransport (const std::string &host, const std::string &port="6363")
 
 ~TcpTransport () override
 
void close () override
 Close the connection. More...
 
void connect (boost::asio::io_service &ioService, const ReceiveCallback &receiveCallback) override
 asynchronously open the connection More...
 
bool isConnected () const
 
bool isReceiving () const
 
void pause () override
 pause the transport More...
 
void resume () override
 resume the transport More...
 
void send (const Block &wire) override
 send a TLV block through the transport More...
 
void send (const Block &header, const Block &payload) override
 send two memory blocks through the transport More...
 

Static Public Member Functions

static shared_ptr< TcpTransportcreate (const std::string &uri)
 Create transport with parameters defined in URI. More...
 

Protected Member Functions

void receive (const Block &wire)
 invoke the receive callback More...
 

Protected Attributes

boost::asio::io_service * m_ioService
 
bool m_isConnected
 
bool m_isReceiving
 
ReceiveCallback m_receiveCallback
 

Friends

class StreamTransportImpl< TcpTransport, boost::asio::ip::tcp >
 

Detailed Description

a transport using TCP socket

Definition at line 40 of file tcp-transport.hpp.

Member Typedef Documentation

typedef function<void()> ndn::Transport::ErrorCallback
inherited

Definition at line 48 of file transport.hpp.

typedef function<void(const Block& wire)> ndn::Transport::ReceiveCallback
inherited

Definition at line 47 of file transport.hpp.

Constructor & Destructor Documentation

ndn::TcpTransport::TcpTransport ( const std::string &  host,
const std::string &  port = "6363" 
)
explicit

Definition at line 32 of file tcp-transport.cpp.

ndn::TcpTransport::~TcpTransport ( )
overridedefault

Member Function Documentation

void ndn::TcpTransport::close ( )
overridevirtual

Close the connection.

Implements ndn::Transport.

Definition at line 111 of file tcp-transport.cpp.

void ndn::TcpTransport::connect ( boost::asio::io_service &  ioService,
const ReceiveCallback receiveCallback 
)
overridevirtual

asynchronously open the connection

Parameters
ioServiceio_service to create socket on
receiveCallbackcallback function when a TLV block is received; must not be empty
Exceptions
boost::system::system_errorconnection cannot be established

Reimplemented from ndn::Transport.

Definition at line 81 of file tcp-transport.cpp.

shared_ptr< TcpTransport > ndn::TcpTransport::create ( const std::string &  uri)
static

Create transport with parameters defined in URI.

Exceptions
Transport::Errorincorrect URI or unsupported protocol is specified

Definition at line 41 of file tcp-transport.cpp.

bool ndn::Transport::isConnected ( ) const
inlineinherited
Return values
trueconnection has been established
falseconnection is not yet established or has been closed

Definition at line 123 of file transport.hpp.

bool ndn::Transport::isReceiving ( ) const
inlineinherited
Return values
trueincoming packets are expected, receiveCallback will be invoked
falseincoming packets are not expected, receiveCallback will not be invoked

Definition at line 129 of file transport.hpp.

void ndn::TcpTransport::pause ( )
overridevirtual

pause the transport

Postcondition
receiveCallback will not be invoked
Note
This operation has no effect if transport has been paused, or when connection is being established.

Implements ndn::Transport.

Definition at line 120 of file tcp-transport.cpp.

void ndn::Transport::receive ( const Block wire)
inlineprotectedinherited

invoke the receive callback

Definition at line 135 of file transport.hpp.

void ndn::TcpTransport::resume ( )
overridevirtual

resume the transport

Postcondition
receiveCallback will be invoked
Note
This operation has no effect if transport is not paused, or when connection is being established.

Implements ndn::Transport.

Definition at line 129 of file tcp-transport.cpp.

void ndn::TcpTransport::send ( const Block wire)
overridevirtual

send a TLV block through the transport

Implements ndn::Transport.

Definition at line 97 of file tcp-transport.cpp.

void ndn::TcpTransport::send ( const Block header,
const Block payload 
)
overridevirtual

send two memory blocks through the transport

Scatter/gather API is utilized to send two non-consecutive memory blocks together (as part of the same message in datagram-oriented transports).

Implements ndn::Transport.

Definition at line 104 of file tcp-transport.cpp.

Friends And Related Function Documentation

friend class StreamTransportImpl< TcpTransport, boost::asio::ip::tcp >
friend

Definition at line 81 of file tcp-transport.hpp.

Member Data Documentation

boost::asio::io_service* ndn::Transport::m_ioService
protectedinherited

Definition at line 116 of file transport.hpp.

bool ndn::Transport::m_isConnected
protectedinherited

Definition at line 117 of file transport.hpp.

bool ndn::Transport::m_isReceiving
protectedinherited

Definition at line 118 of file transport.hpp.

ReceiveCallback ndn::Transport::m_receiveCallback
protectedinherited

Definition at line 119 of file transport.hpp.