Skip to content

Commit

Permalink
[QUIC] Latest msquic interop (dotnet#69876)
Browse files Browse the repository at this point in the history
* Latest msquic interop

* Update src/libraries/System.Net.Quic/src/System/Net/Quic/Implementations/MsQuic/Interop/msquic_extensions.cs

* No polyfill for runtime repo

* Feedback
  • Loading branch information
ManickaP authored Jun 2, 2022
1 parent f873951 commit 655bc1d
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

#if NETSTANDARD
using OperatingSystem = Microsoft.Quic.Polyfill.OperatingSystem;
#else
using OperatingSystem = System.OperatingSystem;
#endif

namespace Microsoft.Quic
{
internal unsafe partial struct QUIC_BUFFER
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#pragma warning disable IDE0073
//
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
//
#pragma warning restore IDE0073

using System;

namespace Microsoft.Quic
{
internal static unsafe class MsQuicExtensions
{
public static void SetConnectionCallback(this ref QUIC_API_TABLE Table, QUIC_HANDLE* Handle, delegate* unmanaged[Cdecl]<QUIC_HANDLE*, void*, QUIC_CONNECTION_EVENT*, int> Callback, void* Context)
{
Table.SetCallbackHandler(Handle, Callback, Context);
}

public static void SetStreamCallback(this ref QUIC_API_TABLE Table, QUIC_HANDLE* Handle, delegate* unmanaged[Cdecl]<QUIC_HANDLE*, void*, QUIC_STREAM_EVENT*, int> Callback, void* Context)
{
Table.SetCallbackHandler(Handle, Callback, Context);
}

public static void SetListenerCallback(this ref QUIC_API_TABLE Table, QUIC_HANDLE* Handle, delegate* unmanaged[Cdecl]<QUIC_HANDLE*, void*, QUIC_LISTENER_EVENT*, int> Callback, void* Context)
{
Table.SetCallbackHandler(Handle, Callback, Context);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@

#pragma warning disable CS0649

// Polyfill for MemoryMarshal on .NET Standard
#if NETSTANDARD && !NETSTANDARD2_1_OR_GREATER
using MemoryMarshal = Microsoft.Quic.Polyfill.MemoryMarshal;
#else
using MemoryMarshal = System.Runtime.InteropServices.MemoryMarshal;
#endif

using System.Runtime.InteropServices;

namespace Microsoft.Quic
Expand Down Expand Up @@ -60,6 +67,9 @@ internal enum QUIC_CREDENTIAL_FLAGS
SET_ALLOWED_CIPHER_SUITES = 0x00002000,
USE_PORTABLE_CERTIFICATES = 0x00004000,
USE_SUPPLIED_CREDENTIALS = 0x00008000,
USE_SYSTEM_MAPPER = 0x00010000,
CACHE_ONLY_URL_RETRIEVAL = 0x00020000,
REVOCATION_CHECK_CACHE_ONLY = 0x00040000,
}

[System.Flags]
Expand Down Expand Up @@ -1679,6 +1689,17 @@ internal byte ServerTrafficSecret0
}
}

internal unsafe partial struct QUIC_SCHANNEL_CREDENTIAL_ATTRIBUTE_W
{
[NativeTypeName("unsigned long")]
internal uint Attribute;

[NativeTypeName("unsigned long")]
internal uint BufferLength;

internal void* Buffer;
}

internal unsafe partial struct QUIC_SCHANNEL_CONTEXT_ATTRIBUTE_W
{
[NativeTypeName("unsigned long")]
Expand All @@ -1687,6 +1708,17 @@ internal unsafe partial struct QUIC_SCHANNEL_CONTEXT_ATTRIBUTE_W
internal void* Buffer;
}

internal unsafe partial struct QUIC_SCHANNEL_CONTEXT_ATTRIBUTE_EX_W
{
[NativeTypeName("unsigned long")]
internal uint Attribute;

[NativeTypeName("unsigned long")]
internal uint BufferLength;

internal void* Buffer;
}

internal enum QUIC_LISTENER_EVENT_TYPE
{
NEW_CONNECTION = 0,
Expand Down Expand Up @@ -2569,6 +2601,9 @@ internal static unsafe partial class MsQuic
[NativeTypeName("#define QUIC_PARAM_CONFIGURATION_VERSION_SETTINGS 0x03000002")]
internal const uint QUIC_PARAM_CONFIGURATION_VERSION_SETTINGS = 0x03000002;

[NativeTypeName("#define QUIC_PARAM_CONFIGURATION_SCHANNEL_CREDENTIAL_ATTRIBUTE_W 0x03000003")]
internal const uint QUIC_PARAM_CONFIGURATION_SCHANNEL_CREDENTIAL_ATTRIBUTE_W = 0x03000003;

[NativeTypeName("#define QUIC_PARAM_LISTENER_LOCAL_ADDRESS 0x04000000")]
internal const uint QUIC_PARAM_LISTENER_LOCAL_ADDRESS = 0x04000000;

Expand Down Expand Up @@ -2659,6 +2694,12 @@ internal static unsafe partial class MsQuic
[NativeTypeName("#define QUIC_PARAM_TLS_SCHANNEL_CONTEXT_ATTRIBUTE_W 0x07000000")]
internal const uint QUIC_PARAM_TLS_SCHANNEL_CONTEXT_ATTRIBUTE_W = 0x07000000;

[NativeTypeName("#define QUIC_PARAM_TLS_SCHANNEL_CONTEXT_ATTRIBUTE_EX_W 0x07000001")]
internal const uint QUIC_PARAM_TLS_SCHANNEL_CONTEXT_ATTRIBUTE_EX_W = 0x07000001;

[NativeTypeName("#define QUIC_PARAM_TLS_SCHANNEL_SECURITY_CONTEXT_TOKEN 0x07000002")]
internal const uint QUIC_PARAM_TLS_SCHANNEL_SECURITY_CONTEXT_TOKEN = 0x07000002;

[NativeTypeName("#define QUIC_PARAM_STREAM_ID 0x08000000")]
internal const uint QUIC_PARAM_STREAM_ID = 0x08000000;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,7 @@ public unsafe MsQuicConnection(IPEndPoint localEndPoint, IPEndPoint remoteEndPoi
try
{
Debug.Assert(!Monitor.IsEntered(_state), "!Monitor.IsEntered(_state)");
delegate* unmanaged[Cdecl]<QUIC_HANDLE*, void*, QUIC_CONNECTION_EVENT*, int> nativeCallback = &NativeCallback;
MsQuicApi.Api.ApiTable->SetCallbackHandler(
_state.Handle.QuicHandle,
nativeCallback,
(void*)GCHandle.ToIntPtr(_state.StateGCHandle));
MsQuicApi.Api.ApiTable->SetConnectionCallback(_state.Handle.QuicHandle, &NativeCallback, (void*)GCHandle.ToIntPtr(_state.StateGCHandle));
}
catch
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,7 @@ internal unsafe MsQuicStream(MsQuicConnection.State connectionState, SafeMsQuicS
try
{
Debug.Assert(!Monitor.IsEntered(_state), "!Monitor.IsEntered(_state)");
delegate* unmanaged[Cdecl]<QUIC_HANDLE*, void*, QUIC_STREAM_EVENT*, int> nativeCallback = &NativeCallback;
MsQuicApi.Api.ApiTable->SetCallbackHandler(
_state.Handle.QuicHandle,
nativeCallback,
(void*)GCHandle.ToIntPtr(_state.StateGCHandle));
MsQuicApi.Api.ApiTable->SetStreamCallback(_state.Handle.QuicHandle, &NativeCallback, (void*)GCHandle.ToIntPtr(_state.StateGCHandle));
}
catch
{
Expand Down

0 comments on commit 655bc1d

Please sign in to comment.