From eafc048121af9e27476986b214f9b09efb5b0ec9 Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Sun, 14 Apr 2024 15:17:11 +0200 Subject: [PATCH] Set expedite TOS for client stream as well --- client/wivrn_client.cpp | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/client/wivrn_client.cpp b/client/wivrn_client.cpp index 6e8ebc9a..1296bf1a 100644 --- a/client/wivrn_client.cpp +++ b/client/wivrn_client.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -31,6 +32,11 @@ #include #include +#ifndef IPTOS_DSCP_EF +// constant is not defined in Android ip.h +#define IPTOS_DSCP_EF 0xb8 +#endif + using namespace std::chrono_literals; void wivrn_session::handshake() @@ -66,6 +72,25 @@ void wivrn_session::handshake() throw std::runtime_error("No handshake received"); } +namespace +{ +template +void init_stream(T & stream) +{ + stream.set_receive_buffer_size(1024 * 1024 * 5); + try + { + stream.set_tos(IPTOS_DSCP_EF); + } + catch (std::exception & e) + { + spdlog::warn("Failed to set IP ToS to Expedited Forwarding: {}", e.what()); + } + // If this packet is lost, a tracking packet will do the job to establish the connection + stream.send(from_headset::handshake{}); +} +} // namespace + wivrn_session::wivrn_session(in6_addr address, int port) : control(address, port), stream(), address(address) { @@ -73,9 +98,7 @@ wivrn_session::wivrn_session(in6_addr address, int port) : spdlog::info("Connection to {}:{}", inet_ntop(AF_INET6, &address, buffer, sizeof(buffer)), port); handshake(); stream.connect(address, port); - stream.set_receive_buffer_size(1024 * 1024 * 5); - // If this packet is lost, a tracking packet will do the job to establish the connection - send_stream(from_headset::handshake{}); + init_stream(stream); } wivrn_session::wivrn_session(in_addr address, int port) : @@ -85,7 +108,5 @@ wivrn_session::wivrn_session(in_addr address, int port) : spdlog::info("Connection to {}:{}", inet_ntop(AF_INET, &address, buffer, sizeof(buffer)), port); handshake(); stream.connect(address, port); - stream.set_receive_buffer_size(1024 * 1024 * 5); - // If this packet is lost, a tracking packet will do the job to establish the connection - send_stream(from_headset::handshake{}); + init_stream(stream); }