internal static unsafe void SetSecurityConfig(MsQuicApi api, IntPtr nativeObject, uint level, uint param, IntPtr value) { QuicBuffer buffer = new QuicBuffer() { Length = (uint)sizeof(void *), Buffer = (byte *)&value }; MsQuicStatusException.ThrowIfFailed(api.UnsafeSetParam(nativeObject, level, param, buffer)); }
internal static unsafe void SetULongParam(MsQuicApi api, IntPtr nativeObject, uint level, uint param, ulong value) { QuicBuffer buffer = new QuicBuffer() { Length = sizeof(ulong), Buffer = (byte *)&value }; MsQuicStatusException.ThrowIfFailed(api.UnsafeGetParam(nativeObject, level, param, ref buffer)); }
internal static unsafe ulong GetULongParam(MsQuicApi api, IntPtr nativeObject, uint level, uint param) { byte * ptr = stackalloc byte[sizeof(ulong)]; QuicBuffer buffer = new QuicBuffer() { Length = sizeof(ulong), Buffer = ptr }; MsQuicStatusException.ThrowIfFailed(api.UnsafeGetParam(nativeObject, level, param, ref buffer)); return(*(ulong *)ptr); }
internal static unsafe SOCKADDR_INET GetINetParam(MsQuicApi api, IntPtr nativeObject, uint level, uint param) { byte * ptr = stackalloc byte[sizeof(SOCKADDR_INET)]; QuicBuffer buffer = new QuicBuffer { Length = (uint)sizeof(SOCKADDR_INET), Buffer = ptr }; MsQuicStatusException.ThrowIfFailed(api.UnsafeGetParam(nativeObject, level, param, ref buffer)); return(*(SOCKADDR_INET *)ptr); }
public IntPtr SessionOpen(byte[] alpn) { IntPtr sessionPtr = IntPtr.Zero; uint status = SessionOpenDelegate( _registrationContext, alpn, IntPtr.Zero, ref sessionPtr); MsQuicStatusException.ThrowIfFailed(status); return(sessionPtr); }
public async ValueTask <MsQuicSecurityConfig> CreateSecurityConfig(X509Certificate certificate) { MsQuicSecurityConfig secConfig = null; var tcs = new TaskCompletionSource <object>(TaskCreationOptions.RunContinuationsAsynchronously); uint secConfigCreateStatus = MsQuicStatusCodes.InternalError; uint status; if (certificate != null) { status = SecConfigCreateDelegate( _registrationContext, (uint)QUIC_SEC_CONFIG_FLAG.CERT_CONTEXT, certificate.Handle, null, IntPtr.Zero, SecCfgCreateCallbackHandler); } else { status = SecConfigCreateDelegate( _registrationContext, (uint)QUIC_SEC_CONFIG_FLAG.CERT_NULL, IntPtr.Zero, null, IntPtr.Zero, SecCfgCreateCallbackHandler); } MsQuicStatusException.ThrowIfFailed(status); void SecCfgCreateCallbackHandler( IntPtr context, uint status, IntPtr securityConfig) { secConfig = new MsQuicSecurityConfig(this, securityConfig); secConfigCreateStatus = status; tcs.SetResult(null); } await tcs.Task.ConfigureAwait(false); MsQuicStatusException.ThrowIfFailed(secConfigCreateStatus); return(secConfig); }
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; }