SFML 3.1.0
Loading...
Searching...
No Matches
SocketSelector.hpp
Go to the documentation of this file.
1
2//
3// SFML - Simple and Fast Multimedia Library
4// Copyright (C) 2007-2026 Laurent Gomila (laurent@sfml-dev.org)
5//
6// This software is provided 'as-is', without any express or implied warranty.
7// In no event will the authors be held liable for any damages arising from the use of this software.
8//
9// Permission is granted to anyone to use this software for any purpose,
10// including commercial applications, and to alter it and redistribute it freely,
11// subject to the following restrictions:
12//
13// 1. The origin of this software must not be misrepresented;
14// you must not claim that you wrote the original software.
15// If you use this software in a product, an acknowledgment
16// in the product documentation would be appreciated but is not required.
17//
18// 2. Altered source versions must be plainly marked as such,
19// and must not be misrepresented as being the original software.
20//
21// 3. This notice may not be removed or altered from any source distribution.
22//
24
25#pragma once
26
28// Headers
30#include <SFML/Network/Export.hpp>
31
32#include <SFML/System/Time.hpp>
33
34#include <functional>
35#include <memory>
36
37#include <cstdint>
38
39
40 namespace sf
41{
42 class Socket;
43
48 class SFML_NETWORK_API SocketSelector
49{
50 public:
51 using ReadinessType = std::uint32_t;
52
57 enum : ReadinessType
58 {
59 Receive = 1 << 0,
60 Send = 1 << 1,
61 };
62
67 SocketSelector();
68
73 ~SocketSelector();
74
81 SocketSelector(const SocketSelector& copy);
82
91 SocketSelector& operator=(const SocketSelector& right);
92
97 SocketSelector(SocketSelector&&) noexcept;
98
103 SocketSelector& operator=(SocketSelector&&) noexcept;
104
164 bool add(const Socket& socket,
165 ReadinessType readinessType = Receive,
166 std::function<void(ReadinessType readinessType)> readyCallback = {});
167
181 bool remove(const Socket& socket);
182
193 void clear();
194
212 [[nodiscard]] bool wait(Time timeout = Time::Zero);
213
232 [[nodiscard]] bool isReady(const Socket& socket, ReadinessType readinessType = Receive) const;
233
252 void dispatchReadyCallbacks();
253
254 private:
255 struct SocketSelectorImpl;
256
258 // Member data
260 std::unique_ptr<SocketSelectorImpl> m_impl;
261};
262
263} // namespace sf
264
265
Export.hpp
SFML_NETWORK_API
#define SFML_NETWORK_API
Definition Network/Export.hpp:42
Time.hpp
sf::SocketSelector::Send
@ Send
Check if sockets are ready to be sent to.
Definition SocketSelector.hpp:60
sf::SocketSelector::Receive
@ Receive
Check if sockets are ready to be received from.
Definition SocketSelector.hpp:59
sf::SocketSelector::ReadinessType
std::uint32_t ReadinessType
Bitwise combination of readiness types.
Definition SocketSelector.hpp:51
sf::SocketSelector::SocketSelector
SocketSelector(const SocketSelector &copy)
Copy constructor.
sf::SocketSelector::isReady
bool isReady(const Socket &socket, ReadinessType readinessType=Receive) const
Test a socket to know if it is ready to receive or send data.
sf::SocketSelector::SocketSelector
SocketSelector()
Default constructor.
sf::SocketSelector::remove
bool remove(const Socket &socket)
Remove a socket from the selector.
sf::SocketSelector::clear
void clear()
Remove all the sockets stored in the selector.
sf::SocketSelector::SocketSelector
SocketSelector(SocketSelector &&) noexcept
Move constructor.
sf::SocketSelector::~SocketSelector
~SocketSelector()
Destructor.
sf::SocketSelector::wait
bool wait(Time timeout=Time::Zero)
Wait until one or more sockets are ready to receive or send.
sf::SocketSelector::dispatchReadyCallbacks
void dispatchReadyCallbacks()
Dispatch callbacks of ready sockets.
sf::SocketSelector::add
bool add(const Socket &socket, ReadinessType readinessType=Receive, std::function< void(ReadinessType readinessType)> readyCallback={})
Add a new socket to the selector.
sf::SocketSelector::operator=
SocketSelector & operator=(const SocketSelector &right)
Overload of assignment operator.
sf::Socket
Base class for all the socket types.
Definition Socket.hpp:43
sf::Time
Represents a time value.
Definition Time.hpp:42
sf::Time::Zero
static const Time Zero
Predefined "zero" time value.
Definition Time.hpp:110
sf
Definition AudioResource.hpp:36