// constructor for inbound connections public MsQuicConnection(IPEndPoint localEndPoint, IPEndPoint remoteEndPoint, MsQuicListener.State listenerState, SafeMsQuicConnectionHandle handle, bool remoteCertificateRequired = false, X509RevocationMode revocationMode = X509RevocationMode.Offline, RemoteCertificateValidationCallback?remoteCertificateValidationCallback = null, ServerCertificateSelectionCallback?serverCertificateSelectionCallback = null) { _state.Handle = handle; _state.StateGCHandle = GCHandle.Alloc(_state); _state.RemoteCertificateRequired = remoteCertificateRequired; _state.RevocationMode = revocationMode; _state.RemoteCertificateValidationCallback = remoteCertificateValidationCallback; _state.IsServer = true; _localEndPoint = localEndPoint; _remoteEndPoint = remoteEndPoint; try { Debug.Assert(!Monitor.IsEntered(_state), "!Monitor.IsEntered(_state)"); MsQuicApi.Api.SetCallbackHandlerDelegate( _state.Handle, s_connectionDelegate, GCHandle.ToIntPtr(_state.StateGCHandle)); } catch { _state.StateGCHandle.Free(); throw; } _state.ListenerState = listenerState; _state.TraceId = MsQuicTraceHelper.GetTraceId(_state.Handle); if (NetEventSource.Log.IsEnabled()) { NetEventSource.Info(_state, $"{TraceId()} Inbound connection created"); } }
// constructor for inbound connections public unsafe MsQuicConnection(IPEndPoint localEndPoint, IPEndPoint remoteEndPoint, MsQuicListener.State listenerState, SafeMsQuicConnectionHandle handle, bool remoteCertificateRequired = false, X509RevocationMode revocationMode = X509RevocationMode.Offline, RemoteCertificateValidationCallback?remoteCertificateValidationCallback = null, ServerCertificateSelectionCallback?serverCertificateSelectionCallback = null) { _state.Handle = handle; _state.StateGCHandle = GCHandle.Alloc(_state); _state.RemoteCertificateRequired = remoteCertificateRequired; _state.RevocationMode = revocationMode; _state.RemoteCertificateValidationCallback = remoteCertificateValidationCallback; _state.IsServer = true; _localEndPoint = localEndPoint; _remoteEndPoint = remoteEndPoint; 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)); } catch { _state.StateGCHandle.Free(); throw; } _state.ListenerState = listenerState; if (NetEventSource.Log.IsEnabled()) { NetEventSource.Info(_state, $"{handle} Inbound connection created"); } }