ndn::UnixTransport Class Reference

A transport that uses a Unix stream socket for communication. More...

#include <ndn-cxx/transport/unix-transport.hpp>

+ Inheritance diagram for ndn::UnixTransport:
+ Collaboration diagram for ndn::UnixTransport:

Public Types

using ReceiveCallback = std::function< void(const Block &)>
 
enum class  State {
  CLOSED ,
  CONNECTING ,
  RUNNING ,
  PAUSED
}
 

Public Member Functions

 UnixTransport (const std::string &unixSocket)
 
 ~UnixTransport () override
 
void close () override
 Close the connection. More...
 
void connect (boost::asio::io_context &ioCtx, ReceiveCallback receiveCallback) override
 Asynchronously open the connection. More...
 
State getState () const noexcept
 Return the current state of the transport. More...
 
void pause () override
 Pause the transport, canceling all pending operations. More...
 
void resume () override
 Resume the transport. More...
 
void send (const Block &wire) override
 Send a TLV block through the transport. More...
 

Static Public Member Functions

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

Protected Member Functions

void setState (State state) noexcept
 

Protected Attributes

boost::asio::io_context * m_ioCtx = nullptr
 
ReceiveCallback m_receiveCallback
 

Detailed Description

A transport that uses a Unix stream socket for communication.

Definition at line 41 of file unix-transport.hpp.

Member Typedef Documentation

◆ ReceiveCallback

using ndn::Transport::ReceiveCallback = std::function<void(const Block&)>
inherited

Definition at line 54 of file transport.hpp.

Member Enumeration Documentation

◆ State

enum ndn::Transport::State
stronginherited
Enumerator
CLOSED 
CONNECTING 
RUNNING 
PAUSED 

Definition at line 47 of file transport.hpp.

Constructor & Destructor Documentation

◆ UnixTransport()

ndn::UnixTransport::UnixTransport ( const std::string &  unixSocket)
explicit

Definition at line 33 of file unix-transport.cpp.

◆ ~UnixTransport()

ndn::UnixTransport::~UnixTransport ( )
overridedefault

Member Function Documentation

◆ close()

void ndn::UnixTransport::close ( )
overridevirtual

Close the connection.

Implements ndn::Transport.

Definition at line 95 of file unix-transport.cpp.

◆ connect()

void ndn::UnixTransport::connect ( boost::asio::io_context &  ioCtx,
ReceiveCallback  receiveCallback 
)
overridevirtual

Asynchronously open the connection.

Parameters
ioCtxio_context 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 75 of file unix-transport.cpp.

◆ create()

shared_ptr< UnixTransport > ndn::UnixTransport::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 69 of file unix-transport.cpp.

◆ getState()

State ndn::Transport::getState ( ) const
inlinenoexceptinherited

Return the current state of the transport.

Definition at line 103 of file transport.hpp.

◆ pause()

void ndn::UnixTransport::pause ( )
overridevirtual

Pause the transport, canceling all pending operations.

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

Implements ndn::Transport.

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

◆ resume()

void ndn::UnixTransport::resume ( )
overridevirtual

Resume the transport.

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

Implements ndn::Transport.

Definition at line 113 of file unix-transport.cpp.

◆ send()

void ndn::UnixTransport::send ( const Block block)
overridevirtual

Send a TLV block through the transport.

Implements ndn::Transport.

Definition at line 88 of file unix-transport.cpp.

◆ setState()

void ndn::Transport::setState ( State  state)
inlineprotectednoexceptinherited

Definition at line 110 of file transport.hpp.

Member Data Documentation

◆ m_ioCtx

boost::asio::io_context* ndn::Transport::m_ioCtx = nullptr
protectedinherited

Definition at line 116 of file transport.hpp.

◆ m_receiveCallback

ReceiveCallback ndn::Transport::m_receiveCallback
protectedinherited

Definition at line 117 of file transport.hpp.