Nazara Engine  0.4
A fast, complete, cross-platform API designed for game development
Nz::SocketPoller Class Reference

Network class allowing an application to wait on multiples sockets for them to become active (readable) More...

Public Member Functions

 SocketPoller ()
 Constructs an empty SocketPoller object.
 
 SocketPoller (SocketPoller &&) noexcept=default
 
 ~SocketPoller ()
 Destructs the SocketPoller. More...
 
void Clear ()
 Clears the SocketPoller. More...
 
bool IsReadyToRead (const AbstractSocket &socket) const
 Checks if a specific socket is ready to read data. More...
 
bool IsReadyToWrite (const AbstractSocket &socket) const
 Checks if a specific socket is ready to write data. More...
 
bool IsRegistered (const AbstractSocket &socket) const
 Checks if a specific socket is registered in the SocketPoller. More...
 
bool RegisterSocket (AbstractSocket &socket, SocketPollEventFlags eventFlags)
 Register a socket in the SocketPoller. More...
 
void UnregisterSocket (AbstractSocket &socket)
 Unregister a socket from the SocketPoller. More...
 
bool Wait (int msTimeout)
 Wait until any registered socket switches to a ready state. More...
 
SocketPolleroperator= (SocketPoller &&) noexcept=default
 

Detailed Description

Network class allowing an application to wait on multiples sockets for them to become active (readable)

Constructor & Destructor Documentation

◆ ~SocketPoller()

Nz::SocketPoller::~SocketPoller ( )

Destructs the SocketPoller.

Remarks
When the SocketPoller gets destroyed, all sockets are automatically unregistered from it.

Member Function Documentation

◆ Clear()

void Nz::SocketPoller::Clear ( )

Clears the SocketPoller.

This function reverts the SocketPoller to the initial state, unregistering every socket from the SocketPoller.

See also
Unregister

◆ IsReadyToRead()

bool Nz::SocketPoller::IsReadyToRead ( const AbstractSocket socket) const

Checks if a specific socket is ready to read data.

This function allows you to read the results of the last Wait operation and if a specific socket is ready to read (has incoming data).

A socket in the ready to read state (with the exception of TcpServer) has incoming data and can be read without blocking.

Remarks
You must call Wait before using this function in order to refresh the read state.
A socket must be registered with SocketPollerEvent_Read event flag for its read state to be watched
A TcpServer socket becomes ready to read when it is ready to accept a new client.
Parameters
socketReference to the socket to check
Returns
True if the socket is available for reading without blocking, false otherwise
See also
Wait

◆ IsReadyToWrite()

bool Nz::SocketPoller::IsReadyToWrite ( const AbstractSocket socket) const

Checks if a specific socket is ready to write data.

This function allows you to read the results of the last Wait operation and if a specific socket is ready to write (can be written to without blocking).

Remarks
You must call Wait before using this function in order to refresh the read state.
A socket must be registered with SocketPollerEvent_Write event flag for its read state to be watched
Parameters
socketReference to the socket to check
Returns
True if the socket is available for writing without blocking, false otherwise
See also
Wait

◆ IsRegistered()

bool Nz::SocketPoller::IsRegistered ( const AbstractSocket socket) const

Checks if a specific socket is registered in the SocketPoller.

A registered socket is part of the SocketPoller and will be checked by the next Wait operations.

Parameters
socketReference to the socket to check
Returns
True if the socket is registered, false otherwise
See also
RegisterSocket
UnregisterSocket

◆ RegisterSocket()

bool Nz::SocketPoller::RegisterSocket ( AbstractSocket socket,
SocketPollEventFlags  eventFlags 
)

Register a socket in the SocketPoller.

A registered socket is part of the SocketPoller and will be checked by the next Wait operations according to the event flags passed when registered.

The SocketPoller keeps a reference to the internal handle of registered socket, which should not be freed while it is registered in the SocketPooler.

It is possible for this function to fail if too many sockets are registered in the SocketPoller, the maximum number of socket handled limit is OS-dependent.

Remarks
It is an error to register a socket twice in the same SocketPoller.
The socket should not be freed while it is registered in the SocketPooler.
Parameters
socketReference to the socket to register
eventFlagsSocket events to watch
Returns
True if the socket is registered, false otherwise
See also
IsRegistered
UnregisterSocket

◆ UnregisterSocket()

void Nz::SocketPoller::UnregisterSocket ( AbstractSocket socket)

Unregister a socket from the SocketPoller.

After calling UnregisterSocket, the socket is no longer part of the SocketPoller and thus, not taken into account by any further Wait call until registered again.

This function must be called before destroying a socket part of the SocketPoller.

Remarks
It is an error to try to unregister a non-registered socket from a SocketPoller.
Parameters
socketReference to the socket to unregister
See also
IsRegistered
RegisterSocket

◆ Wait()

bool Nz::SocketPoller::Wait ( int  msTimeout)

Wait until any registered socket switches to a ready state.

Waits a specific/undetermined amount of time until at least one socket part of the SocketPoller becomes ready. To query the ready state of the registered socket, use the IsReadyToRead or IsReadyToWrite functions.

Parameters
msTimeoutMaximum time to wait in milliseconds, 0 will returns immediately and -1 will block indefinitely
Returns
True if at least one socket registered to the poller is ready.
Remarks
It is an error to try to unregister a non-registered socket from a SocketPoller.
See also
IsReady
RegisterSocket

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