CSFML - C binding of the Simple and Fast Multimedia Library

CSFML
Functions
SocketSelector.h File Reference
`#include <SFML/Network/Export.h>`
`#include <SFML/Network/Types.h>`
`#include <SFML/System/Time.h>`

Go to the source code of this file.

## Functions
CSFML_NETWORK_API sfSocketSelector * | sfSocketSelector_create (void)
| Create a new selector. More...
CSFML_NETWORK_API sfSocketSelector * | sfSocketSelector_copy (const sfSocketSelector *selector)
| Create a new socket selector by copying an existing one. More...
CSFML_NETWORK_API void | sfSocketSelector_destroy (sfSocketSelector *selector)
| Destroy a socket selector. More...
CSFML_NETWORK_API void | sfSocketSelector_addTcpListener (sfSocketSelector *selector, sfTcpListener *socket)
| Add a new socket to a socket selector. More...
CSFML_NETWORK_API void | sfSocketSelector_addTcpSocket (sfSocketSelector *selector, sfTcpSocket *socket)
CSFML_NETWORK_API void | sfSocketSelector_addUdpSocket (sfSocketSelector *selector, sfUdpSocket *socket)
CSFML_NETWORK_API void | sfSocketSelector_removeTcpListener (sfSocketSelector *selector, sfTcpListener *socket)
| Remove a socket from a socket selector. More...
CSFML_NETWORK_API void | sfSocketSelector_removeTcpSocket (sfSocketSelector *selector, sfTcpSocket *socket)
CSFML_NETWORK_API void | sfSocketSelector_removeUdpSocket (sfSocketSelector *selector, sfUdpSocket *socket)
CSFML_NETWORK_API void | sfSocketSelector_clear (sfSocketSelector *selector)
| Remove all the sockets stored in a selector. More...
CSFML_NETWORK_API sfBool | sfSocketSelector_wait (sfSocketSelector *selector, sfTime timeout)
| Wait until one or more sockets are ready to receive. More...
CSFML_NETWORK_API sfBool | sfSocketSelector_isTcpListenerReady (const sfSocketSelector *selector, sfTcpListener *socket)
| Test a socket to know if it is ready to receive data. More...
CSFML_NETWORK_API sfBool | sfSocketSelector_isTcpSocketReady (const sfSocketSelector *selector, sfTcpSocket *socket)
CSFML_NETWORK_API sfBool | sfSocketSelector_isUdpSocketReady (const sfSocketSelector *selector, sfUdpSocket *socket)

## Function Documentation

## ◆ sfSocketSelector_addTcpListener()

CSFML_NETWORK_API 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()

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

## ◆ sfSocketSelector_addUdpSocket()

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

## ◆ sfSocketSelector_clear()

CSFML_NETWORK_API 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()

CSFML_NETWORK_API 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()

CSFML_NETWORK_API sfSocketSelector* sfSocketSelector_create | ( | void |  | ) |

Create a new selector.

Returns
  A new sfSocketSelector object

## ◆ sfSocketSelector_destroy()

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

Destroy a socket selector.

Parameters

  selector | Socket selector to destroy

## ◆ sfSocketSelector_isTcpListenerReady()

CSFML_NETWORK_API 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

## ◆ sfSocketSelector_isTcpSocketReady()

CSFML_NETWORK_API sfBool sfSocketSelector_isTcpSocketReady | ( | const sfSocketSelector * | selector,
|  | sfTcpSocket * | socket
| ) |  |

## ◆ sfSocketSelector_isUdpSocketReady()

CSFML_NETWORK_API sfBool sfSocketSelector_isUdpSocketReady | ( | const sfSocketSelector * | selector,
|  | sfUdpSocket * | socket
| ) |  |

## ◆ sfSocketSelector_removeTcpListener()

CSFML_NETWORK_API 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

## ◆ sfSocketSelector_removeTcpSocket()

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

## ◆ sfSocketSelector_removeUdpSocket()

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

## ◆ sfSocketSelector_wait()

CSFML_NETWORK_API 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