Improve SocketSelector in-documentation example

This commit is contained in:
Vittorio Romeo 2024-02-04 17:30:49 +01:00
parent 368ff9dace
commit 76295f2624

View File

@ -209,10 +209,13 @@ private:
/// \code /// \code
/// // Create a socket to listen to new connections /// // Create a socket to listen to new connections
/// sf::TcpListener listener; /// sf::TcpListener listener;
/// listener.listen(55001); /// if (listener.listen(55001) != sf::Socket::Status::Done)
/// {
/// // Handle error...
/// }
/// ///
/// // Create a list to store the future clients /// // Create a list to store the future clients
/// std::list<std::unique_ptr<sf::TcpSocket>> clients; /// std::vector<sf::TcpSocket> clients;
/// ///
/// // Create a selector /// // Create a selector
/// sf::SocketSelector selector; /// sf::SocketSelector selector;
@ -230,20 +233,19 @@ private:
/// if (selector.isReady(listener)) /// if (selector.isReady(listener))
/// { /// {
/// // The listener is ready: there is a pending connection /// // The listener is ready: there is a pending connection
/// auto client = std::make_unique<sf::TcpSocket>(); /// sf::TcpSocket client;
/// if (listener.accept(*client) == sf::Socket::Status::Done) /// if (listener.accept(client) == sf::Socket::Status::Done)
/// { /// {
/// // Add the new client to the selector so that we will /// // Add the new client to the selector so that we will
/// // be notified when he sends something /// // be notified when he sends something
/// selector.add(*client); /// selector.add(client);
/// ///
/// // Add the new client to the clients list /// // Add the new client to the clients list
/// clients.push_back(std::move(client)); /// clients.push_back(std::move(client));
/// } /// }
/// else /// else
/// { /// {
/// // Error, we won't get a new connection, delete the socket /// // Handle error...
/// client.reset();
/// } /// }
/// } /// }
/// else /// else