ReXGlue SDK
Loading...
Searching...
No Matches
rex::platform::Socket Class Reference

#include <rex/platform/socket.h>

Inheritance diagram for rex::platform::Socket:
[legend]

Public Member Functions

 Socket (SocketHandle handle)
 Socket (Socket &&other) noexcept
Socket & operator= (Socket &&other) noexcept
bool IsValid () const
SocketHandle GetHandle () const
i32 Connect (const sockaddr *name, i32 name_len) const
i32 Bind (const sockaddr *name, i32 name_len) const
i32 GetLocalName (sockaddr *name, i32 *name_len) const
i32 Listen (i32 backlog) const
Socket Accept (sockaddr *name, i32 *name_len) const
i32 Shutdown (i32 how) const
i32 Recv (void *buf, i32 len, i32 flags) const
i32 RecvFrom (void *buf, i32 len, i32 flags, sockaddr *from, i32 *from_len) const
i32 Send (const void *buf, i32 len, i32 flags) const
i32 SendTo (const void *buf, i32 len, i32 flags, const sockaddr *to, i32 to_len) const
i32 SetOption (i32 level, i32 name, const void *value, i32 len) const
i32 GetOption (i32 level, i32 name, void *value, i32 *len) const
i32 GetPeerName (sockaddr *name, i32 *name_len) const
i32 IOCTL (u32 cmd, u8 *arg) const
i32 Prepare (WaitHandle *event) const

Static Public Member Functions

static Socket Create (i32 family, i32 type, i32 protocol)

Additional Inherited Members

Protected Member Functions inherited from rex::MoveOnly
 MoveOnly (MoveOnly &&)=default
MoveOnly & operator= (MoveOnly &&)=default
 MoveOnly (const MoveOnly &)=delete
MoveOnly & operator= (const MoveOnly &)=delete

Detailed Description

Owns a native socket. The destructor closes it, and a move leaves the source empty.

Constructor & Destructor Documentation

◆ Socket()

rex::platform::Socket::Socket ( SocketHandle handle)
inlineexplicit

Takes ownership of a native socket.

Parameters
handleThe socket, or kInvalidSocket.

Member Function Documentation

◆ Accept()

Socket rex::platform::Socket::Accept ( sockaddr * name,
i32 * name_len ) const

Accepts a connection.

Parameters
nameReceives the peer address.
name_lenThe size of the address buffer, then the size of the peer address.
Returns
The connected socket, empty with GetSocketError set on failure.

◆ Bind()

i32 rex::platform::Socket::Bind ( const sockaddr * name,
i32 name_len ) const

Binds to an address.

Returns
0 on success, -1 with GetSocketError set.

◆ Connect()

i32 rex::platform::Socket::Connect ( const sockaddr * name,
i32 name_len ) const

Connects to an address.

Returns
0 on success, -1 with GetSocketError set.

◆ Create()

Socket rex::platform::Socket::Create ( i32 family,
i32 type,
i32 protocol )
static

Creates a native socket.

Returns
The socket, empty with GetSocketError set on failure.

◆ GetHandle()

SocketHandle rex::platform::Socket::GetHandle ( ) const
inline

Returns the native socket, kInvalidSocket when empty.

◆ GetLocalName()

i32 rex::platform::Socket::GetLocalName ( sockaddr * name,
i32 * name_len ) const

Reads the local address.

Parameters
nameReceives the local address.
name_lenThe size of the address buffer, then the size of the local address.
Returns
0 on success, -1 with GetSocketError set.

◆ GetOption()

i32 rex::platform::Socket::GetOption ( i32 level,
i32 name,
void * value,
i32 * len ) const

Reads a socket option.

Parameters
valueReceives the option value.
lenThe size of the value buffer, then the size of the value.
Returns
0 on success, -1 with GetSocketError set.

◆ GetPeerName()

i32 rex::platform::Socket::GetPeerName ( sockaddr * name,
i32 * name_len ) const

Reads the address of the connected peer.

Parameters
nameReceives the peer address.
name_lenThe size of the address buffer, then the size of the peer address.
Returns
0 on success, -1 with GetSocketError set.

◆ IOCTL()

i32 rex::platform::Socket::IOCTL ( u32 cmd,
u8 * arg ) const
inline

Runs an ioctl request through SocketIOCTL.

Parameters
argThe argument buffer, read and written in place.
Returns
0 on success, or the platform error return value.

◆ Listen()

i32 rex::platform::Socket::Listen ( i32 backlog) const

Starts listening for connections.

Parameters
backlogThe length of the pending connection queue.
Returns
0 on success, -1 with GetSocketError set.

◆ Prepare()

i32 rex::platform::Socket::Prepare ( WaitHandle * event) const
inline

Prepares the socket through SocketPrepare.

Parameters
eventA manual reset event whose Set ends a WaitSockets on the socket.
Returns
0 on success, or the platform error return value.

◆ Recv()

i32 rex::platform::Socket::Recv ( void * buf,
i32 len,
i32 flags ) const

Receives data.

Returns
The byte count, or -1 with GetSocketError set.

◆ RecvFrom()

i32 rex::platform::Socket::RecvFrom ( void * buf,
i32 len,
i32 flags,
sockaddr * from,
i32 * from_len ) const

Receives a datagram.

Parameters
fromReceives the sender address.
from_lenThe size of the address buffer, then the size of the sender address.
Returns
The byte count, or -1 with GetSocketError set.

◆ Send()

i32 rex::platform::Socket::Send ( const void * buf,
i32 len,
i32 flags ) const

Sends data. A send to a closed peer raises no signal.

Returns
The byte count, or -1 with GetSocketError set.

◆ SendTo()

i32 rex::platform::Socket::SendTo ( const void * buf,
i32 len,
i32 flags,
const sockaddr * to,
i32 to_len ) const

Sends a datagram. A send to a closed peer raises no signal.

Parameters
toThedestination, null for the connected peer.
Returns
The byte count, or -1 with GetSocketError set.

◆ SetOption()

i32 rex::platform::Socket::SetOption ( i32 level,
i32 name,
const void * value,
i32 len ) const

Sets a socket option.

Returns
0 on success, -1 with GetSocketError set.

◆ Shutdown()

i32 rex::platform::Socket::Shutdown ( i32 how) const

Shuts a connection down.

Returns
0 on success, -1 with GetSocketError set.

The documentation for this class was generated from the following file: