CppServer  1.0.0.0
C++ Server Library
Public Member Functions | List of all members
CppServer::Nanomsg::Bus Class Reference

Nanomsg bus node. More...

#include <bus.h>

Inheritance diagram for CppServer::Nanomsg::Bus:
CppServer::Nanomsg::Server

Public Member Functions

 Bus (const std::string &address, bool threading=true)
 Initialize bus node with a given endpoint address. More...
 
 Bus (const Bus &)=delete
 
 Bus (Bus &&)=default
 
virtual ~Bus ()=default
 
Busoperator= (const Bus &)=delete
 
Busoperator= (Bus &&)=default
 
bool Link (const std::string &address)
 Link the current bus node to another one. More...
 
- Public Member Functions inherited from CppServer::Nanomsg::Server
 Server (Domain domain, Protocol protocol, const std::string &address, bool threading=true)
 Initialize server with a given domain, protocol and endpoint address. More...
 
 Server (const Server &)=delete
 
 Server (Server &&)=default
 
virtual ~Server ()
 
Serveroperator= (const Server &)=delete
 
Serveroperator= (Server &&)=default
 
Socketsocket () noexcept
 Get the Nanomsg socket. More...
 
bool IsStarted () const noexcept
 Is the server started? More...
 
bool Start ()
 Start the server. More...
 
bool Stop ()
 Stop the server. More...
 
bool Restart ()
 Restart the server. More...
 
size_t Send (const void *buffer, size_t size)
 Send data to the client. More...
 
size_t Send (const std::string &text)
 Send a text string to the client. More...
 
size_t Send (const Message &message)
 Send a message to the client. More...
 
size_t TrySend (const void *buffer, size_t size)
 Try to send data to the client in non-blocking mode. More...
 
size_t TrySend (const std::string &text)
 Try to send a text string to the client in non-blocking mode. More...
 
size_t TrySend (const Message &message)
 Try to send a message to the client in non-blocking mode. More...
 
size_t Receive (Message &message)
 Receive a message from the client. More...
 
size_t TryReceive (Message &message)
 Try to receive a message from the client in non-blocking mode. More...
 

Additional Inherited Members

- Protected Member Functions inherited from CppServer::Nanomsg::Server
virtual void onThreadInitialize ()
 Initialize thread handler. More...
 
virtual void onThreadCleanup ()
 Cleanup thread handler. More...
 
virtual void onStarted ()
 Handle server started notification. More...
 
virtual void onStopped ()
 Handle server stopped notification. More...
 
virtual void onIdle ()
 Handle server idle notification. More...
 
virtual void onReceived (Message &message)
 Handle message received notification. More...
 
virtual void onError (int error, const std::string &message)
 Handle error notification. More...
 

Detailed Description

Nanomsg bus node.

Nanomsg bus node is used to perform a duplex communication with other Nanomsg bus nodes.

Broadcasts messages from any node to all other nodes in the topology. The server should never receive messages that it sent itself.

This pattern scales only to local level (within a single machine or within a single LAN). Trying to scale it further can result in overloading individual nodes with messages.

Sent messages are distributed to all nodes in the topology. Incoming messages from all other nodes in the topology are fair-queued in the server.

Warning: For bus topology to function correctly, user is responsible for ensuring that path from each node to any other node exists within the topology.

Thread-safe.

Examples:
nanomsg_bus.cpp.

Definition at line 39 of file bus.h.

Constructor & Destructor Documentation

◆ Bus() [1/3]

CppServer::Nanomsg::Bus::Bus ( const std::string &  address,
bool  threading = true 
)
inlineexplicit

Initialize bus node with a given endpoint address.

Parameters
address- Endpoint address
threading- Run the bus node in a separate thread (default is true)
Examples:
nanomsg_bus.cpp.

Definition at line 47 of file bus.h.

◆ Bus() [2/3]

CppServer::Nanomsg::Bus::Bus ( const Bus )
delete

◆ Bus() [3/3]

CppServer::Nanomsg::Bus::Bus ( Bus &&  )
default

◆ ~Bus()

virtual CppServer::Nanomsg::Bus::~Bus ( )
virtualdefault

Member Function Documentation

◆ Link()

bool CppServer::Nanomsg::Bus::Link ( const std::string &  address)

Link the current bus node to another one.

The address argument consists of two parts as follows: transport://address. The transport specifies the underlying transport protocol to use. The meaning of the address part is specific to the underlying transport protocol.

Parameters
address- Endpoint address
Returns
'true' if the bus node was successfully linked, 'false' if the bus node was already linked or the nanomsg engine terminated

Definition at line 14 of file bus.cpp.

◆ operator=() [1/2]

Bus& CppServer::Nanomsg::Bus::operator= ( const Bus )
delete

◆ operator=() [2/2]

Bus& CppServer::Nanomsg::Bus::operator= ( Bus &&  )
default

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