mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-01-09 23:59:27 +01:00
Socket: Make use of std::erase_if
This commit is contained in:
parent
96eac73d11
commit
e69ac2d43e
@ -1047,66 +1047,61 @@ void WiiSockMan::UpdatePollCommands()
|
|||||||
auto& system = Core::System::GetInstance();
|
auto& system = Core::System::GetInstance();
|
||||||
auto& memory = system.GetMemory();
|
auto& memory = system.GetMemory();
|
||||||
|
|
||||||
pending_polls.erase(
|
std::erase_if(pending_polls, [&system, &memory, this](PollCommand& pcmd) {
|
||||||
std::remove_if(
|
const auto request = Request(system, pcmd.request_addr);
|
||||||
pending_polls.begin(), pending_polls.end(),
|
auto& pfds = pcmd.wii_fds;
|
||||||
[&system, &memory, this](PollCommand& pcmd) {
|
int ret = 0;
|
||||||
const auto request = Request(system, pcmd.request_addr);
|
|
||||||
auto& pfds = pcmd.wii_fds;
|
|
||||||
int ret = 0;
|
|
||||||
|
|
||||||
// Happens only on savestate load
|
// Happens only on savestate load
|
||||||
if (pfds[0].revents & error_event)
|
if (pfds[0].revents & error_event)
|
||||||
{
|
{
|
||||||
ret = static_cast<int>(pfds.size());
|
ret = static_cast<int>(pfds.size());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Make the behavior of poll consistent across platforms by not passing:
|
// Make the behavior of poll consistent across platforms by not passing:
|
||||||
// - Set with invalid fds, revents is set to 0 (Linux) or POLLNVAL (Windows)
|
// - Set with invalid fds, revents is set to 0 (Linux) or POLLNVAL (Windows)
|
||||||
// - Set without a valid socket, raises an error on Windows
|
// - Set without a valid socket, raises an error on Windows
|
||||||
std::vector<int> original_order(pfds.size());
|
std::vector<int> original_order(pfds.size());
|
||||||
std::iota(original_order.begin(), original_order.end(), 0);
|
std::iota(original_order.begin(), original_order.end(), 0);
|
||||||
// Select indices with valid fds
|
// Select indices with valid fds
|
||||||
auto mid = std::partition(original_order.begin(), original_order.end(), [&](auto i) {
|
auto mid = std::partition(original_order.begin(), original_order.end(), [&](auto i) {
|
||||||
return GetHostSocket(memory.Read_U32(pcmd.buffer_out + 0xc * i)) >= 0;
|
return GetHostSocket(memory.Read_U32(pcmd.buffer_out + 0xc * i)) >= 0;
|
||||||
});
|
});
|
||||||
const auto n_valid = std::distance(original_order.begin(), mid);
|
const auto n_valid = std::distance(original_order.begin(), mid);
|
||||||
|
|
||||||
// Move all the valid pollfds to the front of the vector
|
// Move all the valid pollfds to the front of the vector
|
||||||
for (auto i = 0; i < n_valid; ++i)
|
for (auto i = 0; i < n_valid; ++i)
|
||||||
std::swap(pfds[i], pfds[original_order[i]]);
|
std::swap(pfds[i], pfds[original_order[i]]);
|
||||||
|
|
||||||
if (n_valid > 0)
|
if (n_valid > 0)
|
||||||
ret = poll(pfds.data(), n_valid, 0);
|
ret = poll(pfds.data(), n_valid, 0);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
ret = GetNetErrorCode(ret, "UpdatePollCommands", false);
|
ret = GetNetErrorCode(ret, "UpdatePollCommands", false);
|
||||||
|
|
||||||
// Move everything back to where they were
|
// Move everything back to where they were
|
||||||
for (auto i = 0; i < n_valid; ++i)
|
for (auto i = 0; i < n_valid; ++i)
|
||||||
std::swap(pfds[i], pfds[original_order[i]]);
|
std::swap(pfds[i], pfds[original_order[i]]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ret == 0 && pcmd.timeout)
|
if (ret == 0 && pcmd.timeout)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Translate native to Wii events,
|
// Translate native to Wii events,
|
||||||
for (u32 i = 0; i < pfds.size(); ++i)
|
for (u32 i = 0; i < pfds.size(); ++i)
|
||||||
{
|
{
|
||||||
const int revents = ConvertEvents(pfds[i].revents, ConvertDirection::NativeToWii);
|
const int revents = ConvertEvents(pfds[i].revents, ConvertDirection::NativeToWii);
|
||||||
|
|
||||||
// No need to change fd or events as they are input only.
|
// No need to change fd or events as they are input only.
|
||||||
// memory.Write_U32(ufds[i].fd, request.buffer_out + 0xc*i); //fd
|
// memory.Write_U32(ufds[i].fd, request.buffer_out + 0xc*i); //fd
|
||||||
// memory.Write_U32(events, request.buffer_out + 0xc*i + 4); //events
|
// memory.Write_U32(events, request.buffer_out + 0xc*i + 4); //events
|
||||||
memory.Write_U32(revents, pcmd.buffer_out + 0xc * i + 8); // revents
|
memory.Write_U32(revents, pcmd.buffer_out + 0xc * i + 8); // revents
|
||||||
DEBUG_LOG_FMT(IOS_NET,
|
DEBUG_LOG_FMT(IOS_NET, "IOCTL_SO_POLL socket {} wevents {:08X} events {:08X} revents {:08X}",
|
||||||
"IOCTL_SO_POLL socket {} wevents {:08X} events {:08X} revents {:08X}",
|
i, revents, pfds[i].events, pfds[i].revents);
|
||||||
i, revents, pfds[i].events, pfds[i].revents);
|
}
|
||||||
}
|
GetIOS()->EnqueueIPCReply(request, ret);
|
||||||
GetIOS()->EnqueueIPCReply(request, ret);
|
return true;
|
||||||
return true;
|
});
|
||||||
}),
|
|
||||||
pending_polls.end());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WiiSockMan::ToNativeAddrIn(const u8* addr, sockaddr_in* to)
|
void WiiSockMan::ToNativeAddrIn(const u8* addr, sockaddr_in* to)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user