Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Platform-Guard Assertion Annotations for some known cases #52689

Merged
merged 7 commits into from
May 17, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
<MicrosoftCodeAnalysisVersion>3.8.0</MicrosoftCodeAnalysisVersion>
</PropertyGroup>
<PropertyGroup>
<MicrosoftCodeAnalysisNetAnalyzersVersion>6.0.0-preview5.21219.2</MicrosoftCodeAnalysisNetAnalyzersVersion>
<MicrosoftCodeAnalysisNetAnalyzersVersion>6.0.0-preview5.21262.4</MicrosoftCodeAnalysisNetAnalyzersVersion>
<MicrosoftCodeAnalysisCSharpCodeStyleVersion>3.10.0-2.final</MicrosoftCodeAnalysisCSharpCodeStyleVersion>
<MicrosoftCodeAnalysisCSharpVersion>3.10.0-2.final</MicrosoftCodeAnalysisCSharpVersion>
<!-- Arcade dependencies -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ public ConsoleLoggerProvider(IOptionsMonitor<ConsoleLoggerOptions> options, IEnu
_optionsReloadToken = _options.OnChange(ReloadLoggerOptions);

_messageQueue = new ConsoleLoggerProcessor();
// TODO update when https://github.com/dotnet/runtime/issues/44922 implemented
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows) || DoesWindowsConsoleSupportAnsi())

if (DoesWindowsConsoleSupportAnsi())
{
_messageQueue.Console = new AnsiLogConsole();
_messageQueue.ErrorConsole = new AnsiLogConsole(stdErr: true);
Expand All @@ -60,8 +60,14 @@ public ConsoleLoggerProvider(IOptionsMonitor<ConsoleLoggerOptions> options, IEnu
}
}

[UnsupportedOSPlatformGuard("windows")]
private static bool DoesWindowsConsoleSupportAnsi()
{
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
buyaa-n marked this conversation as resolved.
Show resolved Hide resolved
{
return true;
}

// for Windows, check the console mode
var stdOutHandle = Interop.Kernel32.GetStdHandle(Interop.Kernel32.STD_OUTPUT_HANDLE);
if (!Interop.Kernel32.GetConsoleMode(stdOutHandle, out int consoleMode))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ internal sealed class HttpConnectionPool : IDisposable
private byte[]? _http2AltSvcOriginUri;
internal readonly byte[]? _http2EncodedAuthorityHostHeader;

[SupportedOSPlatformGuard("linux")]
[SupportedOSPlatformGuard("macOS")]
[SupportedOSPlatformGuard("Windows")]
private readonly bool _http3Enabled;
private Http3Connection? _http3Connection;
private SemaphoreSlim? _http3ConnectionCreateLock;
Expand Down Expand Up @@ -122,8 +125,8 @@ public HttpConnectionPool(HttpConnectionPoolManager poolManager, HttpConnectionK
}

_http2Enabled = _poolManager.Settings._maxHttpVersion >= HttpVersion.Version20;
// TODO: Replace with Platform-Guard Assertion Annotations once https://github.com/dotnet/runtime/issues/44922 is finished
if ((OperatingSystem.IsLinux() && !OperatingSystem.IsAndroid()) || OperatingSystem.IsWindows() || OperatingSystem.IsMacOS())

if (_http3Enabled)
buyaa-n marked this conversation as resolved.
Show resolved Hide resolved
{
_http3Enabled = _poolManager.Settings._maxHttpVersion >= HttpVersion.Version30 && (_poolManager.Settings._quicImplementationProvider ?? QuicImplementationProviders.Default).IsSupported;
buyaa-n marked this conversation as resolved.
Show resolved Hide resolved
}
Expand Down Expand Up @@ -261,14 +264,10 @@ public HttpConnectionPool(HttpConnectionPoolManager poolManager, HttpConnectionK
_http3EncodedAuthorityHostHeader = QPackEncoder.EncodeLiteralHeaderFieldWithStaticNameReferenceToArray(H3StaticTable.Authority, hostHeader);
}

// TODO: Replace with Platform-Guard Assertion Annotations once https://github.com/dotnet/runtime/issues/44922 is finished
if ((OperatingSystem.IsLinux() && !OperatingSystem.IsAndroid()) || OperatingSystem.IsWindows() || OperatingSystem.IsMacOS())
if (_http3Enabled)
{
if (_http3Enabled)
{
_sslOptionsHttp3 = ConstructSslOptions(poolManager, sslHostName);
_sslOptionsHttp3.ApplicationProtocols = s_http3ApplicationProtocols;
}
_sslOptionsHttp3 = ConstructSslOptions(poolManager, sslHostName);
_sslOptionsHttp3.ApplicationProtocols = s_http3ApplicationProtocols;
}
}

Expand Down Expand Up @@ -866,8 +865,7 @@ private async ValueTask<HttpResponseMessage> DetermineVersionAndSendAsync(HttpRe
{
HttpResponseMessage? response;

// TODO: Replace with Platform-Guard Assertion Annotations once https://github.com/dotnet/runtime/issues/44922 is finished
if ((OperatingSystem.IsLinux() && !OperatingSystem.IsAndroid()) || OperatingSystem.IsWindows() || OperatingSystem.IsMacOS())
if (_http3Enabled)
{
response = await TrySendUsingHttp3Async(request, async, doRequestAuth, cancellationToken).ConfigureAwait(false);
if (response is not null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,11 @@ protected internal override void QueueTask(Task task)
if (Thread.IsThreadStartSupported && (options & TaskCreationOptions.LongRunning) != 0)
{
// Run LongRunning tasks on their own dedicated thread.
#pragma warning disable CA1416 // TODO: https://github.com/dotnet/runtime/issues/44922
buyaa-n marked this conversation as resolved.
Show resolved Hide resolved
new Thread(s_longRunningThreadWork)
{
IsBackground = true,
Name = ".NET Long Running Task"
}.UnsafeStart(task);
#pragma warning restore CA1416
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ public Thread(ParameterizedThreadStart start, int maxStackSize)
}

#if !TARGET_BROWSER
[UnsupportedOSPlatformGuard("browser")]
internal const bool IsThreadStartSupported = true;

/// <summary>Causes the operating system to change the state of the current instance to <see cref="ThreadState.Running"/>, and optionally supplies an object containing data to be used by the method the thread executes.</summary>
Expand Down