PLCnext API Documentation 25.0.2.69
Public Types | Public Member Functions | Friends | List of all members
Arp::System::Commons::Net::Socket Class Reference

Interface to realizes ethernet based communications. More...

#include <Socket.hpp>

Public Types

typedef std::shared_ptr< SocketPtr
 Contextual definition of pointer type.
 

Public Member Functions

 Socket (SocketType type, SocketDomain domain, SocketBlockingMode blockingMode)
 Constructs an Socket instance. More...
 
 Socket (const Socket &arg)=delete
 Copy contructor.
 
Socketoperator= (const Socket &arg)=delete
 Assignment operator.
 
 ~Socket (void)
 Destructs this instance and frees all resouces. More...
 
SocketType GetSocketType (void) const
 Returns the type of the socket. More...
 
SocketDomain GetSocketDomain (void) const
 Returns the utilized domain. More...
 
bool IsBlocking (void) const
 Checks if the socket is in blocking mode. More...
 
bool IsConnected (void) const
 Checks if the socket was connected yet with a remote peer. More...
 
IpAddress GetRemoteIpAddress (void) const
 If this socket is connected this method returns the ip-address (v4). More...
 
int GetRemotePort (void) const
 If this socket is connected this method returns the port of the connection. More...
 
Ptr Accept (IpAddress &ip4address, int &port, SocketError &error)
 Accepts a pending connection request. More...
 
SocketError Bind (const IpAddress &ip4Address, int port)
 Binds the socket to a specific address and port combination. More...
 
SocketError Bind2 (const IpAddress &ip4Address, int &port)
 Binds the socket to a specific address and port combination. More...
 
SocketError Connect (const IpAddress &ip4Address, int port)
 Tries to connect with a remote socket. More...
 
SocketError Listen (size_t backlog)
 Marks this socket as a passive socket that accepts incoming connection requests. More...
 
SocketError Shutdown (void)
 Shuts down a full-duplex connection. More...
 
SocketError Shutdown (ShutdownMode mode)
 Shuts down a full-duplex connection. More...
 
SocketError Close (void)
 Closes the socket. This ends all communication on the socket. More...
 
int Send (const void *pBuffer, size_t length, SocketError &error)
 Transmit data over the socket that is in a connected state. More...
 
int SendTo (const void *pBuffer, size_t length, IpAddress ip4Adress, int port, SocketError &error)
 Like Send but this method is to be used on sockets created with SocketType::Udp. More...
 
int Receive (void *pBuffer, size_t length, SocketError &error)
 Reads data from connected socket. More...
 
int ReceiveFrom (void *pBuffer, size_t length, IpAddress &ip4Adress, int &port, SocketError &error)
 Like Receive but this method is to be used on sockets created with SocketType::Udp. More...
 
bool Select (SelectMode mode, Microseconds timeout, SocketError &error)
 Checks if an i/o operation can be performed without blocking the calling thread. More...
 
int Poll (PollMode mode, Milliseconds timeout, SocketError &error)
 Checks if an i/o operation can be processed without blocking. More...
 
SocketError SetSocketOption (SocketOptionName optionName, const void *optionValue, size_t optionLength)
 Sets a single option on the socket. More...
 
SocketError GetSocketOption (SocketOptionName optionName, void *optionValue, size_t *optionLength) const
 Returns current value of queried socket option. More...
 
SocketError SetOptionReuseAddress (bool enabled)
 Enables/Disables the reuse-address option for this socket. More...
 
SocketError GetOptionReuseAddress (bool &enabled) const
 Checks if reuse-address is enabled. More...
 
SocketError SetOptionKeepAlive (bool enabled)
 Enables/Disables the keep-alive option for this socket. More...
 
SocketError GetOptionKeepAlive (bool &enabled) const
 Checks if keep-alive is enabled. More...
 
SocketError SetOptionBroadcast (bool enabled)
 Enables/Disables broadcast for this socket. More...
 
SocketError GetOptionBroadcast (bool &enabled) const
 Checks if broadcast is enabled. More...
 
SocketError SetOptionNoDelay (bool enabled)
 Enables/Disables no-delay for this socket. More...
 
SocketError GetOptionNoDelay (bool &enabled) const
 Checks if no-delay is enabled. More...
 
SocketError SetOptionBlocking (bool enable)
 Enables/disables the blocking mode of this socket.. More...
 
SocketError SetOptionLinger (bool enable, size_t timeout)
 Sets the amount of time a socket resides in TIME_WAIT state after active close. More...
 
SocketError GetOptionLinger (bool &enable, size_t &timeout)
 Returns the current linger options. For more information see Arp::System::Commons::Net::Socket::SetOptionLinger More...
 
SocketError SetOptionUserTimeout (size_t timeout_ms)
 Sets the retransmission timeout of a socket. This only works on Linux. More...
 
SocketError GetOptionUserTimeout (size_t &timeout_ms)
 Gets the retransmission timeout of a socket. This only works on Linux. For more information see Arp::System::Commons::Net::Socket::SetOptionUserTimeout More...
 
SocketError SetOptionKeepAliveIdleTime (int seconds)
 Sets the time that the socket needs to be idle for, before the Keep Alive mechanism can start if the KeepAlive SocketOption is set to true. More...
 
SocketError GetOptionKeepAliveIdleTime (int &seconds)
 Gets the time that the socket needs to be idle for, before the Keep Alive mechanism can start if the KeepAlive SocketOption is set to true. For more information see Arp::System::Commons::Net::Socket::SetOptionKeepAliveIdleTime More...
 
SocketError SetOptionKeepAliveProbeInterval (int seconds)
 Sets the interval time in between each Keep Alive probe, if the KeepAlive SocketOption is set to true. More...
 
SocketError GetOptionKeepAliveProbeInterval (int &seconds)
 Gets the interval time in between each Keep Alive probe, if the KeepAlive SocketOption is set to true. For more information see Arp::System::Commons::Net::Socket::SetOptionKeepAliveProbeInterval More...
 
SocketError SetOptionKeepAliveProbeCount (int probeCount)
 Sets the amount of probes to be sent, if the KeepAlive SocketOption is set to true. More...
 
SocketError GetOptionKeepAliveProbeCount (int &probeCount)
 Gets the amount of probes to be sent, if the KeepAlive SocketOption is set to true. For more information see Arp::System::Commons::Net::Socket::SetOptionKeepAliveProbeCount More...
 

Friends

class TlsSocket
 
class TlsSocket2
 

Detailed Description

Interface to realizes ethernet based communications.

Instances of this class can be used to realize an ethernet based communication with remote peers. By now 2 different types of protocols are supported. Either UPD or TCP. A simple TCP echo server can be realized with the following code.

class TcpEchoServer
{
public:
TcpEchoServer(void);
void Process();
private:
Socket listeningSocket;
};
inline TcpEchoServer::TcpEchoServer(void) : listeningSocket(SocketType::Tcp, SocketDomain::Ipv4, SocketBlockingMode::Blocking)
{}
void TcpEchoServer::Process()
{
int port = 45451;
// Bind the port to any local address.
if (listeningSocket.Bind(0, port) != SocketError::None)
{
return;
}
// Make socket a passive listener that processes incoming connection requests.
if (listeningSocket.Listen(10) != SocketError::None)
{
return;
}
uint32 remoteIp;
int remotePort;
SocketError error;
// Wait for the first client that requests a connection and accept it.
Socket::Ptr newSocket = listeningSocket.Accept(remoteIp, remotePort, error);
if (newSocket != nullptr)
{
byte buffer[256];
// No receive any message and reply it directly to the sender.
while (true)
{
memset(buffer, 0, sizeof(buffer));
int bytesReceived = newSocket->Receive(buffer, sizeof(buffer), error);
int sendResult = newSocket->Send(buffer, bytesReceived, error);
}
(void) newSocket->Shutdown();
(void) newSocket->Close();
}
}
Interface to realizes ethernet based communications.
Definition: Socket.hpp:118
std::shared_ptr< Socket > Ptr
Contextual definition of pointer type.
Definition: Socket.hpp:122
High level API to create and manage a processes.
Definition: Process.hpp:20
std::uint32_t uint32
The Arp unsigned integer type of 4 byte size.
Definition: PrimitiveTypes.hpp:33
SocketDomain
Supported communication domains, selecting the protocol for communication.
Definition: SocketDomain.hpp:14
@ Ipv4
Communication is based on internet protocol version 4.
SocketType
Enumeration of supported socket types.
Definition: SocketType.hpp:14
SocketError
Possible error codes for socket operation results.
Definition: SocketError.hpp:15
SocketBlockingMode
Supported blocking modes.
Definition: Socket.hpp:28
@ Blocking
Socket is in blocking mode, i.e. the Send*, Receive* and Accept methods will block if no data is avai...

The server uses a single passive socket called listenigSocket that is used to wait for a single connection. Therefore the socket is created during instance creation of the TcpEchoServer-object as a blocking TCP socket that uses Ipv4 protocol. In the Process method the socket is then bound to all local network interfaces and port 45451. Note that from this time on, no other socket can be bound to any address and port 45451 since the socket has enable reusing of addresses. See Arp::System::Commons::Net::Socket::SetOptionReuseAddress for more information. Afterwards the socket is marked as passive socket listening for incoming connection request by invoking Arp::System::Commons::Net::Socket::Listen. Since the socket is a blocking socket the server will block at the accept call until a connection request reaches the socket. Afterwards it justs reads any data of up to 256 bytes and simply returns them to the sender.

A client on the same machine can then connect and communicate with the server using the following code

int32 address = 127 + (0 << 8) + (0 << 16) + (1 << 24);
SocketError error = socket.Connect(address, 45451);
if (error == SocketError::None)
{
char *pMessage = "test-message";
int bytes = socket.Send(pMessage, strlen(pMessage), error);
char message[256];
bytes = socket.Receive(message, sizeof(message), error);
}
std::int32_t int32
The Arp integer type of 4 byte size.
Definition: PrimitiveTypes.hpp:35
@ Tcp
Socket uses TCP protocol.
@ None
The Socket operation succeeded.

Constructor & Destructor Documentation

◆ Socket()

Arp::System::Commons::Net::Socket::Socket ( SocketType  typeArg,
SocketDomain  domainArg,
SocketBlockingMode  blockingMode 
)

Constructs an Socket instance.

Parameters
typeThe type of socket to be created.
domainThe address domain for the socket. Currently only SocketDomain::Ipv4 is supported.
blockingModeThe blocking mode of the socket.

◆ ~Socket()

Arp::System::Commons::Net::Socket::~Socket ( void  )

Destructs this instance and frees all resouces.

This will also close the socket if it is not yet closed.

Member Function Documentation

◆ Accept()

Socket::Ptr Arp::System::Commons::Net::Socket::Accept ( IpAddress ip4address,
int &  port,
SocketError error 
)

Accepts a pending connection request.

Before a socket can accept connection requests, it must be Bind with an address and must be set to Listen state.

If no connection request is pending and the socket is in

  • blocking mode, the call blocks until a remote peer sends a connection request
  • non-blocking mode, the call returns a nullptr and error is set to SocketError::WouldBlock

Currently only ip v4 addresses are supported. The address must be encoded in a single 32 bit value. For an example how to encode the address see the example in the class description.

Parameters
ip4addressholds the 32 bit encoded ip v4 address of the connected peer socket.
portHolds the port number of the connected peer socket.
errorHolds error code in case the method returns nullptr.
Returns
Pointer to class instance representing accepted socket, nullptr otherwise.

◆ Bind()

SocketError Arp::System::Commons::Net::Socket::Bind ( const IpAddress ip4Address,
int  port 
)

Binds the socket to a specific address and port combination.

Currently only ip v4 addresses are supported. The address must be encoded in a single 32 bit value. For an example how to encode the address see the example in the class description.

To bind this socket to all local interfaces, 0 has to be assigned to parameter ip4Address.

Parameters
ip4AddressIP v4 based address to connect to.
portPort number to connect with.
Returns
See SocketError for more information on possible return values.

◆ Bind2()

SocketError Arp::System::Commons::Net::Socket::Bind2 ( const IpAddress ip4Address,
int &  port 
)

Binds the socket to a specific address and port combination.

bind2 returns the actual port used by this socket in the port parameter in contrast to bind i.e. use bind(ip, 0) to let the os choose the port to use, after the call port will contain the port choosed by the os.

Currently only ip v4 addresses are supported. The address must be encoded in a single 32 bit value. For an example how to encode the address see the example in the class description.

To bind this socket to all local interfaces, 0 has to be assigned to parameter ip4Address.

Parameters
ip4AddressIP v4 based address to connect to.
portPort number to connect with.
Returns
See SocketError for more information on possible return values.

◆ Close()

SocketError Arp::System::Commons::Net::Socket::Close ( void  )

Closes the socket. This ends all communication on the socket.

After Close() no further calls (i.e. a new connect()) on this socket are possible thus the socket instance must be destroyed.

Returns
See SocketError for more information on possible return values.

◆ Connect()

SocketError Arp::System::Commons::Net::Socket::Connect ( const IpAddress ip4Address,
int  port 
)

Tries to connect with a remote socket.

Currently only ip v4 addresses are supported. The address must be encoded in a single 32 bit value. For an example how to encode the address see the example in the class description.

Parameters
ip4AddressIP v4 based address to connect to.
portPort number to connect with.
Returns
See SocketError for more information on possible return values.

◆ GetOptionBroadcast()

SocketError Arp::System::Commons::Net::Socket::GetOptionBroadcast ( bool &  enabled) const

Checks if broadcast is enabled.

See SetOptionBroadcast for more information.

Parameters
enabledContainer for current option state.
Returns
See SocketError for more information on possible return values.

◆ GetOptionKeepAlive()

SocketError Arp::System::Commons::Net::Socket::GetOptionKeepAlive ( bool &  enabled) const

Checks if keep-alive is enabled.

See SetOptionKeepAlive for more information.

Parameters
enabledContainer for current option state.
Returns
See SocketError for more information on possible return values.

◆ GetOptionKeepAliveIdleTime()

SocketError Arp::System::Commons::Net::Socket::GetOptionKeepAliveIdleTime ( int &  seconds)

Gets the time that the socket needs to be idle for, before the Keep Alive mechanism can start if the KeepAlive SocketOption is set to true. For more information see Arp::System::Commons::Net::Socket::SetOptionKeepAliveIdleTime

Parameters
secondsGets the required Keep Alive socket idle time duration in seconds if Keep Alive is enabled.
Returns
See SocketError for more information on possible return values.

◆ GetOptionKeepAliveProbeCount()

SocketError Arp::System::Commons::Net::Socket::GetOptionKeepAliveProbeCount ( int &  probeCount)

Gets the amount of probes to be sent, if the KeepAlive SocketOption is set to true. For more information see Arp::System::Commons::Net::Socket::SetOptionKeepAliveProbeCount

Parameters
probeCountGets the amount of Keep Alive probes to be sent if Keep Alive is enabled.
Returns
See SocketError for more information on possible return values.

◆ GetOptionKeepAliveProbeInterval()

SocketError Arp::System::Commons::Net::Socket::GetOptionKeepAliveProbeInterval ( int &  seconds)

Gets the interval time in between each Keep Alive probe, if the KeepAlive SocketOption is set to true. For more information see Arp::System::Commons::Net::Socket::SetOptionKeepAliveProbeInterval

Parameters
secondsGets the interval in seconds in between Keep Alive probes if Keep Alive is enabled.
Returns
See SocketError for more information on possible return values.

◆ GetOptionLinger()

SocketError Arp::System::Commons::Net::Socket::GetOptionLinger ( bool &  enable,
size_t &  timeout 
)

Returns the current linger options. For more information see Arp::System::Commons::Net::Socket::SetOptionLinger

Parameters
enableTrue if linger option is active, otherwise false.
timeoutHolds current timeout value in seconds if linger is activated on this socket.
Returns
See SocketError for more information on possible return values.

◆ GetOptionNoDelay()

SocketError Arp::System::Commons::Net::Socket::GetOptionNoDelay ( bool &  enabled) const

Checks if no-delay is enabled.

See SetOptionNoDelay for more information.

Parameters
enabledContainer for current option state.
Returns
See SocketError for more information on possible return values.

◆ GetOptionReuseAddress()

SocketError Arp::System::Commons::Net::Socket::GetOptionReuseAddress ( bool &  enabled) const

Checks if reuse-address is enabled.

See SetOptionReuseAddress for more information

Parameters
enabledContainer for current option state.
Returns
See SocketError for more information on possible return values.

◆ GetOptionUserTimeout()

SocketError Arp::System::Commons::Net::Socket::GetOptionUserTimeout ( size_t &  timeout_ms)

Gets the retransmission timeout of a socket. This only works on Linux. For more information see Arp::System::Commons::Net::Socket::SetOptionUserTimeout

Parameters
timeout_msHolds the current retransmission timeout value in milliseconds if it has been set on this socket.
Returns
See SocketError for more information on possible return values.

◆ GetRemoteIpAddress()

IpAddress Arp::System::Commons::Net::Socket::GetRemoteIpAddress ( void  ) const

If this socket is connected this method returns the ip-address (v4).

This returned address is encoded in network byte order.

Returns
The ip-address (v4) of the remote peer if this socket is connected, otherwise 0 is returned.

◆ GetRemotePort()

int Arp::System::Commons::Net::Socket::GetRemotePort ( void  ) const

If this socket is connected this method returns the port of the connection.

The port number is returned in host byte order, not in network byte order.

Returns
The port of the connection if this port is connected, otherwise 0 is returned.

◆ GetSocketDomain()

SocketDomain Arp::System::Commons::Net::Socket::GetSocketDomain ( void  ) const

Returns the utilized domain.

Returns
The utilized domain.

◆ GetSocketOption()

SocketError Arp::System::Commons::Net::Socket::GetSocketOption ( SocketOptionName  optionName,
void *  optionValue,
size_t *  optionLength 
) const

Returns current value of queried socket option.

Parameters
optionNameName of option where current value is queried.
optionValuePointer to buffer where current socket option value is to be stored.
optionLengthValue-Result argument. Must be initialized to byte size of buffer pointed to by optionValue. Holds amount of bytes set in buffer optionValue after call returned.
Returns
See SocketError for more information on possible return values.

◆ GetSocketType()

SocketType Arp::System::Commons::Net::Socket::GetSocketType ( void  ) const

Returns the type of the socket.

Returns
Type of socket.

◆ IsBlocking()

bool Arp::System::Commons::Net::Socket::IsBlocking ( void  ) const

Checks if the socket is in blocking mode.

Returns
True if socket is in blocking mode, otherwise false is returned.

◆ IsConnected()

bool Arp::System::Commons::Net::Socket::IsConnected ( void  ) const

Checks if the socket was connected yet with a remote peer.

This operation does not check, if the connection to the remote peer is still available.

Returns
true if this socket was connected yet, otherwise false.

◆ Listen()

SocketError Arp::System::Commons::Net::Socket::Listen ( size_t  backlog)

Marks this socket as a passive socket that accepts incoming connection requests.

A socket in listening state features an internal queue where incoming connection requests are stored until they are processed by an Accept invocation. The maximal capacity of this queue is determined by the parameter backlog. If a connection request arrives while the queue is filled, the client may receive an error telling that the connection is refused or, if the utilized protocol allows retransmissions, the request may be ignored so that a consecutive reattempt to connnect may succeed.

Parameters
backlogDefines the maximum number of pending connection requests.
Returns
See SocketError for more information on possible return values.

◆ Poll()

int Arp::System::Commons::Net::Socket::Poll ( PollMode  mode,
Milliseconds  timeout,
SocketError error 
)

Checks if an i/o operation can be processed without blocking.

Parameters
modeSpecifies the i/o operation to be checked.
timeoutSpecifies the timeout to wait for the socket to get ready for the i/o operation. If set to zero, the call will return immediately. Milliseconds(-1) determines infinite.
errorThe resulting socket error, if any error occur.
Returns
1 if the specified i/o operation might be processed without blocking. The error is <cref name="SocketError::ConnectionReset" >, if the socket was closed local or remote. 0 if this operation timed out. -1 if any error occurs. Check the error to get more infos about the error.

◆ Receive()

int Arp::System::Commons::Net::Socket::Receive ( void *  pBuffer,
size_t  length,
SocketError error 
)

Reads data from connected socket.

Parameters
pBufferPointer to buffer where read data can be stored.
lengthCapacity in bytes of buffer pBuffer.
errorContainer variable holding error code after call returned.
Returns
Amount of bytes read from socket, -1 in case of failure.

◆ ReceiveFrom()

int Arp::System::Commons::Net::Socket::ReceiveFrom ( void *  pBuffer,
size_t  length,
IpAddress ip4Adress,
int &  port,
SocketError error 
)

Like Receive but this method is to be used on sockets created with SocketType::Udp.

Parameters
pBufferPointer to buffer where read data can be stored.
lengthCapacity in bytes of buffer pBuffer.
ip4AdressSource address (ip v4 only) of received data.
portSource port number of received data.
errorContainer variable holding error code after call returned.
Returns
Amount of bytes read from socket, -1 in case of failure.

◆ Select()

bool Arp::System::Commons::Net::Socket::Select ( SelectMode  mode,
Microseconds  timeout,
SocketError error 
)

Checks if an i/o operation can be performed without blocking the calling thread.

Parameters
modeDetermines the i/o operation to be checked.
timeoutSpecifies the time to wait for the socket to be ready for the i/o operation. If set to zero, the call will return immediately.
errorContainer variable holding error code after call returned.
Returns
true if the specified i/o operation can be performed without blocking, otherwise false is returned. true is also returned, when the socket was closed local or remote (Linux socket API behaviour!). The only way to determine if the socket is still alive, is through a subsequent call of <cref name="Socket::Receive">.

This operation is a legacy operation, use <cref name="Socket::Poll"> instead.

◆ Send()

int Arp::System::Commons::Net::Socket::Send ( const void *  pBuffer,
size_t  length,
SocketError error 
)

Transmit data over the socket that is in a connected state.

Parameters
pBufferPointer to buffer containing serialized data to be send.
lengthAmount of bytes to be send.
errorContainer variable holding error code after call returned.
Returns
Amount of transmitted bytes, -1 in case of failure.

◆ SendTo()

int Arp::System::Commons::Net::Socket::SendTo ( const void *  pBuffer,
size_t  length,
IpAddress  ip4Adress,
int  port,
SocketError error 
)

Like Send but this method is to be used on sockets created with SocketType::Udp.

Parameters
pBufferPointer to buffer containing serialized data to be send.
lengthAmount of bytes to be send.
ip4AdressDestination address (ip v4 only) for data.
portDestination port number for data.
errorContainer variable holding error code after call returned.
Returns
Amount of transmitted bytes, -1 in case of failure.

◆ SetOptionBlocking()

SocketError Arp::System::Commons::Net::Socket::SetOptionBlocking ( bool  enable)

Enables/disables the blocking mode of this socket..

Parameters
enabletrue if the blocking mode shall be enabled, otherwise false.
Returns
SocketError for more information on possible return values.

◆ SetOptionBroadcast()

SocketError Arp::System::Commons::Net::Socket::SetOptionBroadcast ( bool  enabled)

Enables/Disables broadcast for this socket.

This option is only valid for datagram sockets and can be used to enable the sending of packets to broadcast addresses.

Parameters
enabledSet to tro true activate option, otherwise set to false.
Returns
See SocketError for more information on possible return values.

◆ SetOptionKeepAlive()

SocketError Arp::System::Commons::Net::Socket::SetOptionKeepAlive ( bool  enabled)

Enables/Disables the keep-alive option for this socket.

Enables the sending of keep-alive probes to remote peers to check if a connection is still up if no data was transmitted for a while.

This option is only valid for connection-based sockets.

Parameters
enabledSet to true to activate option, otherwise set to false.
Returns
See SocketError for more information on possible return values.

◆ SetOptionKeepAliveIdleTime()

SocketError Arp::System::Commons::Net::Socket::SetOptionKeepAliveIdleTime ( int  seconds)

Sets the time that the socket needs to be idle for, before the Keep Alive mechanism can start if the KeepAlive SocketOption is set to true.

Parameters
secondsSets the required Keep Alive socket idle time duration in seconds if Keep Alive is set to true.
Returns
See SocketError for more information on possible return values.

◆ SetOptionKeepAliveProbeCount()

SocketError Arp::System::Commons::Net::Socket::SetOptionKeepAliveProbeCount ( int  probeCount)

Sets the amount of probes to be sent, if the KeepAlive SocketOption is set to true.

Parameters
probeCountSets the amount of Keep Alive probes to be sent if Keep Alive is enabled.
Returns
See SocketError for more information on possible return values.

◆ SetOptionKeepAliveProbeInterval()

SocketError Arp::System::Commons::Net::Socket::SetOptionKeepAliveProbeInterval ( int  seconds)

Sets the interval time in between each Keep Alive probe, if the KeepAlive SocketOption is set to true.

Parameters
secondsSets the interval in seconds in between Keep Alive probes if Keep Alive is enabled.
Returns
See SocketError for more information on possible return values.

◆ SetOptionLinger()

SocketError Arp::System::Commons::Net::Socket::SetOptionLinger ( bool  enable,
size_t  timeout 
)

Sets the amount of time a socket resides in TIME_WAIT state after active close.

The port of a connection that is activly closed, i.e. first calls Arp::System::Commons::Net::Socket::Close will reside in a state called TIME_WAIT for a specific amount of time. This prevents subsequently delivered packages to be considered to belong to a potential new established connection using the same port.

The time a port is in TIME_WAIT state can be adjusted using this method. A smaller timeout can be of interest if the system has to manage a lot of connections that only are active for a small amount of time. In this case a small timeout will prevent a lot of socket residing in TIME_WAIT and are therefore unavailable for creation of new connections.

Parameters
enableSet to true to activate new linger timeout, false otherwise.
timeoutThe new linger timeout in seconds.
Returns
See SocketError for more information on possible return values.

◆ SetOptionNoDelay()

SocketError Arp::System::Commons::Net::Socket::SetOptionNoDelay ( bool  enabled)

Enables/Disables no-delay for this socket.

If this option is enabled packets are not buffered by the TCP stack stack to optimize the network usage by only sending sufficiently large amount of data. Instead even small packets are send immediately over the network.

Parameters
enabledSet to tro true activate option, otherwise set to false.
Returns
See SocketError for more information on possible return values.

◆ SetOptionReuseAddress()

SocketError Arp::System::Commons::Net::Socket::SetOptionReuseAddress ( bool  enabled)

Enables/Disables the reuse-address option for this socket.

Activating this option changes the validation process for socket bindings. If the option is disabled and one port is for example bound to 0.0.0.0:21 (any local address and port 21) another port can not be bound to 192.168.0.4:21 because the wildcard IP address 0.0.0.0 conflicts with the other address. If the option is enabled, bounding the second socket will succeed.

Parameters
enabledSet to true to enable the option, otherwise set to false.
Returns
See SocketError for more information on possible return values.

◆ SetOptionUserTimeout()

SocketError Arp::System::Commons::Net::Socket::SetOptionUserTimeout ( size_t  timeout_ms)

Sets the retransmission timeout of a socket. This only works on Linux.

By default, in the case of a retransmission, the system will use the global "tcp_retries2" value in a backoff algorithm (Doubles each try) in order to try and resend its data. Generally this can last for around 13-30 minutes, depending on the "tcl_retries2" value.

During this time, the socket will not be able to enter an idle state, therefore blocking the KeepAlive mechanism until after the retransmission phase has completed, even if the connection is no longer valid.

This SocketOption enables a timeout that will override the maximum length the rentransmission phase can last, on order to be able to utilize KeepAlive to detect a broken connection before the long retransmission phase ends.

It is generally adviced that the timeout should be set slightly lower than the total time the KeepAlive process takes, to ensure that both retransmission occurs and KeepAlive probes are able to be sent.

Parameters
timeout_msSets a new retransmission timeout in milliseconds.
Returns
See SocketError for more information on possible return values.

◆ SetSocketOption()

SocketError Arp::System::Commons::Net::Socket::SetSocketOption ( SocketOptionName  optionName,
const void *  optionValue,
size_t  optionLength 
)

Sets a single option on the socket.

Parameters
optionNameName of option ot be set.
optionValuePointer to additional data for socket option.
optionLengthByte size of buffer pointed to by optionValue.
Returns
See SocketError for more information on possible return values.

◆ Shutdown() [1/2]

SocketError Arp::System::Commons::Net::Socket::Shutdown ( ShutdownMode  mode)

Shuts down a full-duplex connection.

After the shutdown has been called, further reception and transmission on the socket is disallowed.

Parameters
modeSpecifies if read or write operations should be shutdown.
Returns
See SocketError for more information on possible return values.

◆ Shutdown() [2/2]

SocketError Arp::System::Commons::Net::Socket::Shutdown ( void  )

Shuts down a full-duplex connection.

After the shutdown has been called, further reception and transmission on the socket is disallowed.

Returns
See SocketError for more information on possible return values.

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