sf::Socket::Status NETSERVER::acceptTime(sf::TcpListener &p_listener, sf::TcpSocket &p_client) { sf::SocketSelector selector; selector.add(p_listener); if(selector.wait(sf::seconds(0.5))) { return p_listener.accept(p_client); } else { return sf::Socket::NotReady; } } // acceptTime()
inline bool tryAccept(sf::TcpListener& mListener) { if(busy) { ssvu::lo("ManagedSocket") << "Error: already connected" << std::endl; return false; } for(int i{0}; i < 5; ++i) { if(!busy && mListener.accept(socket) == sf::Socket::Done) goto succeed; std::this_thread::sleep_for(std::chrono::milliseconds(50)); } return false; succeed: if(!busy) { ssvu::lo("ManagedSocket") << "Accepting..." << std::endl; busy = true; handlerFuture = std::async(std::launch::async, [this]{ while(busy) update(); }); } ssvu::lo("ManagedSocket") << "Accepted" << std::endl; return true; }