CSFML 3.0.0
Loading...
Searching...
No Matches
Functions
SocketSelector.h File Reference
`#include <CSFML/Network/Export.h>`
`#include <CSFML/Network/Types.h>`
`#include <CSFML/System/Time.h>`

Go to the source code of this file.

## Functions
sfSocketSelector * | sfSocketSelector_create (void)
| Create a new selector.
sfSocketSelector * | sfSocketSelector_copy (const sfSocketSelector *selector)
| Create a new socket selector by copying an existing one.
void | sfSocketSelector_destroy (const sfSocketSelector *selector)
| Destroy a socket selector.
void | sfSocketSelector_addTcpListener (sfSocketSelector *selector, sfTcpListener *socket)
| Add a new socket to a socket selector.
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.
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.
bool | sfSocketSelector_wait (sfSocketSelector *selector, sfTime timeout)
| Wait until one or more sockets are ready to receive.
bool | sfSocketSelector_isTcpListenerReady (const sfSocketSelector *selector, sfTcpListener *socket)
| Test a socket to know if it is ready to receive data.
bool | sfSocketSelector_isTcpSocketReady (const sfSocketSelector *selector, sfTcpSocket *socket)
bool | sfSocketSelector_isUdpSocketReady (const sfSocketSelector *selector, sfUdpSocket *socket)

## Function Documentation

## ◆ sfSocketSelector_addTcpListener()

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

## ◆ sfSocketSelector_addTcpSocket()

void sfSocketSelector_addTcpSocket | ( | sfSocketSelector * | selector,
|  | sfTcpSocket * | socket )

## ◆ sfSocketSelector_addUdpSocket()

void sfSocketSelector_addUdpSocket | ( | sfSocketSelector * | selector,
|  | sfUdpSocket * | socket )

## ◆ sfSocketSelector_clear()

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

## ◆ sfSocketSelector_copy()

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

## ◆ sfSocketSelector_create()

sfSocketSelector * sfSocketSelector_create | ( | void |  | ) |

Create a new selector.

Returns
  A new sfSocketSelector object

## ◆ sfSocketSelector_destroy()

void sfSocketSelector_destroy | ( | const sfSocketSelector * | selector | ) |

Destroy a socket selector.

Parameters

  selector | Socket selector to destroy

## ◆ sfSocketSelector_isTcpListenerReady()

bool 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 true for a sfTcpListener, this means that it is ready to accept a new connection.

Parameters

  selector | Socket selector object
  socket | Socket to test

Returns
  true if the socket is ready to read, false otherwise

## ◆ sfSocketSelector_isTcpSocketReady()

bool sfSocketSelector_isTcpSocketReady | ( | const sfSocketSelector * | selector,
|  | sfTcpSocket * | socket )

## ◆ sfSocketSelector_isUdpSocketReady()

bool sfSocketSelector_isUdpSocketReady | ( | const sfSocketSelector * | selector,
|  | sfUdpSocket * | socket )

## ◆ sfSocketSelector_removeTcpListener()

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 | Pointer to the socket to remove

## ◆ sfSocketSelector_removeTcpSocket()

void sfSocketSelector_removeTcpSocket | ( | sfSocketSelector * | selector,
|  | sfTcpSocket * | socket )

## ◆ sfSocketSelector_removeUdpSocket()

void sfSocketSelector_removeUdpSocket | ( | sfSocketSelector * | selector,
|  | sfUdpSocket * | socket )

## ◆ sfSocketSelector_wait()

bool 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 false.

Parameters

  selector | Socket selector object
  timeout | Maximum time to wait (use sfTimeZero for infinity)

Returns
  true if there are sockets ready, false otherwise