CppServer
1.0.0.0
C++ Server Library
|
#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 () | |
Socket & | operator= (const Socket &)=delete |
Socket & | operator= (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... | |
Nanomsg socket.
Nanomsg socket is used as a base communication primitive that wraps all necessary Nanomsg library API.
Thread-safe.
Initialize and open socket with a given domain and protocol.
domain | - Domain |
protocol | - Protocol |
Definition at line 19 of file socket.cpp.
|
delete |
|
defaultnoexcept |
CppServer::Nanomsg::Socket::~Socket | ( | ) |
Definition at line 28 of file socket.cpp.
|
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.
|
noexcept |
Get the number of connections successfully established that were accepted by this socket.
Definition at line 48 of file socket.cpp.
|
inlinenoexcept |
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.
address | - Endpoint address |
Definition at line 168 of file socket.cpp.
|
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.
|
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.
|
noexcept |
Get the number of bytes received by this socket.
Definition at line 98 of file socket.cpp.
|
noexcept |
Get the number of bytes sent by this socket.
Definition at line 93 of file socket.cpp.
bool CppServer::Nanomsg::Socket::Close | ( | ) |
Close the socket.
Definition at line 114 of file socket.cpp.
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.
address | - Endpoint address |
Definition at line 189 of file socket.cpp.
|
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.
|
noexcept |
Get the number of connections currently estabalished to this socket.
Definition at line 78 of file socket.cpp.
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.
Definition at line 226 of file socket.cpp.
|
inlinenoexcept |
|
noexcept |
Get the number of established connections that were dropped by this socket.
Definition at line 53 of file socket.cpp.
|
inlinenoexcept |
|
noexcept |
Get the number of connections successfully established that were initiated from this socket.
Definition at line 43 of file socket.cpp.
bool CppServer::Nanomsg::Socket::GetSocketOption | ( | int | level, |
int | option, | ||
void * | value, | ||
size_t * | size | ||
) |
Get the socket option.
level | - Protocol level |
option | - Socket option |
value | - Option value pointer |
size | - Option value size |
Definition at line 152 of file socket.cpp.
|
inlinenoexcept |
|
inlinenoexcept |
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.
address | - Endpoint address |
Definition at line 210 of file socket.cpp.
|
noexcept |
Get the number messages received by this socket.
Definition at line 88 of file socket.cpp.
|
noexcept |
Get the number messages sent by this socket.
Definition at line 83 of file socket.cpp.
bool CppServer::Nanomsg::Socket::Open | ( | ) |
Open the socket.
Definition at line 103 of file socket.cpp.
|
inlinenoexcept |
size_t CppServer::Nanomsg::Socket::Receive | ( | Message & | message | ) |
Receive a message from the socket in non-blocking mode.
message | - Message to receive |
Definition at line 297 of file socket.cpp.
std::tuple< size_t, bool > CppServer::Nanomsg::Socket::ReceiveSurvey | ( | Message & | message | ) |
Receive a respond to the survey from the socket in non-blocking mode.
message | - Message to receive |
Definition at line 351 of file socket.cpp.
bool CppServer::Nanomsg::Socket::Reopen | ( | ) |
Reopen the socket.
Definition at line 128 of file socket.cpp.
size_t CppServer::Nanomsg::Socket::Send | ( | const void * | buffer, |
size_t | size | ||
) |
Send data to the socket.
buffer | - Buffer to send |
size | - Buffer size |
Definition at line 247 of file socket.cpp.
|
inline |
|
inline |
bool CppServer::Nanomsg::Socket::SetSocketOption | ( | int | level, |
int | option, | ||
const void * | value, | ||
size_t | size | ||
) |
Set the socket option.
level | - Protocol level |
option | - Socket option |
value | - Option value pointer |
size | - Option value size |
Definition at line 136 of file socket.cpp.
|
inlinenoexcept |
|
static |
Terminate all socket operations.
Definition at line 409 of file socket.cpp.
size_t CppServer::Nanomsg::Socket::TryReceive | ( | Message & | message | ) |
Try to receive a message from the socket in non-blocking mode.
message | - Message to receive |
Definition at line 323 of file socket.cpp.
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.
message | - Message to receive |
Definition at line 379 of file socket.cpp.
size_t CppServer::Nanomsg::Socket::TrySend | ( | const void * | buffer, |
size_t | size | ||
) |
Try to send data to the socket in non-blocking mode.
buffer | - Buffer to send |
size | - Buffer size |
Definition at line 271 of file socket.cpp.
|
inline |
|
inline |