A wrapper for TCP listener sockets inheriting from Socket.
More...
#include <C_socket.hpp>
|
enum | Type { TYPE_UDP
, TYPE_TCP
, TYPE_LISTENER_TCP
} |
| The possible types of sockets. More...
|
|
enum | Error {
ERR_NOERROR = 0
, ERR_SUCCESS = ERR_NOERROR
, ERR_DONE = ERR_NOERROR
, ERR_PARTIAL
,
ERR_NOTREADY
, ERR_DISCONNECTED
, ERR_REFUSED
, ERR_ALREADYCONNECTED
,
ERR_ALREADYUSED
, ERR_TOOMANYSOCKET
, ERR_NOTINIT
, ERR_INVALIDARGUMENT
,
ERR_UNSUCCESS
, ERR_UNKNOWN = ERR_UNSUCCESS
} |
| The error codes. More...
|
|
using | SocketDescriptor = int |
|
|
Type | g_type |
|
IpAddress::Types | g_addressType {IpAddress::Types::Ipv4} |
|
SocketDescriptor | g_socket |
|
bool | g_isBlocking |
|
A wrapper for TCP listener sockets inheriting from Socket.
◆ Error
◆ Type
The possible types of sockets.
◆ accept()
Accept a new connection.
- Parameters
-
socket | The socket to accept the connection into |
- Returns
- Error::ERR_NOERROR if successful, otherwise an error code
◆ close()
void fge::net::Socket::close |
( |
| ) |
|
|
inherited |
◆ create()
Create the socket listener.
- Returns
- Error::ERR_NOERROR if successful, otherwise an error code
Implements fge::net::Socket.
◆ getAddressType()
IpAddress::Types fge::net::Socket::getAddressType |
( |
| ) |
const |
|
inlinenodiscardinherited |
Get the address type of the socket.
By default, the address type is Ipv4.
- Returns
- The address type of the socket (Ipv4 or Ipv6)
◆ getLocalAddress()
Get the local address of the socket.
From MSDN: This function provide the only way to determine the local association that has been set by the system.
- Returns
- The local address of the socket or fge::net::IpAddress::None if there was an error
◆ getLocalPort()
fge::net::Port fge::net::Socket::getLocalPort |
( |
| ) |
const |
|
nodiscardinherited |
Get the local port of the socket.
From MSDN: This function provide the only way to determine the local association that has been set by the system.
- Returns
- The local port of the socket or 0 if there was an error
◆ getPlatformSpecifiedError()
static int fge::net::Socket::getPlatformSpecifiedError |
( |
| ) |
|
|
staticnodiscardinherited |
Get the last platform specific error code.
- Returns
- The last platform specific error code
◆ getRemoteAddress()
Get the remote address of the socket.
From MSDN: For datagram sockets, only the address of a peer specified in a previous connect call will be returned. Any address specified by a previous sendto call will not be returned.
- Returns
- The remote address of the socket or fge::net::IpAddress::None if there was an error
◆ getRemotePort()
fge::net::Port fge::net::Socket::getRemotePort |
( |
| ) |
const |
|
nodiscardinherited |
Get the remote port of the socket.
From MSDN: For datagram sockets, only the address of a peer specified in a previous connect call will be returned. Any address specified by a previous sendto call will not be returned.
- Returns
- The remote port of the socket or 0 if there was an error
◆ getType()
Type fge::net::Socket::getType |
( |
| ) |
const |
|
inlinenodiscardinherited |
Get the type of the socket.
Type can be one of the type defined in the Socket::Type enum
- Returns
- The type of the socket
◆ initSocket()
static bool fge::net::Socket::initSocket |
( |
| ) |
|
|
staticinherited |
Init the low-level socket library.
This call WSAStartup() on Windows and nothing on other platforms
- Returns
- true if successful, false otherwise
◆ isBlocking()
bool fge::net::Socket::isBlocking |
( |
| ) |
const |
|
nodiscardinherited |
Check if the socket is in blocking mode.
- Returns
- true if the socket is in blocking mode, false otherwise
◆ isValid()
bool fge::net::Socket::isValid |
( |
| ) |
const |
|
nodiscardinherited |
Check if the socket is valid.
The socket is valid if it has been created and not closed
- Returns
- true if the socket is valid, false otherwise
◆ listen()
Start listening for new connections from a port.
- Parameters
-
port | The port to listen on |
address | The address to listen on or fge::net::IpAddress::Any |
- Returns
- Error::ERR_NOERROR if successful, otherwise an error code
◆ select()
Error fge::net::Socket::select |
( |
bool | read, |
|
|
uint32_t | timeoutms ) |
|
inherited |
Check the socket for readability or writability.
From MSDN: The select function allows an application to determine the status of a socket.
If timeout is 0, the function returns immediately (polling).
- Parameters
-
read | true if the socket should be checked for readability, false otherwise |
timeoutms | The timeout in milliseconds |
- Returns
- Error::ERR_NOERROR if the socket is ready, otherwise an error code
◆ setAddressType()
void fge::net::Socket::setAddressType |
( |
IpAddress::Types | type | ) |
|
|
inherited |
Set the address type of the socket.
When the address type is changed, the socket is closed and recreated.
- Parameters
-
type | The address type of the socket (Ipv4 or Ipv6) |
◆ setBlocking()
Error fge::net::Socket::setBlocking |
( |
bool | mode | ) |
|
|
inherited |
Set the blocking mode of the socket.
- Parameters
-
mode | The blocking mode to set |
- Returns
- Error::ERR_NOERROR if successful, otherwise an error code
◆ setBroadcastOption()
Error fge::net::Socket::setBroadcastOption |
( |
bool | mode | ) |
|
|
inherited |
Set if the socket support broadcast.
From MSDN: The SO_BROADCAST socket option enables the socket to send and receive broadcast messages.
- Parameters
-
mode | The broadcast mode to set |
- Returns
- Error::ERR_NOERROR if successful, otherwise an error code
◆ setReuseAddress()
Error fge::net::Socket::setReuseAddress |
( |
bool | mode | ) |
|
|
inherited |
Set if the socket reuse the address.
From MSDN: The SO_REUSEADDR socket option allows the application to bind to an address that is already in use.
- Parameters
-
mode | The reuse mode to set |
- Returns
- Error::ERR_NOERROR if successful, otherwise an error code
◆ uninitSocket()
static void fge::net::Socket::uninitSocket |
( |
| ) |
|
|
staticinherited |
Shutdown the low-level socket library.
The documentation for this class was generated from the following file: