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

Nanomsg socket. More...

#include <socket.h>

Public Member Functions

 Socket (Domain domain, Protocol protocol)
 Initialize and open socket with a given domain and protocol. More...
 
 Socket (const Socket &)=delete
 
 Socket (Socket &&) noexcept=default
 
 ~Socket ()
 
Socketoperator= (const Socket &)=delete
 
Socketoperator= (Socket &&) noexcept=default
 
Domain domain () const noexcept
 Get the socket domain. More...
 
Protocol protocol () const noexcept
 Get the socket protocol. More...
 
int socket () const noexcept
 Get the socket handler. More...
 
int endpoint () const noexcept
 Get the socket endpoint. More...
 
const std::string & address () const noexcept
 Get the socket address. More...
 
uint64_t established_connections () const noexcept
 Get the number of connections successfully established that were initiated from this socket. More...
 
uint64_t accepted_connections () const noexcept
 Get the number of connections successfully established that were accepted by this socket. More...
 
uint64_t dropped_connections () const noexcept
 Get the number of established connections that were dropped by this socket. More...
 
uint64_t broken_connections () const noexcept
 Get the number of established connections that were closed by this socket, typically due to protocol errors. More...
 
uint64_t connect_errors () const noexcept
 Get the number of errors encountered by this socket trying to connect to a remote peer. More...
 
uint64_t bind_errors () const noexcept
 Get the number of errors encountered by this socket trying to bind to a local address. More...
 
uint64_t accept_errors () const noexcept
 Get the number of errors encountered by this socket trying to accept a a connection from a remote peer. More...
 
uint64_t current_connections () const noexcept
 Get the number of connections currently estabalished to this socket. More...
 
uint64_t messages_sent () const noexcept
 Get the number messages sent by this socket. More...
 
uint64_t messages_received () const noexcept
 Get the number messages received by this socket. More...
 
uint64_t bytes_sent () const noexcept
 Get the number of bytes sent by this socket. More...
 
uint64_t bytes_received () const noexcept
 Get the number of bytes received by this socket. More...
 
bool IsOpened () const noexcept
 Is socket opened? More...
 
bool IsConnected () const noexcept
 Is socket connected? More...
 
bool Open ()
 Open the socket. More...
 
bool Close ()
 Close the socket. More...
 
bool Reopen ()
 Reopen the socket. More...
 
bool SetSocketOption (int level, int option, const void *value, size_t size)
 Set the socket option. More...
 
bool GetSocketOption (int level, int option, void *value, size_t *size)
 Get the socket option. More...
 
bool Bind (const std::string &address)
 Bind the socket to the local endpoint. More...
 
bool Connect (const std::string &address)
 Connect the socket to the remote endpoint. More...
 
bool Link (const std::string &address)
 Link the socket to the remote endpoint. More...
 
bool Disconnect ()
 Disconnect the socket from the endpoint. More...
 
size_t Send (const void *buffer, size_t size)
 Send data to the socket. More...
 
size_t Send (const std::string &text)
 Send a text string to the socket. More...
 
size_t Send (const Message &message)
 Send a message to the socket. More...
 
size_t TrySend (const void *buffer, size_t size)
 Try to send data to the socket in non-blocking mode. More...
 
size_t TrySend (const std::string &text)
 Try to send a text string to the socket in non-blocking mode. More...
 
size_t TrySend (const Message &message)
 Try to send a message to the socket in non-blocking mode. More...
 
size_t Receive (Message &message)
 Receive a message from the socket in non-blocking mode. More...
 
size_t TryReceive (Message &message)
 Try to receive a message from the socket in non-blocking mode. More...
 
std::tuple< size_t, bool > ReceiveSurvey (Message &message)
 Receive a respond to the survey from the socket in non-blocking mode. More...
 
std::tuple< size_t, bool > TryReceiveSurvey (Message &message)
 Try to receive a respond to the survey from the socket in non-blocking mode. More...
 

Static Public Member Functions

static void Terminate ()
 Terminate all socket operations. More...
 

Detailed Description

Nanomsg socket.

Nanomsg socket is used as a base communication primitive that wraps all necessary Nanomsg library API.

Thread-safe.

http://nanomsg.org

Definition at line 29 of file socket.h.

Constructor & Destructor Documentation

◆ Socket() [1/3]

CppServer::Nanomsg::Socket::Socket ( Domain  domain,
Protocol  protocol 
)
explicit

Initialize and open socket with a given domain and protocol.

Parameters
domain- Domain
protocol- Protocol

Definition at line 19 of file socket.cpp.

◆ Socket() [2/3]

CppServer::Nanomsg::Socket::Socket ( const Socket )
delete

◆ Socket() [3/3]

CppServer::Nanomsg::Socket::Socket ( Socket &&  )
defaultnoexcept

◆ ~Socket()

CppServer::Nanomsg::Socket::~Socket ( )

Definition at line 28 of file socket.cpp.

Member Function Documentation

◆ accept_errors()

uint64_t CppServer::Nanomsg::Socket::accept_errors ( ) const
noexcept

Get the number of errors encountered by this socket trying to accept a a connection from a remote peer.

Definition at line 73 of file socket.cpp.

◆ accepted_connections()

uint64_t CppServer::Nanomsg::Socket::accepted_connections ( ) const
noexcept

Get the number of connections successfully established that were accepted by this socket.

Definition at line 48 of file socket.cpp.

◆ address()

const std::string& CppServer::Nanomsg::Socket::address ( ) const
inlinenoexcept

Get the socket address.

Definition at line 54 of file socket.h.

◆ Bind()

bool CppServer::Nanomsg::Socket::Bind ( const std::string &  address)

Bind the socket to the local endpoint.

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 socket was successfully bind, 'false' if the socket was already connected or the nanomsg engine terminated

Definition at line 168 of file socket.cpp.

◆ bind_errors()

uint64_t CppServer::Nanomsg::Socket::bind_errors ( ) const
noexcept

Get the number of errors encountered by this socket trying to bind to a local address.

Definition at line 68 of file socket.cpp.

◆ broken_connections()

uint64_t CppServer::Nanomsg::Socket::broken_connections ( ) const
noexcept

Get the number of established connections that were closed by this socket, typically due to protocol errors.

Definition at line 58 of file socket.cpp.

◆ bytes_received()

uint64_t CppServer::Nanomsg::Socket::bytes_received ( ) const
noexcept

Get the number of bytes received by this socket.

Definition at line 98 of file socket.cpp.

◆ bytes_sent()

uint64_t CppServer::Nanomsg::Socket::bytes_sent ( ) const
noexcept

Get the number of bytes sent by this socket.

Definition at line 93 of file socket.cpp.

◆ Close()

bool CppServer::Nanomsg::Socket::Close ( )

Close the socket.

Returns
'true' if the socket was successfully closed, 'false' if the socket was already closed

Definition at line 114 of file socket.cpp.

◆ Connect()

bool CppServer::Nanomsg::Socket::Connect ( const std::string &  address)

Connect the socket to the remote endpoint.

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 socket was successfully connected, 'false' if the socket was already connected or the nanomsg engine terminated

Definition at line 189 of file socket.cpp.

◆ connect_errors()

uint64_t CppServer::Nanomsg::Socket::connect_errors ( ) const
noexcept

Get the number of errors encountered by this socket trying to connect to a remote peer.

Definition at line 63 of file socket.cpp.

◆ current_connections()

uint64_t CppServer::Nanomsg::Socket::current_connections ( ) const
noexcept

Get the number of connections currently estabalished to this socket.

Definition at line 78 of file socket.cpp.

◆ Disconnect()

bool CppServer::Nanomsg::Socket::Disconnect ( )

Disconnect the socket from the endpoint.

Removes an endpoint from the socket. The method call will return immediately, however, the library will try to deliver any outstanding outbound messages to the endpoint for the time specified by NN_LINGER socket option.

Returns
'true' if the socket was successfully disconnected, 'false' if the socket was already disconnected or the nanomsg engine terminated

Definition at line 226 of file socket.cpp.

◆ domain()

Domain CppServer::Nanomsg::Socket::domain ( ) const
inlinenoexcept

Get the socket domain.

Definition at line 46 of file socket.h.

◆ dropped_connections()

uint64_t CppServer::Nanomsg::Socket::dropped_connections ( ) const
noexcept

Get the number of established connections that were dropped by this socket.

Definition at line 53 of file socket.cpp.

◆ endpoint()

int CppServer::Nanomsg::Socket::endpoint ( ) const
inlinenoexcept

Get the socket endpoint.

Definition at line 52 of file socket.h.

◆ established_connections()

uint64_t CppServer::Nanomsg::Socket::established_connections ( ) const
noexcept

Get the number of connections successfully established that were initiated from this socket.

Definition at line 43 of file socket.cpp.

◆ GetSocketOption()

bool CppServer::Nanomsg::Socket::GetSocketOption ( int  level,
int  option,
void *  value,
size_t *  size 
)

Get the socket option.

Parameters
level- Protocol level
option- Socket option
value- Option value pointer
size- Option value size
Returns
'true' if the socket option was successfully get, 'false' if the nanomsg engine terminated

Definition at line 152 of file socket.cpp.

◆ IsConnected()

bool CppServer::Nanomsg::Socket::IsConnected ( ) const
inlinenoexcept

Is socket connected?

Definition at line 84 of file socket.h.

◆ IsOpened()

bool CppServer::Nanomsg::Socket::IsOpened ( ) const
inlinenoexcept

Is socket opened?

Definition at line 82 of file socket.h.

◆ Link()

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

Link the socket to the remote endpoint.

Important: This method works properly only for bus protocol!

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 socket was successfully linked, 'false' if the current protocol does not support linking or the nanomsg engine terminated

Definition at line 210 of file socket.cpp.

◆ messages_received()

uint64_t CppServer::Nanomsg::Socket::messages_received ( ) const
noexcept

Get the number messages received by this socket.

Definition at line 88 of file socket.cpp.

◆ messages_sent()

uint64_t CppServer::Nanomsg::Socket::messages_sent ( ) const
noexcept

Get the number messages sent by this socket.

Definition at line 83 of file socket.cpp.

◆ Open()

bool CppServer::Nanomsg::Socket::Open ( )

Open the socket.

Returns
'true' if the socket was successfully opened, 'false' if the socket was already opened

Definition at line 103 of file socket.cpp.

◆ operator=() [1/2]

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

◆ operator=() [2/2]

Socket& CppServer::Nanomsg::Socket::operator= ( Socket &&  )
defaultnoexcept

◆ protocol()

Protocol CppServer::Nanomsg::Socket::protocol ( ) const
inlinenoexcept

Get the socket protocol.

Definition at line 48 of file socket.h.

◆ Receive()

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

Receive a message from the socket in non-blocking mode.

Parameters
message- Message to receive
Returns
Count of received bytes

Definition at line 297 of file socket.cpp.

◆ ReceiveSurvey()

std::tuple< size_t, bool > CppServer::Nanomsg::Socket::ReceiveSurvey ( Message message)

Receive a respond to the survey from the socket in non-blocking mode.

Parameters
message- Message to receive
Returns
Count of received bytes and survey complete flag

Definition at line 351 of file socket.cpp.

◆ Reopen()

bool CppServer::Nanomsg::Socket::Reopen ( )

Reopen the socket.

Returns
'true' if the socket was successfully reopened, 'false' if the socket was not reopened

Definition at line 128 of file socket.cpp.

◆ Send() [1/3]

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

Send data to the socket.

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

Definition at line 247 of file socket.cpp.

◆ Send() [2/3]

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

Send a text string to the socket.

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

Definition at line 175 of file socket.h.

◆ Send() [3/3]

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

Send a message to the socket.

Parameters
message- Message to send
Returns
Count of sent bytes

Definition at line 181 of file socket.h.

◆ SetSocketOption()

bool CppServer::Nanomsg::Socket::SetSocketOption ( int  level,
int  option,
const void *  value,
size_t  size 
)

Set the socket option.

Parameters
level- Protocol level
option- Socket option
value- Option value pointer
size- Option value size
Returns
'true' if the socket option was successfully set, 'false' if the nanomsg engine terminated

Definition at line 136 of file socket.cpp.

◆ socket()

int CppServer::Nanomsg::Socket::socket ( ) const
inlinenoexcept

Get the socket handler.

Definition at line 50 of file socket.h.

◆ Terminate()

void CppServer::Nanomsg::Socket::Terminate ( )
static

Terminate all socket operations.

Definition at line 409 of file socket.cpp.

◆ TryReceive()

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

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

Parameters
message- Message to receive
Returns
Count of received bytes

Definition at line 323 of file socket.cpp.

◆ TryReceiveSurvey()

std::tuple< size_t, bool > CppServer::Nanomsg::Socket::TryReceiveSurvey ( Message message)

Try to receive a respond to the survey from the socket in non-blocking mode.

Parameters
message- Message to receive
Returns
Count of received bytes and survey complete flag

Definition at line 379 of file socket.cpp.

◆ TrySend() [1/3]

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

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

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

Definition at line 271 of file socket.cpp.

◆ TrySend() [2/3]

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

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

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

Definition at line 195 of file socket.h.

◆ TrySend() [3/3]

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

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

Parameters
message- Message to send
Returns
Count of sent bytes

Definition at line 201 of file socket.h.


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