Skip to content

Commit

Permalink
DomainName as command line parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
ami-GS committed Nov 18, 2024
1 parent 91abe69 commit 5bb2241
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/dotnet-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,4 @@ jobs:
dotnet-version: 6.0.x
- name: Run Lang Interop
shell: pwsh
run: scripts/DotNetTest.ps1 -Config Debug -Arch ${{ matrix.vec.arch }} -Tls ${{ matrix.vec.tls }}
run: scripts/DotNetTest.ps1 -Config Debug -Arch ${{ matrix.vec.arch }} -Tls ${{ matrix.vec.tls }} -DomainName "google.com"
7 changes: 5 additions & 2 deletions scripts/DotNetTest.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ param (
[string]$Tls = "",

[Parameter(Mandatory = $false)]
[string]$ExtraArtifactDir = ""
[string]$ExtraArtifactDir = "",

[Parameter(Mandatory = $true)]
[string]$DomainName = ""
)

Set-StrictMode -Version 'Latest'
Expand All @@ -43,4 +46,4 @@ if ($IsWindows) {
$RootDir = Split-Path $PSScriptRoot -Parent

dotnet build (Join-Path $RootDir src cs)
dotnet run --project (Join-Path $RootDir src cs tool) -- (Join-Path $RootArtifactDir $LibName)
dotnet run --project (Join-Path $RootDir src cs tool) -- $DomainName (Join-Path $RootArtifactDir $LibName)
25 changes: 22 additions & 3 deletions src/cs/tool/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,32 @@ static unsafe void Main(string[] args)
{
// This code lets us pass in an argument of where to search for the library at.
// Very helpful for testing
if (args.Length > 0)
if (args.Length == 0)
{
Console.WriteLine("Usage: MsQuicTool <DomainName> [PathToMsQuic]");
return;
}

string DomainName = args[0];

if (string.IsNullOrWhiteSpace(DomainName))
{
Console.WriteLine("DomainName cannot be empty.");
return;
}

if (DomainName.Length > 253)
{
Console.WriteLine("DomainName is too long.");
return;
}

if (args.Length > 1)
{
NativeLibrary.SetDllImportResolver(typeof(MsQuic).Assembly, (libraryName, assembly, searchPath) =>
{
if (libraryName != "msquic") return IntPtr.Zero;
if (NativeLibrary.TryLoad(args[0], out var ptr))
if (NativeLibrary.TryLoad(args[1], out var ptr))
{
return ptr;
}
Expand All @@ -32,7 +52,6 @@ static unsafe void Main(string[] args)
}

var ApiTable = MsQuic.Open();
const string DomainName = "google.com";
QUIC_HANDLE* registration = null;
QUIC_HANDLE* configuration = null;
QUIC_HANDLE* connection = null;
Expand Down

0 comments on commit 5bb2241

Please sign in to comment.