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 String & | GetName () 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 String & | GetUniqueIdentifier () 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::Socket & | GetSystemSocket ()=0 |
Get the system socket object. More... | |
virtual const System::Socket & | GetSystemSocket () 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()
|
pure virtual |
Set the name of the socket.
- Parameters
-
name The name of the socket.
◆ GetName()
|
pure virtual |
Get the name of the socket.
- Returns
- The name of the socket.
◆ SetUniqueIdentifier()
|
pure virtual |
Set the unique identifier of the socket.
- Parameters
-
uniqueId The unique identifier of the socket.
◆ GetUniqueIdentifier()
|
pure virtual |
Get the unique identifier of the socket.
- Returns
- The unique identifier of the socket.
◆ ConnectTcp()
|
pure virtual |
Connects to a specified server address using tcp.
Enables reuse-address, keep-alive and tcp-no-delay socket option.
- Parameters
-
address The address of the server to connect.
- Returns
- true if successful.
◆ ConnectTcpNonBlocking()
|
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
-
address The address of the server to connect.
- Returns
- true if successful.
◆ 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()
|
pure virtual |
Connects to a specified server address using udp.
Enables tcp-no-delay socket option.
- Parameters
-
address The address of the server to connect.
- Returns
- true if successful.
◆ BindTcpListen()
|
pure virtual |
Bind a listener to accept tcp connections.
Enables reuse-address and keep-alive socket option.
- Parameters
-
address The 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). maxQueue The maximum length of the queue of pending connections.
- Returns
- true if successful.
◆ BindUdpListen()
|
pure virtual |
Bind a listener to accept udp connections.
Enables reuse-address socket option.
- Parameters
-
address The 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()
|
pure virtual |
Create a socket to send udp broadcast.
Enables reuse-address and broadcast socket option.
- Returns
- true if successful.
◆ Disconnect()
|
pure virtual |
Disconnect the socket.
- Returns
- true if successful.
◆ IsConnected()
|
pure virtual |
Check if the socket is connected.
- Returns
- true if the socket is connected.
◆ IsConnecting()
|
pure virtual |
Check if the socket is connecting in non blocking mode.
- Returns
- true if the socket is connected in non blocking mode.
◆ Accept()
|
pure virtual |
Accept connection on the socket.
Enables keep-alive and tcp-no-delay socket option after accept.
- Parameters
-
listenSocket The socket which is listening for the connection.
- Returns
- true if successful.
◆ AcceptNonBlocking()
|
pure virtual |
Accept connection on the socket.
Enables keep-alive, tcp-no-delay and non-blocking socket option after accept.
- Parameters
-
listenSocket The socket which is listening for the connection.
- Returns
- true if successful.
◆ Pair()
|
pure virtual |
Create a socket pair ready to communicate.
- Parameters
-
pairSocket The socket to connect with this socket.
- Returns
- true if successful.
◆ Select()
|
pure virtual |
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 in seconds, -1 for no timeout.
- Returns
- The number of selected sockets, zero if the timeout was reached or -1 if select failed.
◆ IsReadSelected()
|
pure virtual |
◆ IsWriteSelected()
|
pure virtual |
◆ 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() [1/2]
Send the entire data to the socket.
- Parameters
-
data The data to send.
- Returns
- true if successful.
◆ Send() [2/2]
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, a negative return value if a socket error occurs.
◆ ReceiveFrom()
|
pure virtual |
Receive data and the sender address from the socket.
This is typically used by sockets connected with ConnectUdpListen().
- 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() [1/2]
|
pure virtual |
Send the entire data to a specified address.
This is typically used by sockets connected with ConnectUdpBroadcast().
- Parameters
-
data The data to send. address The address to send the data.
- Returns
- true if successful.
◆ SendTo() [2/2]
|
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
-
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 or the address is null, a negative return value if a socket error occurs.
◆ GetSystemSocket() [1/2]
|
pure virtual |
Get the system socket object.
- Returns
- The system socket object.
◆ GetSystemSocket() [2/2]
|
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