Skip to content

Commit

Permalink
MsQuicGlobalSettings C++ Helper (#3774)
Browse files Browse the repository at this point in the history
  • Loading branch information
nibanks committed Jul 25, 2023
1 parent 9685eb5 commit 27b62ca
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 6 deletions.
29 changes: 29 additions & 0 deletions src/inc/msquic.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,35 @@ class MsQuicVersionSettings : public QUIC_VERSION_SETTINGS {
static_assert(sizeof(QUIC_VERSION_SETTINGS) == sizeof(MsQuicVersionSettings), "Cpp wrappers must not change size");
#endif

class MsQuicGlobalSettings : public QUIC_GLOBAL_SETTINGS {
public:
MsQuicGlobalSettings() noexcept { IsSetFlags = 0; }
MsQuicGlobalSettings& SetRetryMemoryLimit(uint16_t Value) { RetryMemoryLimit = Value; IsSet.RetryMemoryLimit = TRUE; return *this; }
MsQuicGlobalSettings& SetLoadBalancingMode(uint16_t Value) { LoadBalancingMode = Value; IsSet.LoadBalancingMode = TRUE; return *this; }
MsQuicGlobalSettings& SetFixedServerID(uint32_t Value) { FixedServerID = Value; IsSet.FixedServerID = TRUE; return *this; }

QUIC_STATUS Set() const noexcept {
const QUIC_GLOBAL_SETTINGS* Settings = this;
return
MsQuic->SetParam(
nullptr,
QUIC_PARAM_GLOBAL_GLOBAL_SETTINGS,
sizeof(*Settings),
Settings);
}

QUIC_STATUS Get() noexcept {
QUIC_GLOBAL_SETTINGS* Settings = this;
uint32_t Size = sizeof(*Settings);
return
MsQuic->GetParam(
nullptr,
QUIC_PARAM_GLOBAL_GLOBAL_SETTINGS,
&Size,
Settings);
}
};

class MsQuicSettings : public QUIC_SETTINGS {
public:
MsQuicSettings() noexcept { IsSetFlags = 0; }
Expand Down
10 changes: 4 additions & 6 deletions src/perf/lib/PerfServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,12 @@ PerfServer::Init(

uint16_t ServerId = 0;
if (TryGetValue(argc, argv, "serverid", &ServerId)) {
QUIC_GLOBAL_SETTINGS GlobalSettings = {0};
GlobalSettings.FixedServerID = ServerId;
GlobalSettings.IsSet.FixedServerID = true;
GlobalSettings.LoadBalancingMode = QUIC_LOAD_BALANCING_SERVER_ID_FIXED;
GlobalSettings.IsSet.LoadBalancingMode = true;
MsQuicGlobalSettings GlobalSettings;
GlobalSettings.SetFixedServerID(ServerId);
GlobalSettings.SetLoadBalancingMode(QUIC_LOAD_BALANCING_SERVER_ID_FIXED);

QUIC_STATUS Status;
if (QUIC_FAILED(Status = MsQuic->SetParam(NULL, QUIC_PARAM_GLOBAL_GLOBAL_SETTINGS, sizeof(GlobalSettings), &GlobalSettings))) {
if (QUIC_FAILED(Status = GlobalSettings.Set())) {
WriteOutput("Failed to set global settings %d\n", Status);
return Status;
}
Expand Down

0 comments on commit 27b62ca

Please sign in to comment.