ZIO
Python and C++ interface to ZeroMQ and Zyre
Public Types | Public Member Functions | List of all members
zio::Port Class Reference

A port holds a socket in the context of a node. More...

#include <port.hpp>

Public Types

typedef std::string address_t
 
typedef std::string nodename_t
 
typedef std::string portname_t
 

Public Member Functions

 Port (const std::string &name, int stype, const std::string &hostname="127.0.0.1")
 Create a port of given name and socket type. More...
 
 ~Port ()
 
void set_origin (origin_t origin)
 Access the owning node's origin. More...
 
void set_verbose (bool verbose=true)
 
const std::string & name () const
 Access this port's name. More...
 
void bind ()
 Request a default bind. More...
 
void bind (const std::string &hostname, int tcpportnum)
 Request a bind to a specific TCP/IP host and port. More...
 
void bind (const address_t &address)
 Request bind to fully qualified ZeroMQ address string. More...
 
void connect (const address_t &address)
 Request connect to fully qualified ZeroMQ address string. More...
 
void connect (const nodename_t &node, const portname_t &port)
 Request connect to abstract node/port names. More...
 
void subscribe (const std::string &prefix="")
 Subscribe to a PUB topic. More...
 
void set_header (const std::string &leafname, const std::string &value)
 Set an extra port header. More...
 
headerset_t do_binds ()
 Perform any requested binds. More...
 
void online (Peer &peer)
 Make any previously requested connections. More...
 
void offline ()
 Disconnect and unbind. More...
 
void send (Message &msg)
 Send a message. More...
 
bool recv (Message &msg, int timeout=-1)
 Recieve a message, return false if timeout occurred. More...
 
zio::socket_tsocket ()
 Access the underlying cppzmq socket. More...
 

Detailed Description

A port holds a socket in the context of a node.

A port provides an identity (name) for the socket in the context of a node to the network (via a peer) and to the application (via a method).

It provides direct and discovery-based bind() and connect().

Finally, using its send() and recv() their messages will adhere to the ZIO conventions.

Definition at line 27 of file port.hpp.

Member Typedef Documentation

◆ address_t

typedef std::string zio::Port::address_t

Definition at line 29 of file port.hpp.

◆ nodename_t

typedef std::string zio::Port::nodename_t

Definition at line 30 of file port.hpp.

◆ portname_t

typedef std::string zio::Port::portname_t

Definition at line 31 of file port.hpp.

Constructor & Destructor Documentation

◆ Port()

zio::Port::Port ( const std::string &  name,
int  stype,
const std::string &  hostname = "127.0.0.1" 
)

Create a port of given name and socket type.

The hostname sets the default for ephemeral binds.

A port is typically only constructed via a zio::Node.

Definition at line 56 of file port.cpp.

◆ ~Port()

zio::Port::~Port ( )

Definition at line 61 of file port.cpp.

Member Function Documentation

◆ bind() [1/3]

void zio::Port::bind ( )

Request a default bind.

This is for application to call.

Definition at line 69 of file port.cpp.

◆ bind() [2/3]

void zio::Port::bind ( const std::string &  hostname,
int  tcpportnum 
)

Request a bind to a specific TCP/IP host and port.

TCP port number 0 implies to pick some random, unused port.

This is for application to call.

Definition at line 75 of file port.cpp.

◆ bind() [3/3]

void zio::Port::bind ( const address_t address)

Request bind to fully qualified ZeroMQ address string.

This is for application to call.

Definition at line 83 of file port.cpp.

◆ connect() [1/2]

void zio::Port::connect ( const address_t address)

Request connect to fully qualified ZeroMQ address string.

This is for application to call.

Definition at line 90 of file port.cpp.

◆ connect() [2/2]

void zio::Port::connect ( const nodename_t node,
const portname_t port 
)

Request connect to abstract node/port names.

This will resolve to a direct address by the zio::Peer

This is for application to call.

Definition at line 95 of file port.cpp.

◆ do_binds()

zio::headerset_t zio::Port::do_binds ( )

Perform any requested binds.

The corresponding Zyre headers for any ports that bind are returned and should be given to the peer to announce.

This method is intended for the zio::Node to call.

Definition at line 113 of file port.cpp.

◆ name()

const std::string& zio::Port::name ( ) const
inline

Access this port's name.

Definition at line 48 of file port.hpp.

◆ offline()

void zio::Port::offline ( )

Disconnect and unbind.

This method is intended for the zio::Node to call

Definition at line 195 of file port.cpp.

◆ online()

void zio::Port::online ( zio::Peer peer)

Make any previously requested connections.

The peer will be used to resolve any abstract addresses.

This method is intended for the zio::Node to call

Definition at line 137 of file port.cpp.

◆ recv()

bool zio::Port::recv ( Message msg,
int  timeout = -1 
)

Recieve a message, return false if timeout occurred.

Definition at line 239 of file port.cpp.

◆ send()

void zio::Port::send ( zio::Message msg)

Send a message.

The zio::Message is modified to set its coordinates.

Definition at line 220 of file port.cpp.

◆ set_header()

void zio::Port::set_header ( const std::string &  leafname,
const std::string &  value 
)

Set an extra port header.

The header is of the form: zio.port.<portname>.<leafname> =

Definition at line 107 of file port.cpp.

◆ set_origin()

void zio::Port::set_origin ( origin_t  origin)
inline

Access the owning node's origin.

Definition at line 43 of file port.hpp.

◆ set_verbose()

void zio::Port::set_verbose ( bool  verbose = true)
inline

Definition at line 45 of file port.hpp.

◆ socket()

zio::socket_t& zio::Port::socket ( )
inline

Access the underlying cppzmq socket.

This access is generally not recomended.

Definition at line 126 of file port.hpp.

◆ subscribe()

void zio::Port::subscribe ( const std::string &  prefix = "")

Subscribe to a PUB topic.

This is only meaningful when the underlying socket is a SUB and in this case at least one subscription is required if there shall be any expectation of the app getting messages.

This is for application to call.

Definition at line 100 of file port.cpp.


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