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

View File

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

View File

@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license. // The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information. // See the LICENSE file in the project root for more information.
#nullable enable
using System.Buffers; using System.Buffers;
using System.Diagnostics; using System.Diagnostics;
using System.Net.Http.HPack; using System.Net.Http.HPack;
@ -118,7 +119,7 @@ namespace System.Net.Http.QPack
private bool _huffman; private bool _huffman;
private int? _index; private int? _index;
private byte[] _headerName; private byte[]? _headerName;
private int _headerNameLength; private int _headerNameLength;
private int _headerValueLength; private int _headerValueLength;
private int _stringLength; private int _stringLength;
@ -130,7 +131,7 @@ namespace System.Net.Http.QPack
private static void ReturnAndGetNewPooledArray(ref byte[] buffer, int newSize) private static void ReturnAndGetNewPooledArray(ref byte[] buffer, int newSize)
{ {
byte[] old = buffer; byte[] old = buffer;
buffer = null; buffer = null!;
Pool.Return(old, clearArray: true); Pool.Return(old, clearArray: true);
buffer = Pool.Rent(newSize); buffer = Pool.Rent(newSize);
@ -151,19 +152,19 @@ namespace System.Net.Http.QPack
if (_stringOctets != null) if (_stringOctets != null)
{ {
Pool.Return(_stringOctets, true); Pool.Return(_stringOctets, true);
_stringOctets = null; _stringOctets = null!;
} }
if (_headerNameOctets != null) if (_headerNameOctets != null)
{ {
Pool.Return(_headerNameOctets, true); Pool.Return(_headerNameOctets, true);
_headerNameOctets = null; _headerNameOctets = null!;
} }
if (_headerValueOctets != null) if (_headerValueOctets != null)
{ {
Pool.Return(_headerValueOctets, true); 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. // The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information. // See the LICENSE file in the project root for more information.
#nullable enable
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Net.Http.HPack; using System.Net.Http.HPack;
@ -10,7 +11,7 @@ namespace System.Net.Http.QPack
{ {
internal class QPackEncoder 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 // https://tools.ietf.org/html/draft-ietf-quic-qpack-11#section-4.5.2
// 0 1 2 3 4 5 6 7 // 0 1 2 3 4 5 6 7
@ -194,7 +195,7 @@ namespace System.Net.Http.QPack
/// <summary> /// <summary>
/// Encodes a value by concatenating a collection of strings, separated by a separator string. /// Encodes a value by concatenating a collection of strings, separated by a separator string.
/// </summary> /// </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) if (values.Length == 1)
{ {
@ -209,6 +210,7 @@ namespace System.Net.Http.QPack
if (buffer.Length > 0) if (buffer.Length > 0)
{ {
Debug.Assert(separator != null);
int valueLength = separator.Length * (values.Length - 1); int valueLength = separator.Length * (values.Length - 1);
for (int i = 0; i < values.Length; ++i) for (int i = 0; i < values.Length; ++i)
{ {
@ -386,7 +388,7 @@ namespace System.Net.Http.QPack
do 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) if (length == 0 && throwIfNoneEncoded)
{ {

View File

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

View File

@ -10,7 +10,7 @@ namespace System.Net.Quic.Implementations.Mock
{ {
internal override QuicListenerProvider CreateListener(QuicListenerOptions options) 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) internal override QuicConnectionProvider CreateConnection(QuicClientConnectionOptions options)

View File

@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license. // The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information. // See the LICENSE file in the project root for more information.
#nullable enable
using System.Net.Sockets; using System.Net.Sockets;
using System.Net.Security; using System.Net.Security;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -13,11 +14,11 @@ namespace System.Net.Quic.Implementations.Mock
internal sealed class MockListener : QuicListenerProvider internal sealed class MockListener : QuicListenerProvider
{ {
private bool _disposed = false; private bool _disposed = false;
private SslServerAuthenticationOptions _sslOptions; private SslServerAuthenticationOptions? _sslOptions;
private IPEndPoint _listenEndPoint; 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) if (listenEndPoint == null)
{ {
@ -49,7 +50,7 @@ namespace System.Net.Quic.Implementations.Mock
} while (bytesRead != buffer.Length); } while (bytesRead != buffer.Length);
int peerListenPort = BinaryPrimitives.ReadInt32LittleEndian(buffer); 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 // Listen on a new local endpoint for inbound streams
TcpListener inboundListener = new TcpListener(_listenEndPoint.Address, 0); TcpListener inboundListener = new TcpListener(_listenEndPoint.Address, 0);
@ -96,7 +97,7 @@ namespace System.Net.Quic.Implementations.Mock
if (disposing) if (disposing)
{ {
_tcpListener?.Stop(); _tcpListener?.Stop();
_tcpListener = null; _tcpListener = null!;
} }
// TODO: free unmanaged resources (unmanaged objects) and override a finalizer below. // 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. // The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information. // See the LICENSE file in the project root for more information.
#nullable enable
using System.Buffers; using System.Buffers;
using System.Diagnostics; using System.Diagnostics;
using System.Net.Sockets; using System.Net.Sockets;
@ -17,9 +18,9 @@ namespace System.Net.Quic.Implementations.Mock
private bool _canRead; private bool _canRead;
private bool _canWrite; private bool _canWrite;
private MockConnection _connection; private MockConnection? _connection;
private Socket _socket = null; private Socket? _socket = null;
// Constructor for outbound streams // Constructor for outbound streams
internal MockStream(MockConnection connection, long streamId, bool bidirectional) internal MockStream(MockConnection connection, long streamId, bool bidirectional)
@ -69,7 +70,7 @@ namespace System.Net.Quic.Implementations.Mock
throw new NotSupportedException(); throw new NotSupportedException();
} }
return _socket.Receive(buffer); return _socket!.Receive(buffer);
} }
internal override async ValueTask<int> ReadAsync(Memory<byte> buffer, CancellationToken cancellationToken = default) 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); 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; internal override bool CanWrite => _canWrite;
@ -100,7 +101,7 @@ namespace System.Net.Quic.Implementations.Mock
throw new NotSupportedException(); throw new NotSupportedException();
} }
_socket.Send(buffer); _socket!.Send(buffer);
} }
internal override ValueTask WriteAsync(ReadOnlyMemory<byte> buffer, CancellationToken cancellationToken = default) 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 ConnectAsync(cancellationToken).ConfigureAwait(false);
} }
await _socket.SendAsync(buffer, SocketFlags.None, cancellationToken).ConfigureAwait(false); await _socket!.SendAsync(buffer, SocketFlags.None, cancellationToken).ConfigureAwait(false);
if (endStream) 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) 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) 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()) 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) if (endStream)
{ {
_socket.Shutdown(SocketShutdown.Send); _socket!.Shutdown(SocketShutdown.Send);
} }
} }
@ -221,7 +222,7 @@ namespace System.Net.Quic.Implementations.Mock
{ {
CheckDisposed(); CheckDisposed();
_socket.Shutdown(SocketShutdown.Send); _socket!.Shutdown(SocketShutdown.Send);
} }
private void CheckDisposed() private void CheckDisposed()

View File

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

View File

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

View File

@ -2,11 +2,12 @@
// The .NET Foundation licenses this file to you under the MIT license. // The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information. // See the LICENSE file in the project root for more information.
#nullable enable
namespace System.Net.Quic.Implementations.MsQuic.Internal namespace System.Net.Quic.Implementations.MsQuic.Internal
{ {
internal static class QuicExceptionHelpers 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)) if (!MsQuicStatusHelper.SuccessfulStatusCode(status))
{ {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license. // The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information. // See the LICENSE file in the project root for more information.
#nullable enable
using System.Net.Security; using System.Net.Security;
namespace System.Net.Quic namespace System.Net.Quic
@ -14,17 +15,17 @@ namespace System.Net.Quic
/// <summary> /// <summary>
/// Client authentication options to use when establishing a <see cref="QuicConnection"/>. /// Client authentication options to use when establishing a <see cref="QuicConnection"/>.
/// </summary> /// </summary>
public SslClientAuthenticationOptions ClientAuthenticationOptions { get; set; } public SslClientAuthenticationOptions? ClientAuthenticationOptions { get; set; }
/// <summary> /// <summary>
/// The local endpoint that will be bound to. /// The local endpoint that will be bound to.
/// </summary> /// </summary>
public IPEndPoint LocalEndPoint { get; set; } public IPEndPoint? LocalEndPoint { get; set; }
/// <summary> /// <summary>
/// The endpoint to connect to. /// The endpoint to connect to.
/// </summary> /// </summary>
public IPEndPoint RemoteEndPoint { get; set; } public IPEndPoint? RemoteEndPoint { get; set; }
/// <summary> /// <summary>
/// Limit on the number of bidirectional streams the peer connection can create /// 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. // The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information. // See the LICENSE file in the project root for more information.
#nullable enable
using System.Net.Quic.Implementations; using System.Net.Quic.Implementations;
using System.Net.Quic.Implementations.MsQuic.Internal; using System.Net.Quic.Implementations.MsQuic.Internal;
using System.Net.Security; using System.Net.Security;
@ -22,13 +23,13 @@ namespace System.Net.Quic
/// <param name="remoteEndPoint">The remote endpoint to connect to.</param> /// <param name="remoteEndPoint">The remote endpoint to connect to.</param>
/// <param name="sslClientAuthenticationOptions">TLS options</param> /// <param name="sslClientAuthenticationOptions">TLS options</param>
/// <param name="localEndPoint">The local endpoint to connect from.</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) : this(QuicImplementationProviders.Default, remoteEndPoint, sslClientAuthenticationOptions, localEndPoint)
{ {
} }
// !!! TEMPORARY: Remove "implementationProvider" before shipping // !!! 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 }) : 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. // The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information. // See the LICENSE file in the project root for more information.
#nullable enable
using System.Net.Security; using System.Net.Security;
namespace System.Net.Quic namespace System.Net.Quic
@ -14,22 +15,22 @@ namespace System.Net.Quic
/// <summary> /// <summary>
/// Server Ssl options to use for ALPN, SNI, etc. /// Server Ssl options to use for ALPN, SNI, etc.
/// </summary> /// </summary>
public SslServerAuthenticationOptions ServerAuthenticationOptions { get; set; } public SslServerAuthenticationOptions? ServerAuthenticationOptions { get; set; }
/// <summary> /// <summary>
/// Optional path to certificate file to configure the security configuration. /// Optional path to certificate file to configure the security configuration.
/// </summary> /// </summary>
public string CertificateFilePath { get; set; } public string? CertificateFilePath { get; set; }
/// <summary> /// <summary>
/// Optional path to private key file to configure the security configuration. /// Optional path to private key file to configure the security configuration.
/// </summary> /// </summary>
public string PrivateKeyFilePath { get; set; } public string? PrivateKeyFilePath { get; set; }
/// <summary> /// <summary>
/// The endpoint to listen on. /// The endpoint to listen on.
/// </summary> /// </summary>
public IPEndPoint ListenEndPoint { get; set; } public IPEndPoint? ListenEndPoint { get; set; }
/// <summary> /// <summary>
/// Number of connections to be held without accepting the connection. /// 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. // The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information. // See the LICENSE file in the project root for more information.
#nullable enable
using System.Buffers; using System.Buffers;
using System.IO; using System.IO;
using System.Net.Quic.Implementations; using System.Net.Quic.Implementations;
@ -29,13 +30,13 @@ namespace System.Net.Quic
public override void SetLength(long value) => throw new NotSupportedException(); public override void SetLength(long value) => throw new NotSupportedException();
public override long Position { get => throw new NotSupportedException(); set => 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); TaskToApm.Begin(ReadAsync(buffer, offset, count, default), callback, state);
public override int EndRead(IAsyncResult asyncResult) => public override int EndRead(IAsyncResult asyncResult) =>
TaskToApm.End<int>(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); TaskToApm.Begin(WriteAsync(buffer, offset, count, default), callback, state);
public override void EndWrite(IAsyncResult asyncResult) => public override void EndWrite(IAsyncResult asyncResult) =>