mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2024-11-15 05:47:56 -07:00
InputCommon: instead of blocking on individual DSU server sockets, block on a selector built up from all server sockets
This commit is contained in:
parent
5f7d935b0a
commit
dbb0b72cc5
@ -202,18 +202,6 @@ static bool IsSameController(const Proto::MessageType::PortInfo& a,
|
|||||||
std::tie(b.pad_id, b.pad_state, b.model, b.connection_type, b.pad_mac_address);
|
std::tie(b.pad_id, b.pad_state, b.model, b.connection_type, b.pad_mac_address);
|
||||||
}
|
}
|
||||||
|
|
||||||
static sf::Socket::Status ReceiveWithTimeout(sf::UdpSocket& socket, void* data, std::size_t size,
|
|
||||||
std::size_t& received, sf::IpAddress& remoteAddress,
|
|
||||||
unsigned short& remotePort, sf::Time timeout)
|
|
||||||
{
|
|
||||||
sf::SocketSelector selector;
|
|
||||||
selector.add(socket);
|
|
||||||
if (selector.wait(timeout))
|
|
||||||
return socket.receive(data, size, received, remoteAddress, remotePort);
|
|
||||||
else
|
|
||||||
return sf::Socket::NotReady;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void HotplugThreadFunc()
|
static void HotplugThreadFunc()
|
||||||
{
|
{
|
||||||
Common::SetCurrentThreadName("DualShockUDPClient Hotplug Thread");
|
Common::SetCurrentThreadName("DualShockUDPClient Hotplug Thread");
|
||||||
@ -242,32 +230,50 @@ static void HotplugThreadFunc()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sf::SocketSelector selector;
|
||||||
for (auto& server : s_servers)
|
for (auto& server : s_servers)
|
||||||
{
|
{
|
||||||
// Receive controller port info
|
selector.add(server.m_socket);
|
||||||
using namespace std::chrono;
|
}
|
||||||
using namespace std::chrono_literals;
|
|
||||||
|
using namespace std::chrono;
|
||||||
|
using namespace std::chrono_literals;
|
||||||
|
const auto timeout = s_next_listports - SteadyClock::now();
|
||||||
|
|
||||||
|
// Selector's wait treats a timeout of zero as infinite timeout, which we don't want
|
||||||
|
const auto timeout_ms = std::max(duration_cast<milliseconds>(timeout), 1ms);
|
||||||
|
if (!selector.wait(sf::milliseconds(timeout_ms.count())))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto& server : s_servers)
|
||||||
|
{
|
||||||
|
if (!selector.isReady(server.m_socket))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
Proto::Message<Proto::MessageType::FromServer> msg;
|
Proto::Message<Proto::MessageType::FromServer> msg;
|
||||||
const auto timeout = s_next_listports - SteadyClock::now();
|
|
||||||
// ReceiveWithTimeout treats a timeout of zero as infinite timeout, which we don't want
|
|
||||||
const auto timeout_ms = std::max(duration_cast<milliseconds>(timeout), 1ms);
|
|
||||||
std::size_t received_bytes;
|
std::size_t received_bytes;
|
||||||
sf::IpAddress sender;
|
sf::IpAddress sender;
|
||||||
u16 port;
|
u16 port;
|
||||||
if (ReceiveWithTimeout(server.m_socket, &msg, sizeof(msg), received_bytes, sender, port,
|
if (server.m_socket.receive(&msg, sizeof(msg), received_bytes, sender, port) !=
|
||||||
sf::milliseconds(timeout_ms.count())) == sf::Socket::Status::Done)
|
sf::Socket::Status::Done)
|
||||||
{
|
{
|
||||||
if (auto port_info = msg.CheckAndCastTo<Proto::MessageType::PortInfo>())
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (auto port_info = msg.CheckAndCastTo<Proto::MessageType::PortInfo>())
|
||||||
|
{
|
||||||
|
const bool port_changed =
|
||||||
|
!IsSameController(*port_info, server.m_port_info[port_info->pad_id]);
|
||||||
{
|
{
|
||||||
const bool port_changed =
|
std::lock_guard lock{server.m_port_info_mutex};
|
||||||
!IsSameController(*port_info, server.m_port_info[port_info->pad_id]);
|
server.m_port_info[port_info->pad_id] = *port_info;
|
||||||
{
|
|
||||||
std::lock_guard lock{server.m_port_info_mutex};
|
|
||||||
server.m_port_info[port_info->pad_id] = *port_info;
|
|
||||||
}
|
|
||||||
if (port_changed)
|
|
||||||
PopulateDevices();
|
|
||||||
}
|
}
|
||||||
|
if (port_changed)
|
||||||
|
PopulateDevices();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user