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

Nanomsg request server. More...

#include <request_server.h>

Inheritance diagram for CppServer::Nanomsg::RequestServer:
CppServer::Nanomsg::Server

Public Member Functions

 RequestServer (const std::string &address, bool threading=true)
 Initialize server with a given endpoint address. More...
 
 RequestServer (const RequestServer &)=delete
 
 RequestServer (RequestServer &&)=default
 
virtual ~RequestServer ()=default
 
RequestServeroperator= (const RequestServer &)=delete
 
RequestServeroperator= (RequestServer &&)=default
 
- 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 request server.

Nanomsg request server is used to receive requests from Nanomsg clients and reply with corresponding responses.

This protocol is used to distribute the workload among multiple stateless workers.

Please note that request/reply applications should be stateless.

It's important to include all the information necessary to process the request in the request itself, including information about the sender or the originator of the request if this is necessary to respond to the request.

Sender information cannot be retrieved from the underlying socket connection since, firstly, transports like IPC may not have a firm notion of a message origin. Secondly, transports that have some notion may not have a reliable one

For this reason, sender information must be included by the application if required. Allocating 6 randomly-generated bytes in the message for the lifetime of the connection is sufficient for most purposes. For longer-lived applications, an UUID is more suitable.

Thread-safe.

Examples:
nanomsg_request_server.cpp.

Definition at line 44 of file request_server.h.

Constructor & Destructor Documentation

◆ RequestServer() [1/3]

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

Initialize server with a given endpoint address.

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

Definition at line 52 of file request_server.h.

◆ RequestServer() [2/3]

CppServer::Nanomsg::RequestServer::RequestServer ( const RequestServer )
delete

◆ RequestServer() [3/3]

CppServer::Nanomsg::RequestServer::RequestServer ( RequestServer &&  )
default

◆ ~RequestServer()

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

Member Function Documentation

◆ operator=() [1/2]

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

◆ operator=() [2/2]

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

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