From 1f79f4ed1248cd32089709a7af8c5fc4ccd5c3fa Mon Sep 17 00:00:00 2001 From: Mathias Tillman Date: Wed, 9 Mar 2022 00:30:10 +0100 Subject: [PATCH 1/4] Fix rumble events causing hang because the received input events were not read properly. --- sunshine/platform/linux/input.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/sunshine/platform/linux/input.cpp b/sunshine/platform/linux/input.cpp index fbdc8133..3c92ba81 100644 --- a/sunshine/platform/linux/input.cpp +++ b/sunshine/platform/linux/input.cpp @@ -716,6 +716,15 @@ inline void rumbleIterate(std::vector &effects, std::vector return; } + // Copy over the received events + for (auto x = 0; x < polls_tmp.size(); ++x) { + for (auto y = 0; y < polls.size(); ++y) { + if (polls_tmp[x].fd == polls[y].el.fd) { + polls[y].el.revents = polls_tmp[x].revents; + } + } + } + for(int x = 0; x < polls.size(); ++x) { auto poll = std::begin(polls) + x; auto effect_it = std::begin(effects) + x; From 9a2689692a32904f3208a8180bd7a8526ef0bca3 Mon Sep 17 00:00:00 2001 From: Mathias Tillman Date: Wed, 9 Mar 2022 16:40:39 +0100 Subject: [PATCH 2/4] Fix lint warning about code style. --- sunshine/platform/linux/input.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/sunshine/platform/linux/input.cpp b/sunshine/platform/linux/input.cpp index 3c92ba81..1f9840fb 100644 --- a/sunshine/platform/linux/input.cpp +++ b/sunshine/platform/linux/input.cpp @@ -717,9 +717,10 @@ inline void rumbleIterate(std::vector &effects, std::vector } // Copy over the received events - for (auto x = 0; x < polls_tmp.size(); ++x) { - for (auto y = 0; y < polls.size(); ++y) { - if (polls_tmp[x].fd == polls[y].el.fd) { + for(auto x = 0; x < polls_tmp.size(); ++x) { + auto pfd = polls_tmp[x].fd; + for(auto y = 0; y < polls.size(); ++y) { + if (pfd == polls[y].el.fd) { polls[y].el.revents = polls_tmp[x].revents; } } From 80ebc9982edd3fa284385cf76b221a37cdd99c26 Mon Sep 17 00:00:00 2001 From: Mathias Tillman Date: Wed, 9 Mar 2022 17:27:42 +0100 Subject: [PATCH 3/4] Fix another lint warning. --- sunshine/platform/linux/input.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sunshine/platform/linux/input.cpp b/sunshine/platform/linux/input.cpp index 1f9840fb..c0222927 100644 --- a/sunshine/platform/linux/input.cpp +++ b/sunshine/platform/linux/input.cpp @@ -720,7 +720,7 @@ inline void rumbleIterate(std::vector &effects, std::vector for(auto x = 0; x < polls_tmp.size(); ++x) { auto pfd = polls_tmp[x].fd; for(auto y = 0; y < polls.size(); ++y) { - if (pfd == polls[y].el.fd) { + if(pfd == polls[y].el.fd) { polls[y].el.revents = polls_tmp[x].revents; } } From e61bbe87b4bd4c4554bf84843c830aaed9b0f182 Mon Sep 17 00:00:00 2001 From: Mathias Tillman Date: Wed, 9 Mar 2022 22:23:38 +0100 Subject: [PATCH 4/4] Read revents from the temporary pollfds instead of copying them over to the old vector. Decrement index for polls when erasing to make sure none of the events are skipped. --- sunshine/platform/linux/input.cpp | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/sunshine/platform/linux/input.cpp b/sunshine/platform/linux/input.cpp index c0222927..be923936 100644 --- a/sunshine/platform/linux/input.cpp +++ b/sunshine/platform/linux/input.cpp @@ -696,13 +696,13 @@ public: }; inline void rumbleIterate(std::vector &effects, std::vector &polls, std::chrono::milliseconds to) { - std::vector polls_tmp; - polls_tmp.reserve(polls.size()); + std::vector polls_recv; + polls_recv.reserve(polls.size()); for(auto &poll : polls) { - polls_tmp.emplace_back(poll.el); + polls_recv.emplace_back(poll.el); } - auto res = poll(polls_tmp.data(), polls.size(), to.count()); + auto res = poll(polls_recv.data(), polls_recv.size(), to.count()); // If timed out if(!res) { @@ -716,16 +716,6 @@ inline void rumbleIterate(std::vector &effects, std::vector return; } - // Copy over the received events - for(auto x = 0; x < polls_tmp.size(); ++x) { - auto pfd = polls_tmp[x].fd; - for(auto y = 0; y < polls.size(); ++y) { - if(pfd == polls[y].el.fd) { - polls[y].el.revents = polls_tmp[x].revents; - } - } - } - for(int x = 0; x < polls.size(); ++x) { auto poll = std::begin(polls) + x; auto effect_it = std::begin(effects) + x; @@ -735,16 +725,17 @@ inline void rumbleIterate(std::vector &effects, std::vector // TUPLE_2D_REF(dev, q, *dev_q_it); // on error - if((*poll)->revents & (POLLHUP | POLLRDHUP | POLLERR)) { + if(polls_recv[x].revents & (POLLHUP | POLLRDHUP | POLLERR)) { BOOST_LOG(warning) << "Gamepad ["sv << x << "] file discriptor closed unexpectedly"sv; polls.erase(poll); effects.erase(effect_it); + --x; continue; } - if(!((*poll)->revents & POLLIN)) { + if(!(polls_recv[x].revents & POLLIN)) { continue; } @@ -761,6 +752,7 @@ inline void rumbleIterate(std::vector &effects, std::vector polls.erase(poll); effects.erase(effect_it); + --x; continue; }