Nets v3.0.0
SocketView Struct Reference

Network socket instance view. More...

#include <socket.hpp>

Public Member Functions

 SocketView (Socket_T *instance) noexcept
 Creates a new network socket view.
void destroy () noexcept
 Destroys network socket instance.
Socket_TgetInstance () const noexcept
 Returns socket SSL context view instance.
SocketType getType () const noexcept
 Returns socket communication protocol type.
SocketFamily getFamily () const noexcept
 Returns socket internet protocol (IP) address family type.
bool isBlocking () const noexcept
 Returns true if socket is in blocking mode.
bool isOnlyIPv6 () const noexcept
 Returns true if IPv6 socket is not accepting IPv4 connections.
void getLocalAddress (SocketAddressView socketAddress) const
 Gets local socket IP address.
void getRemoteAddress (SocketAddressView socketAddress) const
 Gets remote socket IP address.
SslContextView getSslContext () const noexcept
 Returns socket SSL context instance.
void * getHandle () const noexcept
 Returns socket internal handle.
bool isNoDelay () const noexcept
 Returns true if stream socket sends without caching.
void setNoDelay (bool value) noexcept
 Sets socket no delay mode.
bool isListening () const noexcept
 Returns true if socket is in the listening state.
size_t getQueueSize () const noexcept
 Returns socket pending connections queue size.
NetsResult listen (size_t queueSize=256) noexcept
 Puts socket in a listening state.
NetsResult accept (SocketView &accepted) noexcept
 Accepts a new socket connection.
NetsResult acceptSsl () noexcept
 Accepts socket SSL connection.
NetsResult connect (SocketAddressView remoteAddress) noexcept
 Connects socket to the specified remote address.
NetsResult connectSsl (const char *hostname=nullptr) noexcept
 Establishes socket SSL connection.
NetsResult shutdown (SocketShutdown shutdown=RECEIVE_SEND_SOCKET_SHUTDOWN) noexcept
 Shutdowns part of the full-duplex connection.
NetsResult receive (void *receiveBuffer, size_t bufferSize, size_t &byteCount) noexcept
 Receives pending socket data.
NetsResult send (const void *data, size_t byteCount)
 Sends specified data to the remote socket.
template<class T>
NetsResult send (const T &data)
 Sends specified data to the remote socket.
NetsResult receiveFrom (SocketAddressView remoteAddress, void *receiveBuffer, size_t bufferSize, size_t &byteCount) noexcept
 Receives pending data from the remote socket.
NetsResult sendTo (const void *data, size_t byteCount, SocketAddressView remoteAddress) noexcept
 Sends specified data to the remote socket.
template<class T>
NetsResult sendTo (const T &data, SocketAddressView remoteAddress) noexcept
 Sends specified data to the remote socket.
 operator bool () const noexcept
 Returns true if socket view is not null.

Static Public Member Functions

static void disableSigpipe () noexcept
 Disablea SIGPIPE signals on Linux for a current thread.

Protected Attributes

Socket_Tinstance = nullptr

Detailed Description

Network socket instance view.

See the socket.h

Constructor & Destructor Documentation

◆ SocketView()

SocketView ( Socket_T * instance)
inlinenoexcept

Creates a new network socket view.

Parameters
[in]instancetarget socket instance

Member Function Documentation

◆ destroy()

void destroy ( )
inlinenoexcept

Destroys network socket instance.

See the destroySocket().

◆ getType()

SocketType getType ( ) const
inlinenoexcept

Returns socket communication protocol type.

See the getSocketType().

◆ getFamily()

SocketFamily getFamily ( ) const
inlinenoexcept

Returns socket internet protocol (IP) address family type.

See the getSocketFamily().

◆ isBlocking()

bool isBlocking ( ) const
inlinenoexcept

Returns true if socket is in blocking mode.

See the isSocketBlocking().

◆ isOnlyIPv6()

bool isOnlyIPv6 ( ) const
inlinenoexcept

Returns true if IPv6 socket is not accepting IPv4 connections.

See the isSocketOnlyIPv6().

◆ getLocalAddress()

void getLocalAddress ( SocketAddressView socketAddress) const
inline

Gets local socket IP address.

See the getSocketLocalAddress().

Exceptions
Errorwith a result string on failure.
Parameters
[out]socketAddresssocket IP address instance

◆ getRemoteAddress()

void getRemoteAddress ( SocketAddressView socketAddress) const
inline

Gets remote socket IP address.

See the getSocketRemoteAddress().

Exceptions
Errorwith a result string on failure.
Parameters
[out]socketAddresssocket IP address instance

◆ getSslContext()

SslContextView getSslContext ( ) const
inlinenoexcept

Returns socket SSL context instance.

See the getSocketSslContext().

◆ getHandle()

void * getHandle ( ) const
inlinenoexcept

Returns socket internal handle.

See the getSocketHandle().

◆ isNoDelay()

bool isNoDelay ( ) const
inlinenoexcept

Returns true if stream socket sends without caching.

See the isSocketNoDelay().

◆ setNoDelay()

void setNoDelay ( bool value)
inlinenoexcept

Sets socket no delay mode.

Does stream socket sends without caching.

Parameters
valueno delay mode value

◆ isListening()

bool isListening ( ) const
inlinenoexcept

Returns true if socket is in the listening state.

See the isSocketListening().

◆ getQueueSize()

size_t getQueueSize ( ) const
inlinenoexcept

Returns socket pending connections queue size.

See the getSocketQueueSize().

◆ listen()

NetsResult listen ( size_t queueSize = 256)
inlinenoexcept

Puts socket in a listening state.

See the listenSocket().

Returns
The operation NetsResult code.
Parameters
queueSizepending connections queue size

◆ accept()

NetsResult accept ( SocketView & accepted)
inlinenoexcept

Accepts a new socket connection.

Note
You should destroy accepted socket instance manually!

See the acceptSocket().

Returns
The operation NetsResult code.
Parameters
[out]acceptedreference to the accepted socket

◆ acceptSsl()

NetsResult acceptSsl ( )
inlinenoexcept

Accepts socket SSL connection.

See the acceptSslSocket().

Returns
The operation NetsResult code.

◆ connect()

NetsResult connect ( SocketAddressView remoteAddress)
inlinenoexcept

Connects socket to the specified remote address.

See the connectSocket().

Returns
The operation NetsResult code.
Parameters
remoteAddressremote socket IP address instance

◆ connectSsl()

NetsResult connectSsl ( const char * hostname = nullptr)
inlinenoexcept

Establishes socket SSL connection.

See the connectSslSocket().

Returns
The operation NetsResult code.
Parameters
[in]hostnameremote socket SNI hostname or NULL

◆ shutdown()

NetsResult shutdown ( SocketShutdown shutdown = RECEIVE_SEND_SOCKET_SHUTDOWN)
inlinenoexcept

Shutdowns part of the full-duplex connection.

See the shutdownSocket().

Returns
The operation NetsResult code.
Parameters
shutdownsocket connection shutdown mode

◆ receive()

NetsResult receive ( void * receiveBuffer,
size_t bufferSize,
size_t & byteCount )
inlinenoexcept

Receives pending socket data.

See the socketReceive().

Returns
The operation NetsResult code.
Parameters
[out]receiveBufferdata receive buffer
bufferSizedata receive buffer size in bytes
[out]byteCountreference to the received byte count

◆ send() [1/2]

NetsResult send ( const void * data,
size_t byteCount )
inline

Sends specified data to the remote socket.

See the socketSend().

Returns
The operation NetsResult code.
Parameters
[in]datatarget data to send
byteCountdata byte count to send

◆ send() [2/2]

template<class T>
NetsResult send ( const T & data)
inline

Sends specified data to the remote socket.

See the socketSend().

Returns
The operation NetsResult code.
Template Parameters
Ttype of the send data
Parameters
[in]datatarget data to send

◆ receiveFrom()

NetsResult receiveFrom ( SocketAddressView remoteAddress,
void * receiveBuffer,
size_t bufferSize,
size_t & byteCount )
inlinenoexcept

Receives pending data from the remote socket.

See the socketReceiveFrom().

Returns
The operation NetsResult code.
Parameters
[out]remoteAddressremote socket IP address
[out]receiveBufferdata receive buffer
bufferSizedata receive buffer size in bytes
[out]byteCountreference to the received byte count

◆ sendTo() [1/2]

NetsResult sendTo ( const void * data,
size_t byteCount,
SocketAddressView remoteAddress )
inlinenoexcept

Sends specified data to the remote socket.

See the socketSendTo().

Returns
The operation NetsResult code.
Parameters
[in]datasend data buffer
byteCountdata byte count to send
remoteAddressdestination remote socket IP address

◆ sendTo() [2/2]

template<class T>
NetsResult sendTo ( const T & data,
SocketAddressView remoteAddress )
inlinenoexcept

Sends specified data to the remote socket.

See the socketSendTo().

Returns
The operation NetsResult code.
Template Parameters
Ttype of the send data
Parameters
[in]datatarget data to send
remoteAddressdestination remote socket IP address