Sync shared code from runtime (#19918)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
This commit is contained in:
github-actions[bot] 2020-03-17 16:48:02 +00:00 committed by GitHub
parent 715ed24382
commit 99c9b8ace1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 106 additions and 85 deletions

View File

@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#nullable enable
using System.Buffers;
using System.Diagnostics;
#if KESTREL
@ -93,7 +94,7 @@ namespace System.Net.Http.HPack
private byte[] _headerValueOctets;
private State _state = State.Ready;
private byte[] _headerName;
private byte[]? _headerName;
private int _stringIndex;
private int _stringLength;
private int _headerNameLength;
@ -129,13 +130,13 @@ namespace System.Net.Http.HPack
CheckIncompleteHeaderBlock(endHeaders);
}
public void Decode(ReadOnlySpan<byte> data, bool endHeaders, IHttpHeadersHandler handler)
public void Decode(ReadOnlySpan<byte> data, bool endHeaders, IHttpHeadersHandler? handler)
{
DecodeInternal(data, endHeaders, handler);
CheckIncompleteHeaderBlock(endHeaders);
}
private void DecodeInternal(ReadOnlySpan<byte> data, bool endHeaders, IHttpHeadersHandler handler)
private void DecodeInternal(ReadOnlySpan<byte> data, bool endHeaders, IHttpHeadersHandler? handler)
{
int intResult;
@ -370,7 +371,7 @@ namespace System.Net.Http.HPack
}
}
private void ProcessHeaderValue(IHttpHeadersHandler handler)
private void ProcessHeaderValue(IHttpHeadersHandler? handler)
{
OnString(nextState: State.Ready);
@ -394,7 +395,7 @@ namespace System.Net.Http.HPack
}
}
private void OnIndexedHeaderField(int index, IHttpHeadersHandler handler)
private void OnIndexedHeaderField(int index, IHttpHeadersHandler? handler)
{
HeaderField header = GetHeader(index);
handler?.OnHeader(header.Name, header.Value);

View File

@ -2,6 +2,8 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#nullable enable
using System.Collections.Generic;
using System.Diagnostics;
namespace System.Net.Http.HPack
@ -370,7 +372,7 @@ namespace System.Net.Http.HPack
return false;
}
public static bool EncodeStringLiterals(ReadOnlySpan<string> values, string separator, Span<byte> destination, out int bytesWritten)
public static bool EncodeStringLiterals(ReadOnlySpan<string> values, string? separator, Span<byte> destination, out int bytesWritten)
{
bytesWritten = 0;
@ -393,6 +395,7 @@ namespace System.Net.Http.HPack
valueLength = checked((int)(valueLength + part.Length));
}
Debug.Assert(separator != null);
valueLength = checked((int)(valueLength + (values.Length - 1) * separator.Length));
destination[0] = 0;

View File

@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#nullable enable
using System.Buffers;
using System.Diagnostics;
using System.Net.Http.HPack;
@ -118,7 +119,7 @@ namespace System.Net.Http.QPack
private bool _huffman;
private int? _index;
private byte[] _headerName;
private byte[]? _headerName;
private int _headerNameLength;
private int _headerValueLength;
private int _stringLength;
@ -130,7 +131,7 @@ namespace System.Net.Http.QPack
private static void ReturnAndGetNewPooledArray(ref byte[] buffer, int newSize)
{
byte[] old = buffer;
buffer = null;
buffer = null!;
Pool.Return(old, clearArray: true);
buffer = Pool.Rent(newSize);
@ -151,19 +152,19 @@ namespace System.Net.Http.QPack
if (_stringOctets != null)
{
Pool.Return(_stringOctets, true);
_stringOctets = null;
_stringOctets = null!;
}
if (_headerNameOctets != null)
{
Pool.Return(_headerNameOctets, true);
_headerNameOctets = null;
_headerNameOctets = null!;
}
if (_headerValueOctets != null)
{
Pool.Return(_headerValueOctets, true);
_headerValueOctets = null;
_headerValueOctets = null!;
}
}

View File

@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#nullable enable
using System.Collections.Generic;
using System.Diagnostics;
using System.Net.Http.HPack;
@ -10,7 +11,7 @@ namespace System.Net.Http.QPack
{
internal class QPackEncoder
{
private IEnumerator<KeyValuePair<string, string>> _enumerator;
private IEnumerator<KeyValuePair<string, string>>? _enumerator;
// https://tools.ietf.org/html/draft-ietf-quic-qpack-11#section-4.5.2
// 0 1 2 3 4 5 6 7
@ -194,7 +195,7 @@ namespace System.Net.Http.QPack
/// <summary>
/// Encodes a value by concatenating a collection of strings, separated by a separator string.
/// </summary>
public static bool EncodeValueString(ReadOnlySpan<string> values, string separator, Span<byte> buffer, out int length)
public static bool EncodeValueString(ReadOnlySpan<string> values, string? separator, Span<byte> buffer, out int length)
{
if (values.Length == 1)
{
@ -209,6 +210,7 @@ namespace System.Net.Http.QPack
if (buffer.Length > 0)
{
Debug.Assert(separator != null);
int valueLength = separator.Length * (values.Length - 1);
for (int i = 0; i < values.Length; ++i)
{
@ -386,7 +388,7 @@ namespace System.Net.Http.QPack
do
{
if (!EncodeLiteralHeaderFieldWithoutNameReference(_enumerator.Current.Key, _enumerator.Current.Value, buffer.Slice(length), out int headerLength))
if (!EncodeLiteralHeaderFieldWithoutNameReference(_enumerator!.Current.Key, _enumerator.Current.Value, buffer.Slice(length), out int headerLength))
{
if (length == 0 && throwIfNoneEncoded)
{

View File

@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#nullable enable
using System.Buffers.Binary;
using System.Net.Security;
using System.Net.Sockets;
@ -14,17 +15,17 @@ namespace System.Net.Quic.Implementations.Mock
{
private readonly bool _isClient;
private bool _disposed = false;
private IPEndPoint _remoteEndPoint;
private IPEndPoint _localEndPoint;
private IPEndPoint? _remoteEndPoint;
private IPEndPoint? _localEndPoint;
private object _syncObject = new object();
private Socket _socket = null;
private IPEndPoint _peerListenEndPoint = null;
private TcpListener _inboundListener = null;
private Socket? _socket = null;
private IPEndPoint? _peerListenEndPoint = null;
private TcpListener? _inboundListener = null;
private long _nextOutboundBidirectionalStream;
private long _nextOutboundUnidirectionalStream;
// Constructor for outbound connections
internal MockConnection(IPEndPoint remoteEndPoint, SslClientAuthenticationOptions sslClientAuthenticationOptions, IPEndPoint localEndPoint = null)
internal MockConnection(IPEndPoint? remoteEndPoint, SslClientAuthenticationOptions? sslClientAuthenticationOptions, IPEndPoint? localEndPoint = null)
{
_remoteEndPoint = remoteEndPoint;
_localEndPoint = localEndPoint;
@ -43,8 +44,8 @@ namespace System.Net.Quic.Implementations.Mock
_socket = socket;
_peerListenEndPoint = peerListenEndPoint;
_inboundListener = inboundListener;
_localEndPoint = (IPEndPoint)socket.LocalEndPoint;
_remoteEndPoint = (IPEndPoint)socket.RemoteEndPoint;
_localEndPoint = (IPEndPoint?)socket.LocalEndPoint;
_remoteEndPoint = (IPEndPoint?)socket.RemoteEndPoint;
}
internal override bool Connected
@ -57,9 +58,9 @@ namespace System.Net.Quic.Implementations.Mock
}
}
internal override IPEndPoint LocalEndPoint => new IPEndPoint(_localEndPoint.Address, _localEndPoint.Port);
internal override IPEndPoint LocalEndPoint => new IPEndPoint(_localEndPoint!.Address, _localEndPoint.Port);
internal override IPEndPoint RemoteEndPoint => new IPEndPoint(_remoteEndPoint.Address, _remoteEndPoint.Port);
internal override IPEndPoint RemoteEndPoint => new IPEndPoint(_remoteEndPoint!.Address, _remoteEndPoint.Port);
internal override SslApplicationProtocol NegotiatedApplicationProtocol => throw new NotImplementedException();
@ -73,14 +74,14 @@ namespace System.Net.Quic.Implementations.Mock
throw new InvalidOperationException("Already connected");
}
Socket socket = new Socket(_remoteEndPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
Socket socket = new Socket(_remoteEndPoint!.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
await socket.ConnectAsync(_remoteEndPoint).ConfigureAwait(false);
socket.NoDelay = true;
_localEndPoint = (IPEndPoint)socket.LocalEndPoint;
_localEndPoint = (IPEndPoint?)socket.LocalEndPoint;
// Listen on a new local endpoint for inbound streams
TcpListener inboundListener = new TcpListener(_localEndPoint.Address, 0);
TcpListener inboundListener = new TcpListener(_localEndPoint!.Address, 0);
inboundListener.Start();
int inboundListenPort = ((IPEndPoint)inboundListener.LocalEndpoint).Port;
@ -97,7 +98,7 @@ namespace System.Net.Quic.Implementations.Mock
} while (bytesRead != buffer.Length);
int peerListenPort = BinaryPrimitives.ReadInt32LittleEndian(buffer);
IPEndPoint peerListenEndPoint = new IPEndPoint(((IPEndPoint)socket.RemoteEndPoint).Address, peerListenPort);
IPEndPoint peerListenEndPoint = new IPEndPoint(((IPEndPoint)socket.RemoteEndPoint!).Address, peerListenPort);
_socket = socket;
_peerListenEndPoint = peerListenEndPoint;
@ -141,7 +142,7 @@ namespace System.Net.Quic.Implementations.Mock
internal async Task<Socket> CreateOutboundMockStreamAsync(long streamId)
{
Socket socket = new Socket(SocketType.Stream, ProtocolType.Tcp);
await socket.ConnectAsync(_peerListenEndPoint).ConfigureAwait(false);
await socket.ConnectAsync(_peerListenEndPoint!).ConfigureAwait(false);
socket.NoDelay = true;
// Write stream ID to socket so server can read it
@ -156,7 +157,7 @@ namespace System.Net.Quic.Implementations.Mock
{
CheckDisposed();
Socket socket = await _inboundListener.AcceptSocketAsync().ConfigureAwait(false);
Socket socket = await _inboundListener!.AcceptSocketAsync().ConfigureAwait(false);
// Read first bytes to get stream ID
byte[] buffer = new byte[8];

View File

@ -10,7 +10,7 @@ namespace System.Net.Quic.Implementations.Mock
{
internal override QuicListenerProvider CreateListener(QuicListenerOptions options)
{
return new MockListener(options.ListenEndPoint, options.ServerAuthenticationOptions);
return new MockListener(options.ListenEndPoint!, options.ServerAuthenticationOptions);
}
internal override QuicConnectionProvider CreateConnection(QuicClientConnectionOptions options)

View File

@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#nullable enable
using System.Net.Sockets;
using System.Net.Security;
using System.Threading.Tasks;
@ -13,11 +14,11 @@ namespace System.Net.Quic.Implementations.Mock
internal sealed class MockListener : QuicListenerProvider
{
private bool _disposed = false;
private SslServerAuthenticationOptions _sslOptions;
private SslServerAuthenticationOptions? _sslOptions;
private IPEndPoint _listenEndPoint;
private TcpListener _tcpListener = null;
private TcpListener _tcpListener;
internal MockListener(IPEndPoint listenEndPoint, SslServerAuthenticationOptions sslServerAuthenticationOptions)
internal MockListener(IPEndPoint listenEndPoint, SslServerAuthenticationOptions? sslServerAuthenticationOptions)
{
if (listenEndPoint == null)
{
@ -49,7 +50,7 @@ namespace System.Net.Quic.Implementations.Mock
} while (bytesRead != buffer.Length);
int peerListenPort = BinaryPrimitives.ReadInt32LittleEndian(buffer);
IPEndPoint peerListenEndPoint = new IPEndPoint(((IPEndPoint)socket.RemoteEndPoint).Address, peerListenPort);
IPEndPoint peerListenEndPoint = new IPEndPoint(((IPEndPoint)socket.RemoteEndPoint!).Address, peerListenPort);
// Listen on a new local endpoint for inbound streams
TcpListener inboundListener = new TcpListener(_listenEndPoint.Address, 0);
@ -96,7 +97,7 @@ namespace System.Net.Quic.Implementations.Mock
if (disposing)
{
_tcpListener?.Stop();
_tcpListener = null;
_tcpListener = null!;
}
// TODO: free unmanaged resources (unmanaged objects) and override a finalizer below.

View File

@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#nullable enable
using System.Buffers;
using System.Diagnostics;
using System.Net.Sockets;
@ -17,9 +18,9 @@ namespace System.Net.Quic.Implementations.Mock
private bool _canRead;
private bool _canWrite;
private MockConnection _connection;
private MockConnection? _connection;
private Socket _socket = null;
private Socket? _socket = null;
// Constructor for outbound streams
internal MockStream(MockConnection connection, long streamId, bool bidirectional)
@ -69,7 +70,7 @@ namespace System.Net.Quic.Implementations.Mock
throw new NotSupportedException();
}
return _socket.Receive(buffer);
return _socket!.Receive(buffer);
}
internal override async ValueTask<int> ReadAsync(Memory<byte> buffer, CancellationToken cancellationToken = default)
@ -86,7 +87,7 @@ namespace System.Net.Quic.Implementations.Mock
await ConnectAsync(cancellationToken).ConfigureAwait(false);
}
return await _socket.ReceiveAsync(buffer, SocketFlags.None, cancellationToken).ConfigureAwait(false);
return await _socket!.ReceiveAsync(buffer, SocketFlags.None, cancellationToken).ConfigureAwait(false);
}
internal override bool CanWrite => _canWrite;
@ -100,7 +101,7 @@ namespace System.Net.Quic.Implementations.Mock
throw new NotSupportedException();
}
_socket.Send(buffer);
_socket!.Send(buffer);
}
internal override ValueTask WriteAsync(ReadOnlyMemory<byte> buffer, CancellationToken cancellationToken = default)
@ -121,11 +122,11 @@ namespace System.Net.Quic.Implementations.Mock
{
await ConnectAsync(cancellationToken).ConfigureAwait(false);
}
await _socket.SendAsync(buffer, SocketFlags.None, cancellationToken).ConfigureAwait(false);
await _socket!.SendAsync(buffer, SocketFlags.None, cancellationToken).ConfigureAwait(false);
if (endStream)
{
_socket.Shutdown(SocketShutdown.Send);
_socket!.Shutdown(SocketShutdown.Send);
}
}
@ -149,12 +150,12 @@ namespace System.Net.Quic.Implementations.Mock
foreach (ReadOnlyMemory<byte> buffer in buffers)
{
await _socket.SendAsync(buffer, SocketFlags.None, cancellationToken).ConfigureAwait(false);
await _socket!.SendAsync(buffer, SocketFlags.None, cancellationToken).ConfigureAwait(false);
}
if (endStream)
{
_socket.Shutdown(SocketShutdown.Send);
_socket!.Shutdown(SocketShutdown.Send);
}
}
@ -178,12 +179,12 @@ namespace System.Net.Quic.Implementations.Mock
foreach (ReadOnlyMemory<byte> buffer in buffers.ToArray())
{
await _socket.SendAsync(buffer, SocketFlags.None, cancellationToken).ConfigureAwait(false);
await _socket!.SendAsync(buffer, SocketFlags.None, cancellationToken).ConfigureAwait(false);
}
if (endStream)
{
_socket.Shutdown(SocketShutdown.Send);
_socket!.Shutdown(SocketShutdown.Send);
}
}
@ -221,7 +222,7 @@ namespace System.Net.Quic.Implementations.Mock
{
CheckDisposed();
_socket.Shutdown(SocketShutdown.Send);
_socket!.Shutdown(SocketShutdown.Send);
}
private void CheckDisposed()

View File

@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#nullable enable
using System.IO;
using System.Net.Security;
using System.Runtime.InteropServices;
@ -127,7 +128,7 @@ namespace System.Net.Quic.Implementations.MsQuic.Internal
_registrationContext = ctx;
}
internal static MsQuicApi Api { get; }
internal static MsQuicApi Api { get; } = null!;
internal static bool IsQuicSupported { get; }
@ -221,10 +222,10 @@ namespace System.Net.Quic.Implementations.MsQuic.Internal
buf);
}
public async ValueTask<MsQuicSecurityConfig> CreateSecurityConfig(X509Certificate certificate, string certFilePath, string privateKeyFilePath)
public async ValueTask<MsQuicSecurityConfig?> CreateSecurityConfig(X509Certificate certificate, string? certFilePath, string? privateKeyFilePath)
{
MsQuicSecurityConfig secConfig = null;
var tcs = new TaskCompletionSource<object>(TaskCreationOptions.RunContinuationsAsynchronously);
MsQuicSecurityConfig? secConfig = null;
var tcs = new TaskCompletionSource<object?>(TaskCreationOptions.RunContinuationsAsynchronously);
uint secConfigCreateStatus = MsQuicStatusCodes.InternalError;
uint createConfigStatus;
IntPtr unmanagedAddr = IntPtr.Zero;

View File

@ -22,7 +22,7 @@ namespace System.Net.Quic.Implementations.MsQuic.Internal
{
if (!_opened)
{
OpenSession(options.ClientAuthenticationOptions.ApplicationProtocols[0].Protocol.ToArray(),
OpenSession(options.ClientAuthenticationOptions!.ApplicationProtocols![0].Protocol.ToArray(),
(ushort)options.MaxBidirectionalStreams,
(ushort)options.MaxUnidirectionalStreams);
}
@ -50,7 +50,7 @@ namespace System.Net.Quic.Implementations.MsQuic.Internal
{
if (!_opened)
{
OpenSession(options.ServerAuthenticationOptions.ApplicationProtocols[0].Protocol.ToArray(),
OpenSession(options.ServerAuthenticationOptions!.ApplicationProtocols![0].Protocol.ToArray(),
(ushort)options.MaxBidirectionalStreams,
(ushort)options.MaxUnidirectionalStreams);
}

View File

@ -2,11 +2,12 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#nullable enable
namespace System.Net.Quic.Implementations.MsQuic.Internal
{
internal static class QuicExceptionHelpers
{
internal static void ThrowIfFailed(uint status, string message = null, Exception innerException = null)
internal static void ThrowIfFailed(uint status, string? message = null, Exception? innerException = null)
{
if (!MsQuicStatusHelper.SuccessfulStatusCode(status))
{

View File

@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#nullable enable
using System.Threading.Tasks;
using System.Threading.Tasks.Sources;
@ -35,7 +36,7 @@ namespace System.Net.Quic.Implementations.MsQuic.Internal
return _valueTaskSource.GetStatus(token);
}
public void OnCompleted(Action<object> continuation, object state, short token, ValueTaskSourceOnCompletedFlags flags)
public void OnCompleted(Action<object?> continuation, object? state, short token, ValueTaskSourceOnCompletedFlags flags)
{
_valueTaskSource.OnCompleted(continuation, state, token, flags);
}

View File

@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#nullable enable
using System.IO;
using System.Net.Quic.Implementations.MsQuic.Internal;
using System.Net.Security;
@ -16,7 +17,7 @@ namespace System.Net.Quic.Implementations.MsQuic
{
internal sealed class MsQuicConnection : QuicConnectionProvider
{
private MsQuicSession _session;
private MsQuicSession? _session;
// Pointer to the underlying connection
// TODO replace all IntPtr with SafeHandles
@ -27,10 +28,10 @@ namespace System.Net.Quic.Implementations.MsQuic
// Delegate that wraps the static function that will be called when receiving an event.
// TODO investigate if the delegate can be static instead.
private ConnectionCallbackDelegate _connectionDelegate;
private ConnectionCallbackDelegate? _connectionDelegate;
// Endpoint to either connect to or the endpoint already accepted.
private IPEndPoint _localEndPoint;
private IPEndPoint? _localEndPoint;
private readonly IPEndPoint _remoteEndPoint;
private readonly ResettableCompletionSource<uint> _connectTcs = new ResettableCompletionSource<uint>();
@ -38,7 +39,7 @@ namespace System.Net.Quic.Implementations.MsQuic
private bool _disposed;
private bool _connected;
private MsQuicSecurityConfig _securityConfig;
private MsQuicSecurityConfig? _securityConfig;
private long _abortErrorCode = -1;
// Queue for accepted streams
@ -70,7 +71,7 @@ namespace System.Net.Quic.Implementations.MsQuic
// Creating a session per connection isn't ideal.
_session = new MsQuicSession();
_ptr = _session.ConnectionOpen(options);
_remoteEndPoint = options.RemoteEndPoint;
_remoteEndPoint = options.RemoteEndPoint!;
SetCallbackHandler();
SetIdleTimeout(options.IdleTimeout);
@ -82,15 +83,15 @@ namespace System.Net.Quic.Implementations.MsQuic
{
get
{
return new IPEndPoint(_localEndPoint.Address, _localEndPoint.Port);
return new IPEndPoint(_localEndPoint!.Address, _localEndPoint.Port);
}
}
internal async ValueTask SetSecurityConfigForConnection(X509Certificate cert, string certFilePath, string privateKeyFilePath)
internal async ValueTask SetSecurityConfigForConnection(X509Certificate cert, string? certFilePath, string? privateKeyFilePath)
{
_securityConfig = await MsQuicApi.Api.CreateSecurityConfig(cert, certFilePath, privateKeyFilePath);
// TODO this isn't being set correctly
MsQuicParameterHelpers.SetSecurityConfig(MsQuicApi.Api, _ptr, (uint)QUIC_PARAM_LEVEL.CONNECTION, (uint)QUIC_PARAM_CONN.SEC_CONFIG, _securityConfig.NativeObjPtr);
MsQuicParameterHelpers.SetSecurityConfig(MsQuicApi.Api, _ptr, (uint)QUIC_PARAM_LEVEL.CONNECTION, (uint)QUIC_PARAM_CONN.SEC_CONFIG, _securityConfig!.NativeObjPtr);
}
internal override IPEndPoint RemoteEndPoint => new IPEndPoint(_remoteEndPoint.Address, _remoteEndPoint.Port);
@ -355,7 +356,7 @@ namespace System.Net.Quic.Implementations.MsQuic
ref ConnectionEvent connectionEventStruct)
{
GCHandle handle = GCHandle.FromIntPtr(context);
MsQuicConnection quicConnection = (MsQuicConnection)handle.Target;
MsQuicConnection quicConnection = (MsQuicConnection)handle.Target!;
return quicConnection.HandleEvent(ref connectionEventStruct);
}

View File

@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#nullable enable
using System.Net.Quic.Implementations.MsQuic.Internal;
using System.Net.Security;
using System.Runtime.InteropServices;
@ -25,7 +26,7 @@ namespace System.Net.Quic.Implementations.MsQuic
private GCHandle _handle;
// Delegate that wraps the static function that will be called when receiving an event.
private ListenerCallbackDelegate _listenerDelegate;
private ListenerCallbackDelegate? _listenerDelegate;
// Ssl listening options (ALPN, cert, etc)
private SslServerAuthenticationOptions _sslOptions;
@ -46,8 +47,8 @@ namespace System.Net.Quic.Implementations.MsQuic
});
_options = options;
_sslOptions = options.ServerAuthenticationOptions;
_listenEndPoint = options.ListenEndPoint;
_sslOptions = options.ServerAuthenticationOptions!;
_listenEndPoint = options.ListenEndPoint!;
_ptr = _session.ListenerOpen(options);
}
@ -77,7 +78,7 @@ namespace System.Net.Quic.Implementations.MsQuic
throw new QuicOperationAbortedException();
}
await connection.SetSecurityConfigForConnection(_sslOptions.ServerCertificate,
await connection.SetSecurityConfigForConnection(_sslOptions.ServerCertificate!,
_options.CertificateFilePath,
_options.PrivateKeyFilePath);
@ -187,7 +188,7 @@ namespace System.Net.Quic.Implementations.MsQuic
ref ListenerEvent connectionEventStruct)
{
GCHandle handle = GCHandle.FromIntPtr(context);
MsQuicListener quicListener = (MsQuicListener)handle.Target;
MsQuicListener quicListener = (MsQuicListener)handle.Target!;
return quicListener.ListenerCallbackHandler(ref connectionEventStruct);
}

View File

@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#nullable enable
using System.Buffers;
using System.Collections.Generic;
using System.Diagnostics;
@ -23,7 +24,7 @@ namespace System.Net.Quic.Implementations.MsQuic
private GCHandle _handle;
// Delegate that wraps the static function that will be called when receiving an event.
private StreamCallbackDelegate _callback;
private StreamCallbackDelegate? _callback;
// Backing for StreamId
private long _streamId = -1;
@ -424,7 +425,7 @@ namespace System.Net.Quic.Implementations.MsQuic
{
ThrowIfDisposed();
return default;
return default!;
}
public override ValueTask DisposeAsync()
@ -500,7 +501,7 @@ namespace System.Net.Quic.Implementations.MsQuic
ref StreamEvent streamEvent)
{
var handle = GCHandle.FromIntPtr(context);
var quicStream = (MsQuicStream)handle.Target;
var quicStream = (MsQuicStream)handle.Target!;
return quicStream.HandleEvent(ref streamEvent);
}

View File

@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#nullable enable
using System.Net.Sockets;
using System.Runtime.InteropServices;
using System.Text;
@ -90,7 +91,7 @@ namespace System.Net.Quic.Implementations.MsQuic.Internal
IntPtr registrationContext,
uint flags,
IntPtr certificate,
[MarshalAs(UnmanagedType.LPStr)]string principal,
[MarshalAs(UnmanagedType.LPStr)]string? principal,
IntPtr context,
SecConfigCreateCompleteDelegate completionHandler);

View File

@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#nullable enable
using System.Net.Security;
namespace System.Net.Quic
@ -14,17 +15,17 @@ namespace System.Net.Quic
/// <summary>
/// Client authentication options to use when establishing a <see cref="QuicConnection"/>.
/// </summary>
public SslClientAuthenticationOptions ClientAuthenticationOptions { get; set; }
public SslClientAuthenticationOptions? ClientAuthenticationOptions { get; set; }
/// <summary>
/// The local endpoint that will be bound to.
/// </summary>
public IPEndPoint LocalEndPoint { get; set; }
public IPEndPoint? LocalEndPoint { get; set; }
/// <summary>
/// The endpoint to connect to.
/// </summary>
public IPEndPoint RemoteEndPoint { get; set; }
public IPEndPoint? RemoteEndPoint { get; set; }
/// <summary>
/// Limit on the number of bidirectional streams the peer connection can create

View File

@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#nullable enable
using System.Net.Quic.Implementations;
using System.Net.Quic.Implementations.MsQuic.Internal;
using System.Net.Security;
@ -22,13 +23,13 @@ namespace System.Net.Quic
/// <param name="remoteEndPoint">The remote endpoint to connect to.</param>
/// <param name="sslClientAuthenticationOptions">TLS options</param>
/// <param name="localEndPoint">The local endpoint to connect from.</param>
public QuicConnection(IPEndPoint remoteEndPoint, SslClientAuthenticationOptions sslClientAuthenticationOptions, IPEndPoint localEndPoint = null)
public QuicConnection(IPEndPoint remoteEndPoint, SslClientAuthenticationOptions? sslClientAuthenticationOptions, IPEndPoint? localEndPoint = null)
: this(QuicImplementationProviders.Default, remoteEndPoint, sslClientAuthenticationOptions, localEndPoint)
{
}
// !!! TEMPORARY: Remove "implementationProvider" before shipping
public QuicConnection(QuicImplementationProvider implementationProvider, IPEndPoint remoteEndPoint, SslClientAuthenticationOptions sslClientAuthenticationOptions, IPEndPoint localEndPoint = null)
public QuicConnection(QuicImplementationProvider implementationProvider, IPEndPoint remoteEndPoint, SslClientAuthenticationOptions? sslClientAuthenticationOptions, IPEndPoint? localEndPoint = null)
: this(implementationProvider, new QuicClientConnectionOptions() { RemoteEndPoint = remoteEndPoint, ClientAuthenticationOptions = sslClientAuthenticationOptions, LocalEndPoint = localEndPoint })
{
}

View File

@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#nullable enable
using System.Net.Security;
namespace System.Net.Quic
@ -14,22 +15,22 @@ namespace System.Net.Quic
/// <summary>
/// Server Ssl options to use for ALPN, SNI, etc.
/// </summary>
public SslServerAuthenticationOptions ServerAuthenticationOptions { get; set; }
public SslServerAuthenticationOptions? ServerAuthenticationOptions { get; set; }
/// <summary>
/// Optional path to certificate file to configure the security configuration.
/// </summary>
public string CertificateFilePath { get; set; }
public string? CertificateFilePath { get; set; }
/// <summary>
/// Optional path to private key file to configure the security configuration.
/// </summary>
public string PrivateKeyFilePath { get; set; }
public string? PrivateKeyFilePath { get; set; }
/// <summary>
/// The endpoint to listen on.
/// </summary>
public IPEndPoint ListenEndPoint { get; set; }
public IPEndPoint? ListenEndPoint { get; set; }
/// <summary>
/// Number of connections to be held without accepting the connection.

View File

@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#nullable enable
using System.Buffers;
using System.IO;
using System.Net.Quic.Implementations;
@ -29,13 +30,13 @@ namespace System.Net.Quic
public override void SetLength(long value) => throw new NotSupportedException();
public override long Position { get => throw new NotSupportedException(); set => throw new NotSupportedException(); }
public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state) =>
public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback? callback, object? state) =>
TaskToApm.Begin(ReadAsync(buffer, offset, count, default), callback, state);
public override int EndRead(IAsyncResult asyncResult) =>
TaskToApm.End<int>(asyncResult);
public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state) =>
public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback? callback, object? state) =>
TaskToApm.Begin(WriteAsync(buffer, offset, count, default), callback, state);
public override void EndWrite(IAsyncResult asyncResult) =>