summaryrefslogtreecommitdiff
path: root/Source
diff options
context:
space:
mode:
authorLioncash <mai.iam2048@gmail.com>2023-12-12 13:29:33 -0500
committerLioncash <mai.iam2048@gmail.com>2023-12-12 13:29:33 -0500
commite69ac2d43e2644591753c3f313dfded14d6d1718 (patch)
tree64d2e3caf4af87f23b31fdc16be398149fef57fe /Source
parent96eac73d11cc96c4a6b0c46e59aa73899f2db6ea (diff)
Socket: Make use of std::erase_if
Diffstat (limited to 'Source')
-rw-r--r--Source/Core/Core/IOS/Network/Socket.cpp111
1 files changed, 53 insertions, 58 deletions
diff --git a/Source/Core/Core/IOS/Network/Socket.cpp b/Source/Core/Core/IOS/Network/Socket.cpp
index caa461a8cd..9f198e18ea 100644
--- a/Source/Core/Core/IOS/Network/Socket.cpp
+++ b/Source/Core/Core/IOS/Network/Socket.cpp
@@ -1047,66 +1047,61 @@ void WiiSockMan::UpdatePollCommands()
auto& system = Core::System::GetInstance();
auto& memory = system.GetMemory();
- pending_polls.erase(
- std::remove_if(
- pending_polls.begin(), pending_polls.end(),
- [&system, &memory, this](PollCommand& pcmd) {
- const auto request = Request(system, pcmd.request_addr);
- auto& pfds = pcmd.wii_fds;
- int ret = 0;
-
- // Happens only on savestate load
- if (pfds[0].revents & error_event)
- {
- ret = static_cast<int>(pfds.size());
- }
- else
- {
- // 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 without a valid socket, raises an error on Windows
- std::vector<int> original_order(pfds.size());
- std::iota(original_order.begin(), original_order.end(), 0);
- // Select indices with valid fds
- auto mid = std::partition(original_order.begin(), original_order.end(), [&](auto i) {
- return GetHostSocket(memory.Read_U32(pcmd.buffer_out + 0xc * i)) >= 0;
- });
- const auto n_valid = std::distance(original_order.begin(), mid);
-
- // Move all the valid pollfds to the front of the vector
- for (auto i = 0; i < n_valid; ++i)
- std::swap(pfds[i], pfds[original_order[i]]);
-
- if (n_valid > 0)
- ret = poll(pfds.data(), n_valid, 0);
- if (ret < 0)
- ret = GetNetErrorCode(ret, "UpdatePollCommands", false);
-
- // Move everything back to where they were
- for (auto i = 0; i < n_valid; ++i)
- std::swap(pfds[i], pfds[original_order[i]]);
- }
+ std::erase_if(pending_polls, [&system, &memory, this](PollCommand& pcmd) {
+ const auto request = Request(system, pcmd.request_addr);
+ auto& pfds = pcmd.wii_fds;
+ int ret = 0;
- if (ret == 0 && pcmd.timeout)
- return false;
+ // Happens only on savestate load
+ if (pfds[0].revents & error_event)
+ {
+ ret = static_cast<int>(pfds.size());
+ }
+ else
+ {
+ // 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 without a valid socket, raises an error on Windows
+ std::vector<int> original_order(pfds.size());
+ std::iota(original_order.begin(), original_order.end(), 0);
+ // Select indices with valid fds
+ auto mid = std::partition(original_order.begin(), original_order.end(), [&](auto i) {
+ return GetHostSocket(memory.Read_U32(pcmd.buffer_out + 0xc * i)) >= 0;
+ });
+ const auto n_valid = std::distance(original_order.begin(), mid);
+
+ // Move all the valid pollfds to the front of the vector
+ for (auto i = 0; i < n_valid; ++i)
+ std::swap(pfds[i], pfds[original_order[i]]);
+
+ if (n_valid > 0)
+ ret = poll(pfds.data(), n_valid, 0);
+ if (ret < 0)
+ ret = GetNetErrorCode(ret, "UpdatePollCommands", false);
+
+ // Move everything back to where they were
+ for (auto i = 0; i < n_valid; ++i)
+ std::swap(pfds[i], pfds[original_order[i]]);
+ }
- // Translate native to Wii events,
- for (u32 i = 0; i < pfds.size(); ++i)
- {
- const int revents = ConvertEvents(pfds[i].revents, ConvertDirection::NativeToWii);
-
- // 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(events, request.buffer_out + 0xc*i + 4); //events
- memory.Write_U32(revents, pcmd.buffer_out + 0xc * i + 8); // revents
- DEBUG_LOG_FMT(IOS_NET,
- "IOCTL_SO_POLL socket {} wevents {:08X} events {:08X} revents {:08X}",
- i, revents, pfds[i].events, pfds[i].revents);
- }
- GetIOS()->EnqueueIPCReply(request, ret);
- return true;
- }),
- pending_polls.end());
+ if (ret == 0 && pcmd.timeout)
+ return false;
+
+ // Translate native to Wii events,
+ for (u32 i = 0; i < pfds.size(); ++i)
+ {
+ const int revents = ConvertEvents(pfds[i].revents, ConvertDirection::NativeToWii);
+
+ // 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(events, request.buffer_out + 0xc*i + 4); //events
+ memory.Write_U32(revents, pcmd.buffer_out + 0xc * i + 8); // revents
+ DEBUG_LOG_FMT(IOS_NET, "IOCTL_SO_POLL socket {} wevents {:08X} events {:08X} revents {:08X}",
+ i, revents, pfds[i].events, pfds[i].revents);
+ }
+ GetIOS()->EnqueueIPCReply(request, ret);
+ return true;
+ });
}
void WiiSockMan::ToNativeAddrIn(const u8* addr, sockaddr_in* to)