NetworkConnectionInterface Class Reference

#include <network_ip.h>

Inheritance diagram for NetworkConnectionInterface:

Detailed Description

This class offers basic network connection functions to read/send data and manage connections.

Classes

class  Properties
 

Public Member Functions

MAXON_METHOD Result< void > CloseConnection ()
 
MAXON_METHOD Result< void > KillConnection ()
 
MAXON_METHOD Result< IntBytesInInputBuffer ()
 
MAXON_METHOD Result< void > RecvBytes (const Block< Byte > &data)
 
MAXON_METHOD Result< IntRecvBytesEOS (const Block< Byte > &data)
 
MAXON_METHOD Result< void > SendBytes (const Block< const Byte > &buffer)
 
MAXON_METHOD Result< void > FlushWriteBuffer ()
 
MAXON_METHOD Result< void > ResetBuffers ()
 
MAXON_METHOD Int64 GetTransferedBytes () const
 
MAXON_METHOD NetworkIpAddrPort GetRemoteAddr () const
 
MAXON_METHOD NetworkIpAddrPort GetHostAddr () const
 
MAXON_METHOD SOCKET GetSocket () const
 
MAXON_METHOD Result< void > SetNonBlockingSocket (Bool nonBlockingSocket)
 
MAXON_METHOD Bool IsNonBlockingSocket () const
 
MAXON_METHOD Result< void > SetUseNagleAlgorithm (Bool useNagleAlgorithm)
 
MAXON_METHOD Bool GetUseNagleAlgorithm () const
 
MAXON_METHOD Result< void > SetTimeout (TimeValue timeoutInSeconds)
 
MAXON_METHOD TimeValue GetTimeout () const
 
MAXON_METHOD CONNECTIONTYPE GetConnectionType () const
 
MAXON_METHOD void SetConnectionType (CONNECTIONTYPE type)
 
MAXON_METHOD void SetThread (const ThreadRef &ref)
 
MAXON_METHOD String GetProxyServerInfo () const
 
MAXON_METHOD void SetProxyServerInfo (const String &proxyInfo)
 

Private Member Functions

 MAXON_INTERFACE (NetworkConnectionInterface, MAXON_REFERENCE_NORMAL, "net.maxon.interface.networkconnection")
 

Member Function Documentation

◆ MAXON_INTERFACE()

MAXON_INTERFACE ( NetworkConnectionInterface  ,
MAXON_REFERENCE_NORMAL  ,
"net.maxon.interface.networkconnection"   
)
private

◆ CloseConnection()

MAXON_METHOD Result<void> CloseConnection ( )

Closes a connection by closing the socket.

Returns
OK on success.

◆ KillConnection()

MAXON_METHOD Result<void> KillConnection ( )

Killing a connection and canceling the connected threads.

◆ BytesInInputBuffer()

MAXON_METHOD Result<Int> BytesInInputBuffer ( )

Returns the number of bytes that is available in the receive buffer.

Returns
Number of bytes available in the read stream. A value of -1 if an error occurred.

◆ RecvBytes()

MAXON_METHOD Result<void> RecvBytes ( const Block< Byte > &  data)

Reads the requested number of bytes from the connection. The function will not return before the number of requested bytes has been read or an error occurred.

Parameters
[in]dataBlock for data buffer with requested number of bytes to read.
Returns
OK on success.

◆ RecvBytesEOS()

MAXON_METHOD Result<Int> RecvBytesEOS ( const Block< Byte > &  data)

Reads the requested number of bytes from the connection to the end of the stream. The function will not return before the number of requested bytes has been read, an error occurred or the stream has been closed.

Parameters
[in]dataBlock for data buffer with requested number of bytes to read.
Returns
Returns the number of bytes read or the error.

◆ SendBytes()

MAXON_METHOD Result<void> SendBytes ( const Block< const Byte > &  buffer)

Sends the given number of bytes to the connection. The function will not return before the number of given bytes is sent or an error occurred. Full duplex connections will not flush the send buffer until FlushWriteBuffer() is called.

Parameters
[in]bufferBlock with the data to send.
Returns
OK on success.

◆ FlushWriteBuffer()

MAXON_METHOD Result<void> FlushWriteBuffer ( )

Flushes the write buffer and send the collected bytes to the network connection.

Returns
OK on success.

◆ ResetBuffers()

MAXON_METHOD Result<void> ResetBuffers ( )

Empties the read and write buffer for the next connection. This can be useful if the connection is of type keep alive.

Returns
OK on success.

◆ GetTransferedBytes()

MAXON_METHOD Int64 GetTransferedBytes ( ) const

Returns the number of transfered bytes. -1 if an error occurred.

◆ GetRemoteAddr()

MAXON_METHOD NetworkIpAddrPort GetRemoteAddr ( ) const

Returns the remote address of this connection.

◆ GetHostAddr()

MAXON_METHOD NetworkIpAddrPort GetHostAddr ( ) const

Returns the host address of this connection.

◆ GetSocket()

MAXON_METHOD SOCKET GetSocket ( ) const

◆ SetNonBlockingSocket()

MAXON_METHOD Result<void> SetNonBlockingSocket ( Bool  nonBlockingSocket)

Enables or disables a non-blocking socket for this connection. For a blocking mode, send or receive calls will wait until they succeeded or the set timeout was reached. In the non-blocking mode a read operation would try and return immediately if no data was available.

Parameters
[in]nonBlockingSocketEnabling or disabling the non-blocking socket

◆ IsNonBlockingSocket()

MAXON_METHOD Bool IsNonBlockingSocket ( ) const

Returns if a non-blocking socket is used for the current connection.

◆ SetUseNagleAlgorithm()

MAXON_METHOD Result<void> SetUseNagleAlgorithm ( Bool  useNagleAlgorithm)

Enables that Nagle algorithm of RFC 896, combining a number of small number of messages into one, reducing the overhead in transmission, but - on the flip side - increasing the latency of the transmission.

Parameters
[in]useNagleAlgorithmEnabling or disabling the Nagle algorithm

◆ GetUseNagleAlgorithm()

MAXON_METHOD Bool GetUseNagleAlgorithm ( ) const

Returns if the Nagle algorithm is used for the current connection.

◆ SetTimeout()

MAXON_METHOD Result<void> SetTimeout ( TimeValue  timeoutInSeconds)

Sets the timeout in case the current connection is blocked and can't send or receive. When exceeded the connection is closed.

Parameters
[in]timeoutInSecondsThe timeout value

◆ GetTimeout()

MAXON_METHOD TimeValue GetTimeout ( ) const

Returns the timeout set for the current connection.

◆ GetConnectionType()

MAXON_METHOD CONNECTIONTYPE GetConnectionType ( ) const

Returns the connection type of the current connection.

◆ SetConnectionType()

MAXON_METHOD void SetConnectionType ( CONNECTIONTYPE  type)

Sets the connection type (Listener, Incomming, Outgoing) for the current connection

Parameters
[in]typeThe type of the connection

◆ SetThread()

MAXON_METHOD void SetThread ( const ThreadRef ref)

This function is private.

The current thread will always be checked for cancellation. You only have to set a thread if an additional thread should be checked for cancellation, too.

Parameters
[in]refAn optional thread which will be checked for cancellation.

◆ GetProxyServerInfo()

MAXON_METHOD String GetProxyServerInfo ( ) const

Returns the stored proxy server information the was set using SetProxyInfo(). The format of the string is "<<server>>:<<port>>".

◆ SetProxyServerInfo()

MAXON_METHOD void SetProxyServerInfo ( const String proxyInfo)

Sets the proxy server to for later use of GetProxyInfo().

Parameters
[in]proxyInfoInfo to set. The format of the proxyInfo must be "<<server>>:<<port>>".