IPV4 socket class.
More...
#include <murl_system_socket.h>
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.
|
SocketHandle * | mHandle |
| The anonymous socket handle for internal use only. More...
|
|
◆ Create()
Bool Murl::System::Socket::Create |
( |
const String & |
protocolName | ) |
|
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 |
( |
| ) |
|
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
-
- Returns
- true if successful.
◆ EnableReuseAddress()
Bool Murl::System::Socket::EnableReuseAddress |
( |
Bool |
enable | ) |
|
Enable/disable the reuse-address socket option.
- Parameters
-
- Returns
- true if successful.
◆ EnableKeepAlive()
Bool Murl::System::Socket::EnableKeepAlive |
( |
Bool |
enable | ) |
|
Enable/disable the keep-alive socket option.
- Parameters
-
- Returns
- true if successful.
◆ EnableBroadcast()
Bool Murl::System::Socket::EnableBroadcast |
( |
Bool |
enable | ) |
|
Enable/disable the Broadcast socket option.
- Parameters
-
- Returns
- true if successful.
◆ EnableNonBlocking()
Bool Murl::System::Socket::EnableNonBlocking |
( |
Bool |
enable | ) |
|
Enable/disable the non-blocking socket option.
- Parameters
-
- Returns
- true if successful.
◆ Bind()
Bind the socket to an address.
- Parameters
-
address | The address to bind to. |
- Returns
- true if successful.
◆ Connect()
Connect the socket to an address.
- Parameters
-
address | The address to connect to. |
- Returns
- true if successful.
◆ Listen()
Bool Murl::System::Socket::Listen |
( |
UInt32 |
maxQueue | ) |
|
Listen to the socket.
- Parameters
-
maxQueue | The 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
-
listenSocket | The 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
-
pairSocket | The socket to connect with this socket. |
- Returns
- true if successful.
◆ Select()
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 |
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
-
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()
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()
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()
Get the address of the socket.
- Returns
- The address object of the socket.
◆ GetLastError()
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()
Set the socket error code.
- Parameters
-
socketError | The socket error code. |
reason | The description for the reason. |
◆ 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: