IPV4 socket class. More...
#include "murl_system_socket.h"
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 () const |
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 SocketAddress & | GetAddress () const |
Get the address of the socket. More... | |
IEnums::SocketError | GetLastError () const |
Get the last socket error code. More... | |
Protected Member Functions | |
Bool | VerifyCreated () const |
Verify if the socket is created and set the corresponding socket error code. More... | |
Bool | VerifyNotCreated () const |
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 () const |
Close the socket. | |
Protected Attributes | |
SocketHandle * | mHandle |
The anonymous socket handle for internal use only. | |
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()
Create the socket by protocol name.
- Parameters
-
protocolName The 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 | ( | ) | const |
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()
Enable/disable the tcp-no-delay socket option.
- Parameters
-
enable The enabled state.
- Returns
- true if successful.
◆ EnableReuseAddress()
Enable/disable the reuse-address socket option.
- Parameters
-
enable The enabled state.
- Returns
- true if successful.
◆ EnableKeepAlive()
Enable/disable the keep-alive socket option.
- Parameters
-
enable The enabled state.
- Returns
- true if successful.
◆ EnableBroadcast()
Enable/disable the Broadcast socket option.
- Parameters
-
enable The enabled state.
- Returns
- true if successful.
◆ EnableNonBlocking()
Enable/disable the non-blocking socket option.
- Parameters
-
enable The enabled state.
- Returns
- true if successful.
◆ Bind()
Bool Murl::System::Socket::Bind | ( | const SocketAddress & | address | ) |
Bind the socket to an address.
- Parameters
-
address The address to bind to.
- Returns
- true if successful.
◆ Connect()
Bool Murl::System::Socket::Connect | ( | const SocketAddress & | address | ) |
Connect the socket to an address.
- Parameters
-
address The address to connect to.
- Returns
- true if successful.
◆ Listen()
Listen to the socket.
- Parameters
-
maxQueue The maximum length of the queue of pending connections.
- Returns
- true if successful.
◆ Accept()
Accept connection on the socket.
- Parameters
-
listenSocket The socket which is listening for the connection.
- Returns
- true if successful.
◆ Pair()
Create a socket pair ready to communicate.
- Parameters
-
pairSocket The 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
-
readSockets Array of read sockets to wait for. writeSockets Array of write sockets to wait for. timeout The 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 |
◆ IsWriteSelected()
Bool Murl::System::Socket::IsWriteSelected | ( | ) | const |
◆ Receive()
Receive data from the socket.
- Parameters
-
data The 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()
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
-
data The data to send. byteOffset The 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
-
data The 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. address The 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
-
data The data to send. byteOffset The data offset in number of bytes. address The 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()
|
protected |
Verify if the socket is created and set the corresponding socket error code.
- Returns
- true if the socket is created.
◆ 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()
|
protected |
Set the socket error code.
- Parameters
-
socketError The socket error code. reason The description for the reason.
The documentation for this class was generated from the following file:
- murl_system_socket.h