dolphin/Source/Core/Common/QoSSession.cpp
Martino Fontana a14c88ba67 Remove unused imports
Yellow squiggly lines begone!
Done automatically on .cpp files through `run-clang-tidy`, with manual corrections to the mistakes.
If an import is directly used, but is technically unnecessary since it's recursively imported by something else, it is *not* removed.
The tool doesn't touch .h files, so I did some of them by hand while fixing errors due to old recursive imports.
Not everything is removed, but the cleanup should be substantial enough.
Because this done on Linux, code that isn't used on it is mostly untouched.
(Hopefully no open PR is depending on these imports...)
2026-01-25 16:12:15 +01:00

95 lines
2.5 KiB
C++

// Copyright 2017 Dolphin Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include "Common/QoSSession.h"
#if defined(_WIN32)
#include <Qos2.h>
#pragma comment(lib, "qwave")
#endif
namespace Common
{
#if defined(_WIN32)
QoSSession::QoSSession(ENetPeer* peer, int tos_val) : m_peer(peer)
{
QOS_VERSION ver = {1, 0};
if (!QOSCreateHandle(&ver, &m_qos_handle))
return;
sockaddr_in sin = {};
sin.sin_family = AF_INET;
sin.sin_port = ENET_HOST_TO_NET_16(peer->host->address.port);
sin.sin_addr.s_addr = peer->host->address.host;
if (QOSAddSocketToFlow(m_qos_handle, peer->host->socket, reinterpret_cast<PSOCKADDR>(&sin),
QOSTrafficTypeControl, QOS_NON_ADAPTIVE_FLOW, &m_qos_flow_id))
{
// We shift the complete ToS value by 3 to get rid of the 3 bit ECN field
DWORD dscp = static_cast<DWORD>(tos_val >> 3);
// Sets DSCP to the same as Linux
// This will fail if we're not admin, but we ignore it
QOSSetFlow(m_qos_handle, m_qos_flow_id, QOSSetOutgoingDSCPValue, sizeof(DWORD), &dscp, 0,
nullptr);
m_success = true;
}
}
QoSSession::~QoSSession()
{
if (m_qos_handle == nullptr)
return;
if (m_qos_flow_id != 0)
QOSRemoveSocketFromFlow(m_qos_handle, m_peer->host->socket, m_qos_flow_id, 0);
QOSCloseHandle(m_qos_handle);
}
#else
QoSSession::QoSSession(ENetPeer* peer, int tos_val)
{
// Apple systems don't support SO_PRIORITY on BSD sockets, but they do support a flag for
// marking sockets as a specific type of traffic. `NET_SERVICE_TYPE_RV` should roughly
// correspond to "low delay tolerant, low-medium loss tolerant, elastic flow, variable
// packet interval, rate and size".
#if defined(__APPLE__)
constexpr int srv_type = NET_SERVICE_TYPE_RV;
setsockopt(peer->host->socket, SOL_SOCKET, SO_NET_SERVICE_TYPE, &srv_type, sizeof(srv_type));
#endif
#if defined(__linux__)
constexpr int priority = 7;
setsockopt(peer->host->socket, SOL_SOCKET, SO_PRIORITY, &priority, sizeof(priority));
#endif
m_success = setsockopt(peer->host->socket, IPPROTO_IP, IP_TOS, &tos_val, sizeof(tos_val)) == 0;
}
QoSSession::~QoSSession() = default;
#endif
QoSSession& QoSSession::operator=(QoSSession&& session)
{
if (this != &session)
{
#if defined(_WIN32)
m_qos_handle = session.m_qos_handle;
m_qos_flow_id = session.m_qos_flow_id;
m_peer = session.m_peer;
session.m_qos_handle = nullptr;
session.m_qos_flow_id = 0;
session.m_peer = nullptr;
#endif
m_success = session.m_success;
session.m_success = false;
}
return *this;
}
} // namespace Common