mirror of
https://github.com/LizardByte/Sunshine.git
synced 2026-03-29 11:45:54 +00:00
Add refcounting to Mac and Linux QoS state to ensure it works properly with multiple clients
This means we can't control DSCP tagging per-client, but it shouldn't pose a big problem as routers that blackhole DSCP tagged traffic are pretty rare.
This commit is contained in:
@ -584,16 +584,25 @@ namespace platf {
|
||||
return true;
|
||||
}
|
||||
|
||||
// We can't track QoS state separately for each destination on this OS,
|
||||
// so we keep a ref count to only disable QoS options when all clients
|
||||
// are disconnected.
|
||||
static std::atomic<int> qos_ref_count = 0;
|
||||
|
||||
class qos_t: public deinit_t {
|
||||
public:
|
||||
qos_t(int sockfd, std::vector<std::tuple<int, int, int>> options):
|
||||
sockfd(sockfd), options(options) {}
|
||||
sockfd(sockfd), options(options) {
|
||||
qos_ref_count++;
|
||||
}
|
||||
|
||||
virtual ~qos_t() {
|
||||
for (const auto &tuple : options) {
|
||||
auto reset_val = std::get<2>(tuple);
|
||||
if (setsockopt(sockfd, std::get<0>(tuple), std::get<1>(tuple), &reset_val, sizeof(reset_val)) < 0) {
|
||||
BOOST_LOG(warning) << "Failed to reset option: "sv << errno;
|
||||
if (--qos_ref_count == 0) {
|
||||
for (const auto &tuple : options) {
|
||||
auto reset_val = std::get<2>(tuple);
|
||||
if (setsockopt(sockfd, std::get<0>(tuple), std::get<1>(tuple), &reset_val, sizeof(reset_val)) < 0) {
|
||||
BOOST_LOG(warning) << "Failed to reset option: "sv << errno;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user