Murl::Net::ISocket Interface Referenceabstract

The socket interface. More...

#include "murl_net_i_socket.h"

Inherited by Murl::Net::Socket.

Public Types

using SharedPtr = SharedPointer< ISocket >
 Definition of the socket shared pointer.
 
using PtrArray = Array< SharedPtr >
 Definition of the socket shared pointer array.
 

Public Member Functions

virtual void SetName (const String &name)=0
 Set the name of the socket. More...
 
virtual const StringGetName () const =0
 Get the name of the socket. More...
 
virtual void SetUniqueIdentifier (const String &uniqueId)=0
 Set the unique identifier of the socket. More...
 
virtual const StringGetUniqueIdentifier () const =0
 Get the unique identifier of the socket. More...
 
virtual Bool ConnectTcp (ISocketAddressPtr address)=0
 Connects to a specified server address using tcp. More...
 
virtual Bool ConnectTcpNonBlocking (ISocketAddressPtr address)=0
 Connects to a specified server address using tcp with non blocking. More...
 
virtual Bool ConfirmConnectTcpNonBlocking ()=0
 Confirm connect using tcp with non blocking. More...
 
virtual Bool ConnectUdp (ISocketAddressPtr address)=0
 Connects to a specified server address using udp. More...
 
virtual Bool BindTcpListen (ISocketAddressPtr address, UInt32 maxQueue=5)=0
 Bind a listener to accept tcp connections. More...
 
virtual Bool BindUdpListen (ISocketAddressPtr address)=0
 Bind a listener to accept udp connections. More...
 
virtual Bool CreateUdpBroadcast ()=0
 Create a socket to send udp broadcast. More...
 
virtual Bool Disconnect ()=0
 Disconnect the socket. More...
 
virtual Bool IsConnected () const =0
 Check if the socket is connected. More...
 
virtual Bool IsConnecting () const =0
 Check if the socket is connecting in non blocking mode. More...
 
virtual Bool Accept (ISocket::SharedPtr listenSocket)=0
 Accept connection on the socket. More...
 
virtual Bool AcceptNonBlocking (ISocket::SharedPtr listenSocket)=0
 Accept connection on the socket. More...
 
virtual Bool Pair (ISocket::SharedPtr pairSocket)=0
 Create a socket pair ready to communicate. More...
 
virtual SInt32 Select (PtrArray &readSockets, PtrArray &writeSockets, Double timeout)=0
 Wait for ready to read and write sockets with timeout. More...
 
virtual Bool IsReadSelected () const =0
 Check if the socket was read selected during the last Select(). More...
 
virtual Bool IsWriteSelected () const =0
 Check if the socket was write selected during the last Select(). More...
 
virtual Bool Receive (Data &data)=0
 Receive data from the socket. More...
 
virtual Bool Send (const ConstData &data)=0
 Send the entire data to the socket. More...
 
virtual SInt64 Send (const ConstData &data, UInt64 byteOffset)=0
 Send data form a specified offset to the socket. More...
 
virtual Bool ReceiveFrom (Data &data, ISocketAddressPtr address)=0
 Receive data and the sender address from the socket. More...
 
virtual Bool SendTo (const ConstData &data, ISocketAddressPtr address)=0
 Send the entire data to a specified address. More...
 
virtual SInt64 SendTo (const ConstData &data, UInt64 byteOffset, ISocketAddressPtr address)=0
 Send data form a specified offset to a specified address. More...
 
virtual System::SocketGetSystemSocket ()=0
 Get the system socket object. More...
 
virtual const System::SocketGetSystemSocket () const =0
 Get the const system socket object. More...
 

Detailed Description

The socket interface.

Several methods are blocking calls when waiting for network response.

(!) Do not use this class directly in the logic code. Use Net::ISocketClient and Net::ISocketServer interfaces instead.

Member Function Documentation

◆ SetName()

virtual void Murl::Net::ISocket::SetName ( const String name)
pure virtual

Set the name of the socket.

Parameters
nameThe name of the socket.

◆ GetName()

virtual const String& Murl::Net::ISocket::GetName ( ) const
pure virtual

Get the name of the socket.

Returns
The name of the socket.

◆ SetUniqueIdentifier()

virtual void Murl::Net::ISocket::SetUniqueIdentifier ( const String uniqueId)
pure virtual

Set the unique identifier of the socket.

Parameters
uniqueIdThe unique identifier of the socket.

◆ GetUniqueIdentifier()

virtual const String& Murl::Net::ISocket::GetUniqueIdentifier ( ) const
pure virtual

Get the unique identifier of the socket.

Returns
The unique identifier of the socket.

◆ ConnectTcp()

virtual Bool Murl::Net::ISocket::ConnectTcp ( ISocketAddressPtr  address)
pure virtual

Connects to a specified server address using tcp.

Enables reuse-address, keep-alive and tcp-no-delay socket option.

Parameters
addressThe address of the server to connect.
Returns
true if successful.

◆ ConnectTcpNonBlocking()

virtual Bool Murl::Net::ISocket::ConnectTcpNonBlocking ( ISocketAddressPtr  address)
pure virtual

Connects to a specified server address using tcp with non blocking.

Enables reuse-address, keep-alive, tcp-no-delay and non-blocking socket option.

Parameters
addressThe address of the server to connect.
Returns
true if successful.

◆ ConfirmConnectTcpNonBlocking()

virtual Bool Murl::Net::ISocket::ConfirmConnectTcpNonBlocking ( )
pure virtual

Confirm connect using tcp with non blocking.

When connection by ConnectTcpNonBlocking() a write select to the socket indicates the connection and must be confirmed by calling this method.

Returns
true if connection established, false if connection error.

◆ ConnectUdp()

virtual Bool Murl::Net::ISocket::ConnectUdp ( ISocketAddressPtr  address)
pure virtual

Connects to a specified server address using udp.

Enables tcp-no-delay socket option.

Parameters
addressThe address of the server to connect.
Returns
true if successful.

◆ BindTcpListen()

virtual Bool Murl::Net::ISocket::BindTcpListen ( ISocketAddressPtr  address,
UInt32  maxQueue = 5 
)
pure virtual

Bind a listener to accept tcp connections.

Enables reuse-address and keep-alive socket option.

Parameters
addressThe address to listen for incoming connections. The address specifies the port to listen and the ip-address to find the correct network adapter (any-address is listening on all adapters).
maxQueueThe maximum length of the queue of pending connections.
Returns
true if successful.

◆ BindUdpListen()

virtual Bool Murl::Net::ISocket::BindUdpListen ( ISocketAddressPtr  address)
pure virtual

Bind a listener to accept udp connections.

Enables reuse-address socket option.

Parameters
addressThe address to listen for incoming connections. The address specifies the port to listen and the ip-address to find the correct network adapter (any-address is listening on all adapters).
Returns
true if successful.

◆ CreateUdpBroadcast()

virtual Bool Murl::Net::ISocket::CreateUdpBroadcast ( )
pure virtual

Create a socket to send udp broadcast.

Enables reuse-address and broadcast socket option.

Returns
true if successful.

◆ Disconnect()

virtual Bool Murl::Net::ISocket::Disconnect ( )
pure virtual

Disconnect the socket.

Returns
true if successful.

◆ IsConnected()

virtual Bool Murl::Net::ISocket::IsConnected ( ) const
pure virtual

Check if the socket is connected.

Returns
true if the socket is connected.

◆ IsConnecting()

virtual Bool Murl::Net::ISocket::IsConnecting ( ) const
pure virtual

Check if the socket is connecting in non blocking mode.

Returns
true if the socket is connected in non blocking mode.

◆ Accept()

virtual Bool Murl::Net::ISocket::Accept ( ISocket::SharedPtr  listenSocket)
pure virtual

Accept connection on the socket.

Enables keep-alive and tcp-no-delay socket option after accept.

Parameters
listenSocketThe socket which is listening for the connection.
Returns
true if successful.

◆ AcceptNonBlocking()

virtual Bool Murl::Net::ISocket::AcceptNonBlocking ( ISocket::SharedPtr  listenSocket)
pure virtual

Accept connection on the socket.

Enables keep-alive, tcp-no-delay and non-blocking socket option after accept.

Parameters
listenSocketThe socket which is listening for the connection.
Returns
true if successful.

◆ Pair()

virtual Bool Murl::Net::ISocket::Pair ( ISocket::SharedPtr  pairSocket)
pure virtual

Create a socket pair ready to communicate.

Parameters
pairSocketThe socket to connect with this socket.
Returns
true if successful.

◆ Select()

virtual SInt32 Murl::Net::ISocket::Select ( PtrArray readSockets,
PtrArray writeSockets,
Double  timeout 
)
pure virtual

Wait for ready to read and write sockets with timeout.

Parameters
readSocketsArray of read sockets to wait for.
writeSocketsArray of write sockets to wait for.
timeoutThe maximum time to wait in seconds, -1 for no timeout.
Returns
The number of selected sockets, zero if the timeout was reached or -1 if select failed.

◆ IsReadSelected()

virtual Bool Murl::Net::ISocket::IsReadSelected ( ) const
pure virtual

Check if the socket was read selected during the last Select().

The select status is valid until the next call of Select() or the socket is closed due to errors or Destroy() is called.

Returns
true if the socket was read selected during the last Select().

◆ IsWriteSelected()

virtual Bool Murl::Net::ISocket::IsWriteSelected ( ) const
pure virtual

Check if the socket was write selected during the last Select().

The select status is valid until the next call of Select() or the socket is closed due to errors or Destroy() is called.

Returns
true if the socket was write selected during the last Select().

◆ Receive()

virtual Bool Murl::Net::ISocket::Receive ( Data data)
pure virtual

Receive data from the socket.

Parameters
dataThe data object to store the incoming data. The data object's byte size is the maximum number of bytes to receive. If the data object is empty a size of 1500 bytes is reserved internally.
Returns
true if successful. The data object is resized to the number of bytes received, otherwise if receive failed the data object is empty.

◆ Send() [1/2]

virtual Bool Murl::Net::ISocket::Send ( const ConstData data)
pure virtual

Send the entire data to the socket.

Parameters
dataThe data to send.
Returns
true if successful.

◆ Send() [2/2]

virtual SInt64 Murl::Net::ISocket::Send ( const ConstData data,
UInt64  byteOffset 
)
pure virtual

Send data form a specified offset to the socket.

In non-blocking operation this method sends only a portion of data and has to be called in a loop which allows to monitor the data transfer.

Parameters
dataThe data to send.
byteOffsetThe data offset in number of bytes.
Returns
The number of bytes sent from the offset, zero if the data is empty or the data offset is invalid, a negative return value if a socket error occurs.

◆ ReceiveFrom()

virtual Bool Murl::Net::ISocket::ReceiveFrom ( Data data,
ISocketAddressPtr  address 
)
pure virtual

Receive data and the sender address from the socket.

This is typically used by sockets connected with ConnectUdpListen().

Parameters
dataThe data object to store the incoming data. The data object's byte size is the maximum number of bytes to receive. If the data object is empty a size of 1500 bytes is reserved internally.
addressThe sender address return value.
Returns
true if successful. The data object is resized to the number of bytes received, otherwise if receive failed the data object is empty.

◆ SendTo() [1/2]

virtual Bool Murl::Net::ISocket::SendTo ( const ConstData data,
ISocketAddressPtr  address 
)
pure virtual

Send the entire data to a specified address.

This is typically used by sockets connected with ConnectUdpBroadcast().

Parameters
dataThe data to send.
addressThe address to send the data.
Returns
true if successful.

◆ SendTo() [2/2]

virtual SInt64 Murl::Net::ISocket::SendTo ( const ConstData data,
UInt64  byteOffset,
ISocketAddressPtr  address 
)
pure virtual

Send data form a specified offset to a specified address.

In non-blocking operation this method sends only a portion of data and has to be called in a loop which allows to monitor the data transfer.

Parameters
dataThe data to send.
byteOffsetThe data offset in number of bytes.
addressThe address to send the data.
Returns
The number of bytes sent from the offset, zero if the data is empty or the data offset is invalid or the address is null, a negative return value if a socket error occurs.

◆ GetSystemSocket() [1/2]

virtual System::Socket& Murl::Net::ISocket::GetSystemSocket ( )
pure virtual

Get the system socket object.

Returns
The system socket object.

◆ GetSystemSocket() [2/2]

virtual const System::Socket& Murl::Net::ISocket::GetSystemSocket ( ) const
pure virtual

Get the const system socket object.

Returns
The const system socket object.

The documentation for this interface was generated from the following file:
  • murl_net_i_socket.h


Copyright © 2011-2024 Spraylight GmbH.