private unsafe MsQuicApi() { MsQuicStatusException.ThrowIfFailed(Interop.MsQuic.MsQuicOpen(version: 1, out MsQuicNativeMethods.NativeApi * registration)); MsQuicNativeMethods.NativeApi nativeRegistration = *registration; RegistrationOpenDelegate = Marshal.GetDelegateForFunctionPointer <MsQuicNativeMethods.RegistrationOpenDelegate>( nativeRegistration.RegistrationOpen); RegistrationCloseDelegate = Marshal.GetDelegateForFunctionPointer <MsQuicNativeMethods.RegistrationCloseDelegate>( nativeRegistration.RegistrationClose); SecConfigCreateDelegate = Marshal.GetDelegateForFunctionPointer <MsQuicNativeMethods.SecConfigCreateDelegate>( nativeRegistration.SecConfigCreate); SecConfigDeleteDelegate = Marshal.GetDelegateForFunctionPointer <MsQuicNativeMethods.SecConfigDeleteDelegate>( nativeRegistration.SecConfigDelete); SessionOpenDelegate = Marshal.GetDelegateForFunctionPointer <MsQuicNativeMethods.SessionOpenDelegate>( nativeRegistration.SessionOpen); SessionCloseDelegate = Marshal.GetDelegateForFunctionPointer <MsQuicNativeMethods.SessionCloseDelegate>( nativeRegistration.SessionClose); SessionShutdownDelegate = Marshal.GetDelegateForFunctionPointer <MsQuicNativeMethods.SessionShutdownDelegate>( nativeRegistration.SessionShutdown); ListenerOpenDelegate = Marshal.GetDelegateForFunctionPointer <MsQuicNativeMethods.ListenerOpenDelegate>( nativeRegistration.ListenerOpen); ListenerCloseDelegate = Marshal.GetDelegateForFunctionPointer <MsQuicNativeMethods.ListenerCloseDelegate>( nativeRegistration.ListenerClose); ListenerStartDelegate = Marshal.GetDelegateForFunctionPointer <MsQuicNativeMethods.ListenerStartDelegate>( nativeRegistration.ListenerStart); ListenerStopDelegate = Marshal.GetDelegateForFunctionPointer <MsQuicNativeMethods.ListenerStopDelegate>( nativeRegistration.ListenerStop); ConnectionOpenDelegate = Marshal.GetDelegateForFunctionPointer <MsQuicNativeMethods.ConnectionOpenDelegate>( nativeRegistration.ConnectionOpen); ConnectionCloseDelegate = Marshal.GetDelegateForFunctionPointer <MsQuicNativeMethods.ConnectionCloseDelegate>( nativeRegistration.ConnectionClose); ConnectionShutdownDelegate = Marshal.GetDelegateForFunctionPointer <MsQuicNativeMethods.ConnectionShutdownDelegate>( nativeRegistration.ConnectionShutdown); ConnectionStartDelegate = Marshal.GetDelegateForFunctionPointer <MsQuicNativeMethods.ConnectionStartDelegate>( nativeRegistration.ConnectionStart); StreamOpenDelegate = Marshal.GetDelegateForFunctionPointer <MsQuicNativeMethods.StreamOpenDelegate>( nativeRegistration.StreamOpen); StreamCloseDelegate = Marshal.GetDelegateForFunctionPointer <MsQuicNativeMethods.StreamCloseDelegate>( nativeRegistration.StreamClose); StreamStartDelegate = Marshal.GetDelegateForFunctionPointer <MsQuicNativeMethods.StreamStartDelegate>( nativeRegistration.StreamStart); StreamShutdownDelegate = Marshal.GetDelegateForFunctionPointer <MsQuicNativeMethods.StreamShutdownDelegate>( nativeRegistration.StreamShutdown); StreamSendDelegate = Marshal.GetDelegateForFunctionPointer <MsQuicNativeMethods.StreamSendDelegate>( nativeRegistration.StreamSend); StreamReceiveCompleteDelegate = Marshal.GetDelegateForFunctionPointer <MsQuicNativeMethods.StreamReceiveCompleteDelegate>( nativeRegistration.StreamReceiveComplete); StreamReceiveSetEnabledDelegate = Marshal.GetDelegateForFunctionPointer <MsQuicNativeMethods.StreamReceiveSetEnabledDelegate>( nativeRegistration.StreamReceiveSetEnabled); SetContextDelegate = Marshal.GetDelegateForFunctionPointer <MsQuicNativeMethods.SetContextDelegate>( nativeRegistration.SetContext); GetContextDelegate = Marshal.GetDelegateForFunctionPointer <MsQuicNativeMethods.GetContextDelegate>( nativeRegistration.GetContext); SetCallbackHandlerDelegate = Marshal.GetDelegateForFunctionPointer <MsQuicNativeMethods.SetCallbackHandlerDelegate>( nativeRegistration.SetCallbackHandler); SetParamDelegate = Marshal.GetDelegateForFunctionPointer <MsQuicNativeMethods.SetParamDelegate>( nativeRegistration.SetParam); GetParamDelegate = Marshal.GetDelegateForFunctionPointer <MsQuicNativeMethods.GetParamDelegate>( nativeRegistration.GetParam); RegistrationOpenDelegate(Encoding.UTF8.GetBytes("SystemNetQuic"), out IntPtr ctx); _registrationContext = ctx; }
private unsafe MsQuicApi() { MsQuicNativeMethods.NativeApi *registration; try { uint status = Interop.MsQuic.MsQuicOpen(version: 1, 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 = Marshal.GetDelegateForFunctionPointer <MsQuicNativeMethods.RegistrationOpenDelegate>( nativeRegistration.RegistrationOpen); RegistrationCloseDelegate = Marshal.GetDelegateForFunctionPointer <MsQuicNativeMethods.RegistrationCloseDelegate>( nativeRegistration.RegistrationClose); SecConfigCreateDelegate = Marshal.GetDelegateForFunctionPointer <MsQuicNativeMethods.SecConfigCreateDelegate>( nativeRegistration.SecConfigCreate); SecConfigDeleteDelegate = Marshal.GetDelegateForFunctionPointer <MsQuicNativeMethods.SecConfigDeleteDelegate>( nativeRegistration.SecConfigDelete); SessionOpenDelegate = Marshal.GetDelegateForFunctionPointer <MsQuicNativeMethods.SessionOpenDelegate>( nativeRegistration.SessionOpen); SessionCloseDelegate = Marshal.GetDelegateForFunctionPointer <MsQuicNativeMethods.SessionCloseDelegate>( nativeRegistration.SessionClose); SessionShutdownDelegate = Marshal.GetDelegateForFunctionPointer <MsQuicNativeMethods.SessionShutdownDelegate>( nativeRegistration.SessionShutdown); ListenerOpenDelegate = Marshal.GetDelegateForFunctionPointer <MsQuicNativeMethods.ListenerOpenDelegate>( nativeRegistration.ListenerOpen); ListenerCloseDelegate = Marshal.GetDelegateForFunctionPointer <MsQuicNativeMethods.ListenerCloseDelegate>( nativeRegistration.ListenerClose); ListenerStartDelegate = Marshal.GetDelegateForFunctionPointer <MsQuicNativeMethods.ListenerStartDelegate>( nativeRegistration.ListenerStart); ListenerStopDelegate = Marshal.GetDelegateForFunctionPointer <MsQuicNativeMethods.ListenerStopDelegate>( nativeRegistration.ListenerStop); ConnectionOpenDelegate = Marshal.GetDelegateForFunctionPointer <MsQuicNativeMethods.ConnectionOpenDelegate>( nativeRegistration.ConnectionOpen); ConnectionCloseDelegate = Marshal.GetDelegateForFunctionPointer <MsQuicNativeMethods.ConnectionCloseDelegate>( nativeRegistration.ConnectionClose); ConnectionShutdownDelegate = Marshal.GetDelegateForFunctionPointer <MsQuicNativeMethods.ConnectionShutdownDelegate>( nativeRegistration.ConnectionShutdown); ConnectionStartDelegate = Marshal.GetDelegateForFunctionPointer <MsQuicNativeMethods.ConnectionStartDelegate>( nativeRegistration.ConnectionStart); StreamOpenDelegate = Marshal.GetDelegateForFunctionPointer <MsQuicNativeMethods.StreamOpenDelegate>( nativeRegistration.StreamOpen); StreamCloseDelegate = Marshal.GetDelegateForFunctionPointer <MsQuicNativeMethods.StreamCloseDelegate>( nativeRegistration.StreamClose); StreamStartDelegate = Marshal.GetDelegateForFunctionPointer <MsQuicNativeMethods.StreamStartDelegate>( nativeRegistration.StreamStart); StreamShutdownDelegate = Marshal.GetDelegateForFunctionPointer <MsQuicNativeMethods.StreamShutdownDelegate>( nativeRegistration.StreamShutdown); StreamSendDelegate = Marshal.GetDelegateForFunctionPointer <MsQuicNativeMethods.StreamSendDelegate>( nativeRegistration.StreamSend); StreamReceiveCompleteDelegate = Marshal.GetDelegateForFunctionPointer <MsQuicNativeMethods.StreamReceiveCompleteDelegate>( nativeRegistration.StreamReceiveComplete); StreamReceiveSetEnabledDelegate = Marshal.GetDelegateForFunctionPointer <MsQuicNativeMethods.StreamReceiveSetEnabledDelegate>( nativeRegistration.StreamReceiveSetEnabled); SetContextDelegate = Marshal.GetDelegateForFunctionPointer <MsQuicNativeMethods.SetContextDelegate>( nativeRegistration.SetContext); GetContextDelegate = Marshal.GetDelegateForFunctionPointer <MsQuicNativeMethods.GetContextDelegate>( nativeRegistration.GetContext); SetCallbackHandlerDelegate = Marshal.GetDelegateForFunctionPointer <MsQuicNativeMethods.SetCallbackHandlerDelegate>( nativeRegistration.SetCallbackHandler); SetParamDelegate = Marshal.GetDelegateForFunctionPointer <MsQuicNativeMethods.SetParamDelegate>( nativeRegistration.SetParam); GetParamDelegate = Marshal.GetDelegateForFunctionPointer <MsQuicNativeMethods.GetParamDelegate>( nativeRegistration.GetParam); RegistrationOpenDelegate(Encoding.UTF8.GetBytes("SystemNetQuic"), out IntPtr ctx); _registrationContext = ctx; }
private unsafe MsQuicApi() { 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 = Marshal.GetDelegateForFunctionPointer <MsQuicNativeMethods.RegistrationOpenDelegate>( nativeRegistration.RegistrationOpen); RegistrationCloseDelegate = Marshal.GetDelegateForFunctionPointer <MsQuicNativeMethods.RegistrationCloseDelegate>( nativeRegistration.RegistrationClose); SecConfigCreateDelegate = Marshal.GetDelegateForFunctionPointer <MsQuicNativeMethods.SecConfigCreateDelegate>( nativeRegistration.SecConfigCreate); SecConfigDeleteDelegate = Marshal.GetDelegateForFunctionPointer <MsQuicNativeMethods.SecConfigDeleteDelegate>( nativeRegistration.SecConfigDelete); SessionOpenDelegate = Marshal.GetDelegateForFunctionPointer <MsQuicNativeMethods.SessionOpenDelegate>( nativeRegistration.SessionOpen); SessionCloseDelegate = Marshal.GetDelegateForFunctionPointer <MsQuicNativeMethods.SessionCloseDelegate>( nativeRegistration.SessionClose); SessionShutdownDelegate = Marshal.GetDelegateForFunctionPointer <MsQuicNativeMethods.SessionShutdownDelegate>( nativeRegistration.SessionShutdown); ListenerOpenDelegate = Marshal.GetDelegateForFunctionPointer <MsQuicNativeMethods.ListenerOpenDelegate>( nativeRegistration.ListenerOpen); ListenerCloseDelegate = Marshal.GetDelegateForFunctionPointer <MsQuicNativeMethods.ListenerCloseDelegate>( nativeRegistration.ListenerClose); ListenerStartDelegate = Marshal.GetDelegateForFunctionPointer <MsQuicNativeMethods.ListenerStartDelegate>( nativeRegistration.ListenerStart); ListenerStopDelegate = Marshal.GetDelegateForFunctionPointer <MsQuicNativeMethods.ListenerStopDelegate>( nativeRegistration.ListenerStop); ConnectionOpenDelegate = Marshal.GetDelegateForFunctionPointer <MsQuicNativeMethods.ConnectionOpenDelegate>( nativeRegistration.ConnectionOpen); ConnectionCloseDelegate = Marshal.GetDelegateForFunctionPointer <MsQuicNativeMethods.ConnectionCloseDelegate>( nativeRegistration.ConnectionClose); ConnectionShutdownDelegate = Marshal.GetDelegateForFunctionPointer <MsQuicNativeMethods.ConnectionShutdownDelegate>( nativeRegistration.ConnectionShutdown); ConnectionStartDelegate = Marshal.GetDelegateForFunctionPointer <MsQuicNativeMethods.ConnectionStartDelegate>( nativeRegistration.ConnectionStart); StreamOpenDelegate = Marshal.GetDelegateForFunctionPointer <MsQuicNativeMethods.StreamOpenDelegate>( nativeRegistration.StreamOpen); StreamCloseDelegate = Marshal.GetDelegateForFunctionPointer <MsQuicNativeMethods.StreamCloseDelegate>( nativeRegistration.StreamClose); StreamStartDelegate = Marshal.GetDelegateForFunctionPointer <MsQuicNativeMethods.StreamStartDelegate>( nativeRegistration.StreamStart); StreamShutdownDelegate = Marshal.GetDelegateForFunctionPointer <MsQuicNativeMethods.StreamShutdownDelegate>( nativeRegistration.StreamShutdown); StreamSendDelegate = Marshal.GetDelegateForFunctionPointer <MsQuicNativeMethods.StreamSendDelegate>( nativeRegistration.StreamSend); StreamReceiveCompleteDelegate = Marshal.GetDelegateForFunctionPointer <MsQuicNativeMethods.StreamReceiveCompleteDelegate>( nativeRegistration.StreamReceiveComplete); StreamReceiveSetEnabledDelegate = Marshal.GetDelegateForFunctionPointer <MsQuicNativeMethods.StreamReceiveSetEnabledDelegate>( nativeRegistration.StreamReceiveSetEnabled); SetContextDelegate = Marshal.GetDelegateForFunctionPointer <MsQuicNativeMethods.SetContextDelegate>( nativeRegistration.SetContext); GetContextDelegate = Marshal.GetDelegateForFunctionPointer <MsQuicNativeMethods.GetContextDelegate>( nativeRegistration.GetContext); SetCallbackHandlerDelegate = Marshal.GetDelegateForFunctionPointer <MsQuicNativeMethods.SetCallbackHandlerDelegate>( nativeRegistration.SetCallbackHandler); SetParamDelegate = Marshal.GetDelegateForFunctionPointer <MsQuicNativeMethods.SetParamDelegate>( nativeRegistration.SetParam); GetParamDelegate = Marshal.GetDelegateForFunctionPointer <MsQuicNativeMethods.GetParamDelegate>( nativeRegistration.GetParam); var registrationConfig = new MsQuicNativeMethods.RegistrationConfig { AppName = "SystemNetQuic", ExecutionProfile = QUIC_EXECUTION_PROFILE.QUIC_EXECUTION_PROFILE_LOW_LATENCY }; RegistrationOpenDelegate(ref registrationConfig, out IntPtr ctx); _registrationContext = ctx; }
private unsafe MsQuicApi(MsQuicNativeMethods.NativeApi *registration) { MsQuicNativeMethods.NativeApi nativeRegistration = *registration; RegistrationOpenDelegate = Marshal.GetDelegateForFunctionPointer <MsQuicNativeMethods.RegistrationOpenDelegate>( nativeRegistration.RegistrationOpen); RegistrationCloseDelegate = Marshal.GetDelegateForFunctionPointer <MsQuicNativeMethods.RegistrationCloseDelegate>( nativeRegistration.RegistrationClose); SecConfigCreateDelegate = Marshal.GetDelegateForFunctionPointer <MsQuicNativeMethods.SecConfigCreateDelegate>( nativeRegistration.SecConfigCreate); SecConfigDeleteDelegate = Marshal.GetDelegateForFunctionPointer <MsQuicNativeMethods.SecConfigDeleteDelegate>( nativeRegistration.SecConfigDelete); SessionOpenDelegate = Marshal.GetDelegateForFunctionPointer <MsQuicNativeMethods.SessionOpenDelegate>( nativeRegistration.SessionOpen); SessionCloseDelegate = Marshal.GetDelegateForFunctionPointer <MsQuicNativeMethods.SessionCloseDelegate>( nativeRegistration.SessionClose); SessionShutdownDelegate = Marshal.GetDelegateForFunctionPointer <MsQuicNativeMethods.SessionShutdownDelegate>( nativeRegistration.SessionShutdown); ListenerOpenDelegate = Marshal.GetDelegateForFunctionPointer <MsQuicNativeMethods.ListenerOpenDelegate>( nativeRegistration.ListenerOpen); ListenerCloseDelegate = Marshal.GetDelegateForFunctionPointer <MsQuicNativeMethods.ListenerCloseDelegate>( nativeRegistration.ListenerClose); ListenerStartDelegate = Marshal.GetDelegateForFunctionPointer <MsQuicNativeMethods.ListenerStartDelegate>( nativeRegistration.ListenerStart); ListenerStopDelegate = Marshal.GetDelegateForFunctionPointer <MsQuicNativeMethods.ListenerStopDelegate>( nativeRegistration.ListenerStop); ConnectionOpenDelegate = Marshal.GetDelegateForFunctionPointer <MsQuicNativeMethods.ConnectionOpenDelegate>( nativeRegistration.ConnectionOpen); ConnectionCloseDelegate = Marshal.GetDelegateForFunctionPointer <MsQuicNativeMethods.ConnectionCloseDelegate>( nativeRegistration.ConnectionClose); ConnectionShutdownDelegate = Marshal.GetDelegateForFunctionPointer <MsQuicNativeMethods.ConnectionShutdownDelegate>( nativeRegistration.ConnectionShutdown); ConnectionStartDelegate = Marshal.GetDelegateForFunctionPointer <MsQuicNativeMethods.ConnectionStartDelegate>( nativeRegistration.ConnectionStart); StreamOpenDelegate = Marshal.GetDelegateForFunctionPointer <MsQuicNativeMethods.StreamOpenDelegate>( nativeRegistration.StreamOpen); StreamCloseDelegate = Marshal.GetDelegateForFunctionPointer <MsQuicNativeMethods.StreamCloseDelegate>( nativeRegistration.StreamClose); StreamStartDelegate = Marshal.GetDelegateForFunctionPointer <MsQuicNativeMethods.StreamStartDelegate>( nativeRegistration.StreamStart); StreamShutdownDelegate = Marshal.GetDelegateForFunctionPointer <MsQuicNativeMethods.StreamShutdownDelegate>( nativeRegistration.StreamShutdown); StreamSendDelegate = Marshal.GetDelegateForFunctionPointer <MsQuicNativeMethods.StreamSendDelegate>( nativeRegistration.StreamSend); StreamReceiveCompleteDelegate = Marshal.GetDelegateForFunctionPointer <MsQuicNativeMethods.StreamReceiveCompleteDelegate>( nativeRegistration.StreamReceiveComplete); StreamReceiveSetEnabledDelegate = Marshal.GetDelegateForFunctionPointer <MsQuicNativeMethods.StreamReceiveSetEnabledDelegate>( nativeRegistration.StreamReceiveSetEnabled); SetContextDelegate = Marshal.GetDelegateForFunctionPointer <MsQuicNativeMethods.SetContextDelegate>( nativeRegistration.SetContext); GetContextDelegate = Marshal.GetDelegateForFunctionPointer <MsQuicNativeMethods.GetContextDelegate>( nativeRegistration.GetContext); SetCallbackHandlerDelegate = Marshal.GetDelegateForFunctionPointer <MsQuicNativeMethods.SetCallbackHandlerDelegate>( nativeRegistration.SetCallbackHandler); SetParamDelegate = Marshal.GetDelegateForFunctionPointer <MsQuicNativeMethods.SetParamDelegate>( nativeRegistration.SetParam); GetParamDelegate = Marshal.GetDelegateForFunctionPointer <MsQuicNativeMethods.GetParamDelegate>( nativeRegistration.GetParam); var registrationConfig = new MsQuicNativeMethods.RegistrationConfig { AppName = "SystemNetQuic", ExecutionProfile = QUIC_EXECUTION_PROFILE.QUIC_EXECUTION_PROFILE_LOW_LATENCY }; RegistrationOpenDelegate(ref registrationConfig, out IntPtr ctx); _registrationContext = ctx; }