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

Nanomsg server. More...

#include <server.h>

Inheritance diagram for CppServer::Nanomsg::Server:
CppServer::Nanomsg::Bus CppServer::Nanomsg::PairServer CppServer::Nanomsg::PushServer CppServer::Nanomsg::RequestServer CppServer::Nanomsg::SubscribeServer CppServer::Nanomsg::SurveyServer

Public Member Functions

 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...
 

Protected Member Functions

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 server.

Nanomsg server is used to receive messages from Nanomsg clients and send responses back to clients.

Thread-safe.

Definition at line 29 of file server.h.

Constructor & Destructor Documentation

◆ Server() [1/3]

CppServer::Nanomsg::Server::Server ( Domain  domain,
Protocol  protocol,
const std::string &  address,
bool  threading = true 
)
explicit

Initialize server with a given domain, protocol and endpoint address.

Parameters
domain- Domain
protocol- Protocol
address- Endpoint address
threading- Run the server in a separate thread (default is true)

Definition at line 19 of file server.cpp.

◆ Server() [2/3]

CppServer::Nanomsg::Server::Server ( const Server )
delete

◆ Server() [3/3]

CppServer::Nanomsg::Server::Server ( Server &&  )
default

◆ ~Server()

CppServer::Nanomsg::Server::~Server ( )
virtual

Definition at line 32 of file server.cpp.

Member Function Documentation

◆ IsStarted()

bool CppServer::Nanomsg::Server::IsStarted ( ) const
inlinenoexcept

Is the server started?

Definition at line 51 of file server.h.

◆ onError()

virtual void CppServer::Nanomsg::Server::onError ( int  error,
const std::string &  message 
)
inlineprotectedvirtual

Handle error notification.

Parameters
error- Error code
message- Error message
Examples:
nanomsg_bus.cpp, nanomsg_pair_server.cpp, nanomsg_push_server.cpp, nanomsg_request_server.cpp, nanomsg_subscribe_server.cpp, and nanomsg_survey_server.cpp.

Definition at line 154 of file server.h.

◆ onIdle()

virtual void CppServer::Nanomsg::Server::onIdle ( )
inlineprotectedvirtual

Handle server idle notification.

Definition at line 141 of file server.h.

◆ onReceived()

virtual void CppServer::Nanomsg::Server::onReceived ( Message message)
inlineprotectedvirtual

Handle message received notification.

Parameters
message- Received message
Examples:
nanomsg_bus.cpp, nanomsg_pair_server.cpp, nanomsg_push_server.cpp, and nanomsg_request_server.cpp.

Definition at line 147 of file server.h.

◆ onStarted()

virtual void CppServer::Nanomsg::Server::onStarted ( )
inlineprotectedvirtual

◆ onStopped()

virtual void CppServer::Nanomsg::Server::onStopped ( )
inlineprotectedvirtual

◆ onThreadCleanup()

virtual void CppServer::Nanomsg::Server::onThreadCleanup ( )
inlineprotectedvirtual

Cleanup thread handler.

This handler can be used to cleanup priority or affinity of the server thread.

Definition at line 133 of file server.h.

◆ onThreadInitialize()

virtual void CppServer::Nanomsg::Server::onThreadInitialize ( )
inlineprotectedvirtual

Initialize thread handler.

This handler can be used to initialize priority or affinity of the server thread.

Definition at line 128 of file server.h.

◆ operator=() [1/2]

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

◆ operator=() [2/2]

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

◆ Receive()

size_t CppServer::Nanomsg::Server::Receive ( Message message)

Receive a message from the client.

Parameters
message- Message to receive
Returns
Count of received bytes

Definition at line 189 of file server.cpp.

◆ Restart()

bool CppServer::Nanomsg::Server::Restart ( )

Restart the server.

Returns
'true' if the server was successfully restarted, 'false' if the server failed to restart

Definition at line 100 of file server.cpp.

◆ Send() [1/3]

size_t CppServer::Nanomsg::Server::Send ( const void *  buffer,
size_t  size 
)

Send data to the client.

Parameters
buffer- Buffer to send
size- Buffer size
Returns
Count of sent bytes
Examples:
nanomsg_pair_server.cpp, and nanomsg_request_server.cpp.

Definition at line 157 of file server.cpp.

◆ Send() [2/3]

size_t CppServer::Nanomsg::Server::Send ( const std::string &  text)
inline

Send a text string to the client.

Parameters
text- Text string to send
Returns
Count of sent bytes

Definition at line 81 of file server.h.

◆ Send() [3/3]

size_t CppServer::Nanomsg::Server::Send ( const Message message)
inline

Send a message to the client.

Parameters
message- Message to send
Returns
Count of sent bytes

Definition at line 87 of file server.h.

◆ socket()

Socket& CppServer::Nanomsg::Server::socket ( )
inlinenoexcept

Get the Nanomsg socket.

Definition at line 48 of file server.h.

◆ Start()

bool CppServer::Nanomsg::Server::Start ( )

Start the server.

Returns
'true' if the server was successfully started, 'false' if the server failed to start

Definition at line 46 of file server.cpp.

◆ Stop()

bool CppServer::Nanomsg::Server::Stop ( )

Stop the server.

Returns
'true' if the server was successfully stopped, 'false' if the server is already stopped

Definition at line 73 of file server.cpp.

◆ TryReceive()

size_t CppServer::Nanomsg::Server::TryReceive ( Message message)

Try to receive a message from the client in non-blocking mode.

Parameters
message- Message to receive
Returns
Count of received bytes

Definition at line 211 of file server.cpp.

◆ TrySend() [1/3]

size_t CppServer::Nanomsg::Server::TrySend ( const void *  buffer,
size_t  size 
)

Try to send data to the client in non-blocking mode.

Parameters
buffer- Buffer to send
size- Buffer size
Returns
Count of sent bytes

Definition at line 173 of file server.cpp.

◆ TrySend() [2/3]

size_t CppServer::Nanomsg::Server::TrySend ( const std::string &  text)
inline

Try to send a text string to the client in non-blocking mode.

Parameters
text- Text string to send
Returns
Count of sent bytes

Definition at line 101 of file server.h.

◆ TrySend() [3/3]

size_t CppServer::Nanomsg::Server::TrySend ( const Message message)
inline

Try to send a message to the client in non-blocking mode.

Parameters
message- Message to send
Returns
Count of sent bytes

Definition at line 107 of file server.h.


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