9 #ifndef CPPSERVER_NANOMSG_SOCKET_H 10 #define CPPSERVER_NANOMSG_SOCKET_H 50 int socket() const noexcept {
return _socket; }
52 int endpoint() const noexcept {
return _endpoint; }
54 const std::string&
address() const noexcept {
return _address; }
82 bool IsOpened() const noexcept {
return (_socket >= 0); }
84 bool IsConnected() const noexcept {
return (_endpoint >= 0); }
110 bool SetSocketOption(
int level,
int option,
const void* value,
size_t size);
119 bool GetSocketOption(
int level,
int option,
void* value,
size_t* size);
169 size_t Send(
const void* buffer,
size_t size);
175 size_t Send(
const std::string& text) {
return Send(text.data(), text.size()); }
189 size_t TrySend(
const void* buffer,
size_t size);
195 size_t TrySend(
const std::string& text) {
return TrySend(text.data(), text.size()); }
239 std::string _address;
245 #endif // CPPSERVER_NANOMSG_SOCKET_H uint64_t established_connections() const noexcept
Get the number of connections successfully established that were initiated from this socket...
uint64_t accept_errors() const noexcept
Get the number of errors encountered by this socket trying to accept a a connection from a remote pee...
bool Reopen()
Reopen the socket.
size_t TrySend(const Message &message)
Try to send a message to the socket in non-blocking mode.
bool SetSocketOption(int level, int option, const void *value, size_t size)
Set the socket option.
bool Close()
Close the socket.
bool Link(const std::string &address)
Link the socket to the remote endpoint.
static void Terminate()
Terminate all socket operations.
uint64_t connect_errors() const noexcept
Get the number of errors encountered by this socket trying to connect to a remote peer...
size_t TrySend(const void *buffer, size_t size)
Try to send data to the socket in non-blocking mode.
std::tuple< size_t, bool > ReceiveSurvey(Message &message)
Receive a respond to the survey from the socket in non-blocking mode.
bool GetSocketOption(int level, int option, void *value, size_t *size)
Get the socket option.
size_t size() const noexcept
Get the message size.
Socket & operator=(const Socket &)=delete
uint64_t broken_connections() const noexcept
Get the number of established connections that were closed by this socket, typically due to protocol ...
Nanomsg message definition.
Domain domain() const noexcept
Get the socket domain.
C++ Server project definitions.
Socket(Domain domain, Protocol protocol)
Initialize and open socket with a given domain and protocol.
std::tuple< size_t, bool > TryReceiveSurvey(Message &message)
Try to receive a respond to the survey from the socket in non-blocking mode.
size_t Send(const std::string &text)
Send a text string to the socket.
uint64_t bind_errors() const noexcept
Get the number of errors encountered by this socket trying to bind to a local address.
bool Bind(const std::string &address)
Bind the socket to the local endpoint.
uint64_t current_connections() const noexcept
Get the number of connections currently estabalished to this socket.
uint64_t messages_sent() const noexcept
Get the number messages sent by this socket.
size_t TrySend(const std::string &text)
Try to send a text string to the socket in non-blocking mode.
int endpoint() const noexcept
Get the socket endpoint.
uint64_t bytes_sent() const noexcept
Get the number of bytes sent by this socket.
uint8_t * buffer() noexcept
Get the message buffer.
Protocol protocol() const noexcept
Get the socket protocol.
bool IsConnected() const noexcept
Is socket connected?
uint64_t messages_received() const noexcept
Get the number messages received by this socket.
Protocol
Nanomsg protocol.
size_t Receive(Message &message)
Receive a message from the socket in non-blocking mode.
uint64_t bytes_received() const noexcept
Get the number of bytes received by this socket.
size_t Send(const void *buffer, size_t size)
Send data to the socket.
uint64_t dropped_connections() const noexcept
Get the number of established connections that were dropped by this socket.
uint64_t accepted_connections() const noexcept
Get the number of connections successfully established that were accepted by this socket...
size_t Send(const Message &message)
Send a message to the socket.
bool Open()
Open the socket.
bool Connect(const std::string &address)
Connect the socket to the remote endpoint.
bool IsOpened() const noexcept
Is socket opened?
const std::string & address() const noexcept
Get the socket address.
size_t TryReceive(Message &message)
Try to receive a message from the socket in non-blocking mode.
int socket() const noexcept
Get the socket handler.
bool Disconnect()
Disconnect the socket from the endpoint.