Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Merge pull request #6146 from HannesMann/qos-support
Netplay: Add Quality of Service (QoS) support
- Loading branch information
Showing
10 changed files
with
160 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| // Copyright 2017 Dolphin Emulator Project | ||
| // Licensed under GPLv2+ | ||
| // Refer to the license.txt file included. | ||
|
|
||
| #include "Common/QoSSession.h" | ||
| #include "Core/ConfigManager.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) | ||
| { | ||
| #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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| // Copyright 2017 Dolphin Emulator Project | ||
| // Licensed under GPLv2+ | ||
| // Refer to the license.txt file included. | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <enet/enet.h> | ||
| #include <utility> | ||
|
|
||
| namespace Common | ||
| { | ||
| class QoSSession | ||
| { | ||
| public: | ||
| // 1 0 1 1 1 0 0 0 | ||
| // DSCP ECN | ||
| static constexpr int ef_tos = 0b10111000; | ||
|
|
||
| QoSSession() = default; | ||
| QoSSession(ENetPeer* peer, int tos_val = ef_tos); | ||
|
|
||
| ~QoSSession(); | ||
|
|
||
| QoSSession& operator=(const QoSSession&) = delete; | ||
| QoSSession(const QoSSession&) = delete; | ||
|
|
||
| QoSSession& operator=(QoSSession&& session); | ||
| QoSSession(QoSSession&& session) { *this = std::move(session); } | ||
| bool Successful() const { return m_success; } | ||
| private: | ||
| #if defined(_WIN32) | ||
| void* m_qos_handle = nullptr; | ||
| unsigned long m_qos_flow_id = 0; | ||
|
|
||
| ENetPeer* m_peer = nullptr; | ||
| #endif | ||
|
|
||
| bool m_success = false; | ||
| }; | ||
| } // namespace Common |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters