private readonly IntPtr _registrationContext;
- private unsafe MsQuicApi()
+ private unsafe MsQuicApi(MsQuicNativeMethods.NativeApi* registration)
{
- MsQuicNativeMethods.NativeApi* registration;
-
- try
- {
- uint status = Interop.MsQuic.MsQuicOpen(out registration);
- if (!MsQuicStatusHelper.SuccessfulStatusCode(status))
- {
- throw new NotSupportedException(SR.net_quic_notsupported);
- }
- }
- catch (DllNotFoundException)
- {
- throw new NotSupportedException(SR.net_quic_notsupported);
- }
-
MsQuicNativeMethods.NativeApi nativeRegistration = *registration;
RegistrationOpenDelegate =
internal static bool IsQuicSupported { get; }
- static MsQuicApi()
+ static unsafe MsQuicApi()
{
// MsQuicOpen will succeed even if the platform will not support it. It will then fail with unspecified
// platform-specific errors in subsequent callbacks. For now, check for the minimum build we've tested it on.
// TODO: try to initialize TLS 1.3 in SslStream.
- try
- {
- Api = new MsQuicApi();
- IsQuicSupported = true;
- }
- catch (NotSupportedException)
+ // TODO: Consider updating all of these delegates to instead use function pointers.
+
+ if (NativeLibrary.TryLoad(Interop.Libraries.MsQuic, out IntPtr msQuicHandle))
{
- IsQuicSupported = false;
+ try
+ {
+ if (NativeLibrary.TryGetExport(msQuicHandle, "MsQuicOpen", out IntPtr msQuicOpenAddress))
+ {
+ MsQuicNativeMethods.MsQuicOpenDelegate msQuicOpen = Marshal.GetDelegateForFunctionPointer<MsQuicNativeMethods.MsQuicOpenDelegate>(msQuicOpenAddress);
+ uint status = msQuicOpen(out MsQuicNativeMethods.NativeApi* registration);
+ if (MsQuicStatusHelper.SuccessfulStatusCode(status))
+ {
+ IsQuicSupported = true;
+ Api = new MsQuicApi(registration);
+ }
+ }
+ }
+ finally
+ {
+ if (!IsQuicSupported)
+ {
+ NativeLibrary.Free(msQuicHandle);
+ }
+ }
}
}
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-using System;
-using System.Net.Quic.Implementations.MsQuic.Internal;
-using System.Runtime.InteropServices;
-
-internal static partial class Interop
-{
- internal static class MsQuic
- {
- [DllImport(Libraries.MsQuic, CallingConvention = CallingConvention.Cdecl)]
- internal static unsafe extern uint MsQuicOpen(out MsQuicNativeMethods.NativeApi* registration);
- }
-}