SocketSelector#

Functions

sfSocketSelector *sfSocketSelector_create(void)#

Create a new selector.

Returns:

A new sfSocketSelector object

sfSocketSelector *sfSocketSelector_copy(const sfSocketSelector *selector)#

Create a new socket selector by copying an existing one.

Parameters:
  • selector – Socket selector to copy

Returns:

A new sfSocketSelector object which is a copy of selector

void sfSocketSelector_destroy(sfSocketSelector *selector)#

Destroy a socket selector.

Parameters:
  • selector – Socket selector to destroy

void sfSocketSelector_addTcpListener(sfSocketSelector *selector, sfTcpListener *socket)#

Add a new socket to a socket selector.

This function keeps a weak pointer to the socket, so you have to make sure that the socket is not destroyed while it is stored in the selector.

Parameters:
  • selector – Socket selector object

  • socket – Pointer to the socket to add

void sfSocketSelector_addTcpSocket(sfSocketSelector *selector, sfTcpSocket *socket)#
void sfSocketSelector_addUdpSocket(sfSocketSelector *selector, sfUdpSocket *socket)#
void sfSocketSelector_removeTcpListener(sfSocketSelector *selector, sfTcpListener *socket)#

Remove a socket from a socket selector.

This function doesn’t destroy the socket, it simply removes the pointer that the selector has to it.

Parameters:
  • selector – Socket selector object

  • socket – POointer to the socket to remove

void sfSocketSelector_removeTcpSocket(sfSocketSelector *selector, sfTcpSocket *socket)#
void sfSocketSelector_removeUdpSocket(sfSocketSelector *selector, sfUdpSocket *socket)#
void sfSocketSelector_clear(sfSocketSelector *selector)#

Remove all the sockets stored in a selector.

This function doesn’t destroy any instance, it simply removes all the pointers that the selector has to external sockets.

Parameters:
  • selector – Socket selector object

sfBool sfSocketSelector_wait(sfSocketSelector *selector, sfTime timeout)#

Wait until one or more sockets are ready to receive.

This function returns as soon as at least one socket has some data available to be received. To know which sockets are ready, use the sfSocketSelector_isXxxReady functions. If you use a timeout and no socket is ready before the timeout is over, the function returns sfFalse.

Parameters:
  • selector – Socket selector object

  • timeout – Maximum time to wait (use sfTimeZero for infinity)

Returns:

sfTrue if there are sockets ready, sfFalse otherwise

sfBool sfSocketSelector_isTcpListenerReady(const sfSocketSelector *selector, sfTcpListener *socket)#

Test a socket to know if it is ready to receive data.

This function must be used after a call to sfSocketSelector_wait, to know which sockets are ready to receive data. If a socket is ready, a call to Receive will never block because we know that there is data available to read. Note that if this function returns sfTrue for a sfTcpListener, this means that it is ready to accept a new connection.

Parameters:
  • selector – Socket selector object

  • socket – Socket to test

Returns:

sfTrue if the socket is ready to read, sfFalse otherwise

sfBool sfSocketSelector_isTcpSocketReady(const sfSocketSelector *selector, sfTcpSocket *socket)#
sfBool sfSocketSelector_isUdpSocketReady(const sfSocketSelector *selector, sfUdpSocket *socket)#