IPV4 socket class. More...

#include "murl_system_socket.h"

Inheritance diagram for Murl::System::Socket:

Public Member Functions

 Socket ()
 The default constructor.
 
virtual ~Socket ()
 The destructor.
 
Bool Create (const String &protocolName)
 Create the socket by protocol name. More...
 
Bool Destroy ()
 Destroy the socket. More...
 
Bool IsCreated () const
 Check if the socket is created. More...
 
Bool HasError ()
 Check and clear the last socket error. More...
 
Bool EnableTcpNoDelay (Bool enable)
 Enable/disable the tcp-no-delay socket option. More...
 
Bool EnableReuseAddress (Bool enable)
 Enable/disable the reuse-address socket option. More...
 
Bool EnableKeepAlive (Bool enable)
 Enable/disable the keep-alive socket option. More...
 
Bool EnableBroadcast (Bool enable)
 Enable/disable the Broadcast socket option. More...
 
Bool EnableNonBlocking (Bool enable)
 Enable/disable the non-blocking socket option. More...
 
Bool Bind (const SocketAddress &address)
 Bind the socket to an address. More...
 
Bool Connect (const SocketAddress &address)
 Connect the socket to an address. More...
 
Bool Listen (UInt32 maxQueue)
 Listen to the socket. More...
 
Bool Accept (const Socket &listenSocket)
 Accept connection on the socket. More...
 
Bool Pair (Socket &pairSocket)
 Create a socket pair ready to communicate. More...
 
SInt32 Select (SocketArray &readSockets, SocketArray &writeSockets, const Time &timeout)
 Wait for ready to read and write sockets with timeout. More...
 
Bool IsReadSelected () const
 Check if the socket was read selected during the last Select(). More...
 
Bool IsWriteSelected () const
 Check if the socket was write selected during the last Select(). More...
 
Bool Receive (Data &data)
 Receive data from the socket. More...
 
SInt64 Send (const ConstData &data, UInt64 byteOffset)
 Send data form a specified offset to the socket. More...
 
Bool ReceiveFrom (Data &data, SocketAddress &address)
 Receive data and the sender address from the socket. More...
 
SInt64 SendTo (const ConstData &data, UInt64 byteOffset, const SocketAddress &address)
 Send data form a specified offset to a specified address. More...
 
const SocketAddressGetAddress () const
 Get the address of the socket. More...
 
IEnums::SocketError GetLastError () const
 Get the last socket error code. More...
 

Protected Member Functions

Bool VerifyCreated ()
 Verify if the socket is created and set the corresponding socket error code. More...
 
Bool VerifyNotCreated ()
 Verify if the socket is not created and set the corresponding socket error code. More...
 
void SetLastError (IEnums::SocketError socketError, const String &reason)
 Set the socket error code. More...
 
void Close ()
 Close the socket.
 

Protected Attributes

SocketHandle * mHandle
 The anonymous socket handle for internal use only. More...
 

Detailed Description

IPV4 socket class.

Platform independent low-level abstraction of the Berkeley socket api. 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

◆ Create()

Bool Murl::System::Socket::Create ( const String protocolName)

Create the socket by protocol name.

Parameters
protocolNameThe protocol name. If the protocol name is "udp" a datagram socket is created, otherwise e.g. for "tcp" a stream socket is created.
Returns
true is successful.

◆ Destroy()

Bool Murl::System::Socket::Destroy ( )

Destroy the socket.

Returns
true is successful.

◆ IsCreated()

Bool Murl::System::Socket::IsCreated ( ) const

Check if the socket is created.

Returns
true if the socket is created.

◆ HasError()

Bool Murl::System::Socket::HasError ( )

Check and clear the last socket error.

This method does not set or clear the GetLastError() code.

Returns
true if the socket has an error.

◆ EnableTcpNoDelay()

Bool Murl::System::Socket::EnableTcpNoDelay ( Bool  enable)

Enable/disable the tcp-no-delay socket option.

Parameters
enableThe enabled state.
Returns
true if successful.

◆ EnableReuseAddress()

Bool Murl::System::Socket::EnableReuseAddress ( Bool  enable)

Enable/disable the reuse-address socket option.

Parameters
enableThe enabled state.
Returns
true if successful.

◆ EnableKeepAlive()

Bool Murl::System::Socket::EnableKeepAlive ( Bool  enable)

Enable/disable the keep-alive socket option.

Parameters
enableThe enabled state.
Returns
true if successful.

◆ EnableBroadcast()

Bool Murl::System::Socket::EnableBroadcast ( Bool  enable)

Enable/disable the Broadcast socket option.

Parameters
enableThe enabled state.
Returns
true if successful.

◆ EnableNonBlocking()

Bool Murl::System::Socket::EnableNonBlocking ( Bool  enable)

Enable/disable the non-blocking socket option.

Parameters
enableThe enabled state.
Returns
true if successful.

◆ Bind()

Bool Murl::System::Socket::Bind ( const SocketAddress address)

Bind the socket to an address.

Parameters
addressThe address to bind to.
Returns
true if successful.

◆ Connect()

Bool Murl::System::Socket::Connect ( const SocketAddress address)

Connect the socket to an address.

Parameters
addressThe address to connect to.
Returns
true if successful.

◆ Listen()

Bool Murl::System::Socket::Listen ( UInt32  maxQueue)

Listen to the socket.

Parameters
maxQueueThe maximum length of the queue of pending connections.
Returns
true if successful.

◆ Accept()

Bool Murl::System::Socket::Accept ( const Socket listenSocket)

Accept connection on the socket.

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

◆ Pair()

Bool Murl::System::Socket::Pair ( Socket pairSocket)

Create a socket pair ready to communicate.

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

◆ Select()

SInt32 Murl::System::Socket::Select ( SocketArray readSockets,
SocketArray writeSockets,
const Time timeout 
)

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, set to System::Time::Infinite() for blocking operation.
Returns
The number of selected sockets, zero if the timeout was reached or -1 if select failed.

◆ IsReadSelected()

Bool Murl::System::Socket::IsReadSelected ( ) const

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()

Bool Murl::System::Socket::IsWriteSelected ( ) const

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()

Bool Murl::System::Socket::Receive ( Data data)

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()

SInt64 Murl::System::Socket::Send ( const ConstData data,
UInt64  byteOffset 
)

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, -1 if a socket error occurs.

◆ ReceiveFrom()

Bool Murl::System::Socket::ReceiveFrom ( Data data,
SocketAddress address 
)

Receive data and the sender address 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.
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()

SInt64 Murl::System::Socket::SendTo ( const ConstData data,
UInt64  byteOffset,
const SocketAddress address 
)

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, -1 if a socket error occurs.

◆ GetAddress()

const SocketAddress& Murl::System::Socket::GetAddress ( ) const

Get the address of the socket.

Returns
The address object of the socket.

◆ GetLastError()

IEnums::SocketError Murl::System::Socket::GetLastError ( ) const

Get the last socket error code.

When calling a socket method the error code is set to the result of the operation performed by the method.

Returns
The last socket error code.

◆ VerifyCreated()

Bool Murl::System::Socket::VerifyCreated ( )
protected

Verify if the socket is created and set the corresponding socket error code.

Returns
true if the socket is created.

◆ VerifyNotCreated()

Bool Murl::System::Socket::VerifyNotCreated ( )
protected

Verify if the socket is not created and set the corresponding socket error code.

Returns
true if the socket is not created.

◆ SetLastError()

void Murl::System::Socket::SetLastError ( IEnums::SocketError  socketError,
const String reason 
)
protected

Set the socket error code.

Parameters
socketErrorThe socket error code.
reasonThe description for the reason.

Member Data Documentation

◆ mHandle

SocketHandle* Murl::System::Socket::mHandle
protected

The anonymous socket handle for internal use only.


The documentation for this class was generated from the following file:
  • murl_system_socket.h


Copyright © 2011-2018 Spraylight GmbH.