Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
MsQuicApi.cs
Go to the documentation of this file.
4
6
7internal sealed class MsQuicApi
8{
9 private static readonly Version MinWindowsVersion;
10
12
13 internal static MsQuicApi Api { get; }
14
15 internal static bool IsQuicSupported { get; }
16
17 internal MsQuicNativeMethods.RegistrationOpenDelegate RegistrationOpenDelegate { get; }
18
19 internal MsQuicNativeMethods.RegistrationCloseDelegate RegistrationCloseDelegate { get; }
20
21 internal MsQuicNativeMethods.ConfigurationOpenDelegate ConfigurationOpenDelegate { get; }
22
23 internal MsQuicNativeMethods.ConfigurationCloseDelegate ConfigurationCloseDelegate { get; }
24
25 internal MsQuicNativeMethods.ConfigurationLoadCredentialDelegate ConfigurationLoadCredentialDelegate { get; }
26
27 internal MsQuicNativeMethods.ListenerOpenDelegate ListenerOpenDelegate { get; }
28
29 internal MsQuicNativeMethods.ListenerCloseDelegate ListenerCloseDelegate { get; }
30
31 internal MsQuicNativeMethods.ListenerStartDelegate ListenerStartDelegate { get; }
32
33 internal MsQuicNativeMethods.ListenerStopDelegate ListenerStopDelegate { get; }
34
35 internal MsQuicNativeMethods.ConnectionOpenDelegate ConnectionOpenDelegate { get; }
36
37 internal MsQuicNativeMethods.ConnectionCloseDelegate ConnectionCloseDelegate { get; }
38
39 internal MsQuicNativeMethods.ConnectionShutdownDelegate ConnectionShutdownDelegate { get; }
40
41 internal MsQuicNativeMethods.ConnectionStartDelegate ConnectionStartDelegate { get; }
42
43 internal MsQuicNativeMethods.ConnectionSetConfigurationDelegate ConnectionSetConfigurationDelegate { get; }
44
45 internal MsQuicNativeMethods.StreamOpenDelegate StreamOpenDelegate { get; }
46
47 internal MsQuicNativeMethods.StreamCloseDelegate StreamCloseDelegate { get; }
48
49 internal MsQuicNativeMethods.StreamStartDelegate StreamStartDelegate { get; }
50
51 internal MsQuicNativeMethods.StreamShutdownDelegate StreamShutdownDelegate { get; }
52
53 internal MsQuicNativeMethods.StreamSendDelegate StreamSendDelegate { get; }
54
55 internal MsQuicNativeMethods.StreamReceiveCompleteDelegate StreamReceiveCompleteDelegate { get; }
56
57 internal MsQuicNativeMethods.StreamReceiveSetEnabledDelegate StreamReceiveSetEnabledDelegate { get; }
58
59 internal MsQuicNativeMethods.SetCallbackHandlerDelegate SetCallbackHandlerDelegate { get; }
60
61 internal MsQuicNativeMethods.SetParamDelegate SetParamDelegate { get; }
62
63 internal MsQuicNativeMethods.GetParamDelegate GetParamDelegate { get; }
64
65 [DynamicDependency(DynamicallyAccessedMemberTypes.PublicConstructors, typeof(SafeMsQuicRegistrationHandle))]
66 [DynamicDependency(DynamicallyAccessedMemberTypes.PublicConstructors, typeof(SafeMsQuicConfigurationHandle))]
67 [DynamicDependency(DynamicallyAccessedMemberTypes.PublicConstructors, typeof(SafeMsQuicListenerHandle))]
68 [DynamicDependency(DynamicallyAccessedMemberTypes.PublicConstructors, typeof(SafeMsQuicConnectionHandle))]
69 [DynamicDependency(DynamicallyAccessedMemberTypes.PublicConstructors, typeof(SafeMsQuicStreamHandle))]
70 private unsafe MsQuicApi(MsQuicNativeMethods.NativeApi* vtable)
71 {
97 {
98 AppName = ".NET",
99 ExecutionProfile = QUIC_EXECUTION_PROFILE.QUIC_EXECUTION_PROFILE_LOW_LATENCY
100 };
101 SafeMsQuicRegistrationHandle registrationContext;
102 uint status = RegistrationOpenDelegate(ref config, out registrationContext);
103 QuicExceptionHelpers.ThrowIfFailed(status, "RegistrationOpen failed.");
104 Registration = registrationContext;
105 }
106
107 unsafe static MsQuicApi()
108 {
109 MinWindowsVersion = new Version(10, 0, 20145, 1000);
110 Api = null;
112 {
113 if (System.Net.NetEventSource.Log.IsEnabled())
114 {
115 System.Net.NetEventSource.Info(null, $"Current Windows version ({Environment.OSVersion}) is not supported by QUIC. Minimal supported version is {MinWindowsVersion}", ".cctor");
116 }
117 }
118 else
119 {
120 if (!NativeLibrary.TryLoad("msquic.dll", typeof(MsQuicApi).Assembly, DllImportSearchPath.AssemblyDirectory, out var handle))
121 {
122 return;
123 }
124 try
125 {
126 if (NativeLibrary.TryGetExport(handle, "MsQuicOpenVersion", out var address))
127 {
128 Unsafe.SkipInit(out MsQuicNativeMethods.NativeApi* vtable);
129 uint status = ((delegate* unmanaged[Cdecl]<uint, out MsQuicNativeMethods.NativeApi*, uint>)(void*)address)(1u, out vtable);
131 {
132 IsQuicSupported = true;
133 Api = new MsQuicApi(vtable);
134 }
135 }
136 }
137 finally
138 {
139 if (!IsQuicSupported)
140 {
142 }
143 }
144 }
145 }
146
151}
static readonly System.Net.NetEventSource Log
static void Info(object thisOrContextObject, FormattableString formattableString=null, [CallerMemberName] string memberName=null)
MsQuicNativeMethods.StreamShutdownDelegate StreamShutdownDelegate
Definition MsQuicApi.cs:51
MsQuicNativeMethods.ConnectionOpenDelegate ConnectionOpenDelegate
Definition MsQuicApi.cs:35
MsQuicNativeMethods.StreamSendDelegate StreamSendDelegate
Definition MsQuicApi.cs:53
MsQuicNativeMethods.StreamCloseDelegate StreamCloseDelegate
Definition MsQuicApi.cs:47
MsQuicNativeMethods.ConnectionShutdownDelegate ConnectionShutdownDelegate
Definition MsQuicApi.cs:39
MsQuicNativeMethods.ConnectionSetConfigurationDelegate ConnectionSetConfigurationDelegate
Definition MsQuicApi.cs:43
MsQuicNativeMethods.StreamReceiveCompleteDelegate StreamReceiveCompleteDelegate
Definition MsQuicApi.cs:55
MsQuicNativeMethods.ListenerOpenDelegate ListenerOpenDelegate
Definition MsQuicApi.cs:27
MsQuicNativeMethods.RegistrationOpenDelegate RegistrationOpenDelegate
Definition MsQuicApi.cs:17
MsQuicNativeMethods.ConfigurationCloseDelegate ConfigurationCloseDelegate
Definition MsQuicApi.cs:23
MsQuicNativeMethods.ConnectionCloseDelegate ConnectionCloseDelegate
Definition MsQuicApi.cs:37
MsQuicNativeMethods.StreamReceiveSetEnabledDelegate StreamReceiveSetEnabledDelegate
Definition MsQuicApi.cs:57
MsQuicNativeMethods.ConfigurationLoadCredentialDelegate ConfigurationLoadCredentialDelegate
Definition MsQuicApi.cs:25
MsQuicNativeMethods.SetCallbackHandlerDelegate SetCallbackHandlerDelegate
Definition MsQuicApi.cs:59
MsQuicNativeMethods.ListenerStartDelegate ListenerStartDelegate
Definition MsQuicApi.cs:31
MsQuicNativeMethods.ConfigurationOpenDelegate ConfigurationOpenDelegate
Definition MsQuicApi.cs:21
MsQuicNativeMethods.ConnectionStartDelegate ConnectionStartDelegate
Definition MsQuicApi.cs:41
MsQuicNativeMethods.GetParamDelegate GetParamDelegate
Definition MsQuicApi.cs:63
unsafe MsQuicApi(MsQuicNativeMethods.NativeApi *vtable)
Definition MsQuicApi.cs:70
MsQuicNativeMethods.SetParamDelegate SetParamDelegate
Definition MsQuicApi.cs:61
MsQuicNativeMethods.StreamStartDelegate StreamStartDelegate
Definition MsQuicApi.cs:49
MsQuicNativeMethods.ListenerStopDelegate ListenerStopDelegate
Definition MsQuicApi.cs:33
MsQuicNativeMethods.StreamOpenDelegate StreamOpenDelegate
Definition MsQuicApi.cs:45
MsQuicNativeMethods.RegistrationCloseDelegate RegistrationCloseDelegate
Definition MsQuicApi.cs:19
MsQuicNativeMethods.ListenerCloseDelegate ListenerCloseDelegate
Definition MsQuicApi.cs:29
delegate uint ConnectionOpenDelegate(SafeMsQuicRegistrationHandle registration, ConnectionCallbackDelegate handler, IntPtr context, out SafeMsQuicConnectionHandle connection)
delegate uint ConnectionStartDelegate(SafeMsQuicConnectionHandle connection, SafeMsQuicConfigurationHandle configuration, QUIC_ADDRESS_FAMILY family, [MarshalAs(UnmanagedType.LPUTF8Str)] string serverName, ushort serverPort)
delegate void ConnectionShutdownDelegate(SafeMsQuicConnectionHandle connection, QUIC_CONNECTION_SHUTDOWN_FLAGS flags, long errorCode)
delegate uint RegistrationOpenDelegate(ref RegistrationConfig config, out SafeMsQuicRegistrationHandle registrationContext)
unsafe delegate uint SetParamDelegate(SafeHandle handle, QUIC_PARAM_LEVEL level, uint param, uint bufferLength, byte *buffer)
delegate uint ListenerOpenDelegate(SafeMsQuicRegistrationHandle registration, ListenerCallbackDelegate handler, IntPtr context, out SafeMsQuicListenerHandle listener)
delegate uint ConnectionSetConfigurationDelegate(SafeMsQuicConnectionHandle connection, SafeMsQuicConfigurationHandle configuration)
delegate uint StreamReceiveSetEnabledDelegate(SafeMsQuicStreamHandle stream, [MarshalAs(UnmanagedType.U1)] bool enabled)
delegate uint StreamStartDelegate(SafeMsQuicStreamHandle stream, QUIC_STREAM_START_FLAGS flags)
delegate void ListenerStopDelegate(SafeMsQuicListenerHandle listener)
delegate uint StreamOpenDelegate(SafeMsQuicConnectionHandle connection, QUIC_STREAM_OPEN_FLAGS flags, StreamCallbackDelegate handler, IntPtr context, out SafeMsQuicStreamHandle stream)
delegate void SetCallbackHandlerDelegate(SafeHandle handle, Delegate del, IntPtr context)
delegate uint StreamReceiveCompleteDelegate(SafeMsQuicStreamHandle stream, ulong bufferLength)
unsafe delegate uint ListenerStartDelegate(SafeMsQuicListenerHandle listener, QuicBuffer *alpnBuffers, uint alpnBufferCount, ref SOCKADDR_INET localAddress)
delegate uint StreamShutdownDelegate(SafeMsQuicStreamHandle stream, QUIC_STREAM_SHUTDOWN_FLAGS flags, long errorCode)
unsafe delegate uint StreamSendDelegate(SafeMsQuicStreamHandle stream, QuicBuffer *buffers, uint bufferCount, QUIC_SEND_FLAGS flags, IntPtr clientSendContext)
delegate uint ConfigurationLoadCredentialDelegate(SafeMsQuicConfigurationHandle configuration, ref CredentialConfig credConfig)
unsafe delegate uint ConfigurationOpenDelegate(SafeMsQuicRegistrationHandle registrationContext, QuicBuffer *alpnBuffers, uint alpnBufferCount, ref QuicSettings settings, uint settingsSize, IntPtr context, out SafeMsQuicConfigurationHandle configuration)
delegate void RegistrationCloseDelegate(IntPtr registrationContext)
unsafe delegate uint GetParamDelegate(SafeHandle handle, QUIC_PARAM_LEVEL level, uint param, ref uint bufferLength, byte *buffer)
static void ThrowIfFailed(uint status, string message=null, Exception innerException=null)
static bool IsWindowsVersionAtLeast(int major, int minor=0, int build=0, int revision=0)
static Delegate GetDelegateForFunctionPointer(IntPtr ptr, Type t)
Definition Marshal.cs:1414
static bool TryLoad(string libraryPath, out IntPtr handle)
static bool TryGetExport(IntPtr handle, string name, out IntPtr address)