Skip to content

Commit

Permalink
Move System.Net.Quic to internal shared source (dotnet#32549)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tratcher authored Feb 20, 2020
1 parent aac8f91 commit 3c523a6
Show file tree
Hide file tree
Showing 66 changed files with 1,372 additions and 571 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,8 @@ internal unsafe uint ListenerCallbackHandler(
return MsQuicStatusCodes.InternalError;
}
}
catch (Exception ex)
catch (Exception)
{
Console.WriteLine(ex.Message);
return MsQuicStatusCodes.InternalError;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace System.Net.Quic.Implementations
{
public abstract class QuicImplementationProvider
internal abstract class QuicImplementationProvider
{
internal QuicImplementationProvider() { }

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Runtime.InteropServices;

namespace System.Net.Quic.Implementations.MsQuic.Internal
{
internal static class MsQuicStatusCodes
{
internal static readonly uint Success = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? Windows.Success : Linux.Success;
internal static readonly uint Pending = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? Windows.Pending : Linux.Pending;
internal static readonly uint InternalError = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? Windows.InternalError : Linux.InternalError;

// TODO return better error messages here.
public static string GetError(uint status)
{
return RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
? Windows.GetError(status) : Linux.GetError(status);
}

private static class Windows
{
internal const uint Success = 0;
internal const uint Pending = 0x703E5;
internal const uint Continue = 0x704DE;
internal const uint OutOfMemory = 0x8007000E;
internal const uint InvalidParameter = 0x80070057;
internal const uint InvalidState = 0x8007139F;
internal const uint NotSupported = 0x80004002;
internal const uint NotFound = 0x80070490;
internal const uint BufferTooSmall = 0x8007007A;
internal const uint HandshakeFailure = 0x80410000;
internal const uint Aborted = 0x80004004;
internal const uint AddressInUse = 0x80072740;
internal const uint ConnectionTimeout = 0x800704CF;
internal const uint ConnectionIdle = 0x800704D4;
internal const uint InternalError = 0x80004005;
internal const uint ServerBusy = 0x800704C9;
internal const uint ProtocolError = 0x800704CD;
internal const uint HostUnreachable = 0x800704D0;
internal const uint VerNegError = 0x80410001;

// TODO return better error messages here.
public static string GetError(uint status)
{
return status switch
{
Success => "SUCCESS",
Pending => "PENDING",
Continue => "CONTINUE",
OutOfMemory => "OUT_OF_MEMORY",
InvalidParameter => "INVALID_PARAMETER",
InvalidState => "INVALID_STATE",
NotSupported => "NOT_SUPPORTED",
NotFound => "NOT_FOUND",
BufferTooSmall => "BUFFER_TOO_SMALL",
HandshakeFailure => "HANDSHAKE_FAILURE",
Aborted => "ABORTED",
AddressInUse => "ADDRESS_IN_USE",
ConnectionTimeout => "CONNECTION_TIMEOUT",
ConnectionIdle => "CONNECTION_IDLE",
InternalError => "INTERNAL_ERROR",
ServerBusy => "SERVER_BUSY",
ProtocolError => "PROTOCOL_ERROR",
VerNegError => "VER_NEG_ERROR",
_ => status.ToString()
};
}
}

private static class Linux
{
internal const uint Success = 0;
internal const uint Pending = unchecked((uint)-2);
internal const uint Continue = unchecked((uint)-1);
internal const uint OutOfMemory = 12;
internal const uint InvalidParameter = 22;
internal const uint InvalidState = 200000002;
internal const uint NotSupported = 95;
internal const uint NotFound = 2;
internal const uint BufferTooSmall = 75;
internal const uint HandshakeFailure = 200000009;
internal const uint Aborted = 200000008;
internal const uint AddressInUse = 98;
internal const uint ConnectionTimeout = 110;
internal const uint ConnectionIdle = 200000011;
internal const uint InternalError = 200000012;
internal const uint ServerBusy = 200000007;
internal const uint ProtocolError = 200000013;
internal const uint VerNegError = 200000014;

// TODO return better error messages here.
public static string GetError(uint status)
{
return status switch
{
Success => "SUCCESS",
Pending => "PENDING",
Continue => "CONTINUE",
OutOfMemory => "OUT_OF_MEMORY",
InvalidParameter => "INVALID_PARAMETER",
InvalidState => "INVALID_STATE",
NotSupported => "NOT_SUPPORTED",
NotFound => "NOT_FOUND",
BufferTooSmall => "BUFFER_TOO_SMALL",
HandshakeFailure => "HANDSHAKE_FAILURE",
Aborted => "ABORTED",
AddressInUse => "ADDRESS_IN_USE",
ConnectionTimeout => "CONNECTION_TIMEOUT",
ConnectionIdle => "CONNECTION_IDLE",
InternalError => "INTERNAL_ERROR",
ServerBusy => "SERVER_BUSY",
ProtocolError => "PROTOCOL_ERROR",
VerNegError => "VER_NEG_ERROR",
_ => status.ToString()
};
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

Expand All @@ -10,7 +10,17 @@ internal static class MsQuicStatusHelper
{
internal static bool SuccessfulStatusCode(uint status)
{
return (int)status <= 0;
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
return status < 0x80000000;
}

if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
return (int)status <= 0;
}

return false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace System.Net.Quic
/// <summary>
/// Options to provide to the <see cref="QuicConnection"/> when connecting to a Listener.
/// </summary>
public class QuicClientConnectionOptions
internal class QuicClientConnectionOptions
{
/// <summary>
/// Client authentication options to use when establishing a <see cref="QuicConnection"/>.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace System.Net.Quic
{
public sealed class QuicConnection : IDisposable
internal sealed class QuicConnection : IDisposable
{
private readonly QuicConnectionProvider _provider;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace System.Net.Quic
{
public class QuicConnectionAbortedException : QuicException
internal class QuicConnectionAbortedException : QuicException
{
internal QuicConnectionAbortedException(long errorCode)
: this(SR.Format(SR.net_quic_connectionaborted, errorCode), errorCode)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace System.Net.Quic
{
public class QuicException : Exception
internal class QuicException : Exception
{
public QuicException(string message)
: base (message)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace System.Net.Quic
{
public static class QuicImplementationProviders
internal static class QuicImplementationProviders
{
public static Implementations.QuicImplementationProvider Mock { get; } = new Implementations.Mock.MockImplementationProvider();
public static Implementations.QuicImplementationProvider MsQuic { get; } = new Implementations.MsQuic.MsQuicImplementationProvider();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace System.Net.Quic
{
public sealed class QuicListener : IDisposable
internal sealed class QuicListener : IDisposable
{
private readonly QuicListenerProvider _provider;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace System.Net.Quic
/// <summary>
/// Options to provide to the <see cref="QuicListener"/>.
/// </summary>
public class QuicListenerOptions
internal class QuicListenerOptions
{
/// <summary>
/// Server Ssl options to use for ALPN, SNI, etc.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace System.Net.Quic
{
public class QuicOperationAbortedException : QuicException
internal class QuicOperationAbortedException : QuicException
{
internal QuicOperationAbortedException()
: base(SR.net_quic_operationaborted)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace System.Net.Quic
{
public sealed class QuicStream : Stream
internal sealed class QuicStream : Stream
{
private readonly QuicStreamProvider _provider;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace System.Net.Quic
{
public class QuicStreamAbortedException : QuicException
internal class QuicStreamAbortedException : QuicException
{
internal QuicStreamAbortedException(long errorCode)
: this(SR.Format(SR.net_quic_streamaborted, errorCode), errorCode)
Expand Down
20 changes: 20 additions & 0 deletions src/libraries/Common/src/System/Net/Http/aspnetcore/SR.Quic.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

namespace System.Net.Quic
{
internal static partial class SR
{
// The resource generator used in AspNetCore does not create this method. This file fills in that functional gap
// so we don't have to modify the shared source.
internal static string Format(string resourceFormat, params object[] args)
{
if (args != null)
{
return string.Format(resourceFormat, args);
}

return resourceFormat;
}
}
}
12 changes: 12 additions & 0 deletions src/libraries/Common/src/System/Net/Http/aspnetcore/SR.resx
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,16 @@
<data name="net_http_request_invalid_char_encoding" xml:space="preserve">
<value>Request headers must contain only ASCII characters.</value>
</data>
<data name="net_quic_connectionaborted" xml:space="preserve">
<value>Connection aborted by peer ({0}).</value>
</data>
<data name="net_quic_notsupported" xml:space="preserve">
<value>QUIC is not supported on this platform. See http://aka.ms/dotnetquic</value>
</data>
<data name="net_quic_operationaborted" xml:space="preserve">
<value>Operation aborted.</value>
</data>
<data name="net_quic_streamaborted" xml:space="preserve">
<value>Stream aborted by peer ({0}).</value>
</data>
</root>
Loading

0 comments on commit 3c523a6

Please sign in to comment.