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

Add net462 build to Grpc.Net.Client with WinHttpHandler default #2220

Merged
merged 1 commit into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ internal interface ISubchannelTransport : IDisposable
ValueTask<Stream> GetStreamAsync(BalancerAddress address, CancellationToken cancellationToken);
#endif

#if !NETSTANDARD2_0
#if !NETSTANDARD2_0 && !NET462
ValueTask<ConnectResult>
#else
Task<ConnectResult>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#region Copyright notice and license
#region Copyright notice and license

// Copyright 2019 The gRPC Authors
//
Expand Down Expand Up @@ -52,7 +52,7 @@ public void Disconnect()
}

public
#if !NETSTANDARD2_0
#if !NETSTANDARD2_0 && !NET462
ValueTask<ConnectResult>
#else
Task<ConnectResult>
Expand All @@ -68,7 +68,7 @@ public void Disconnect()
_currentAddress = currentAddress;
_subchannel.UpdateConnectivityState(ConnectivityState.Ready, "Passively connected.");

#if !NETSTANDARD2_0
#if !NETSTANDARD2_0 && !NET462
return new ValueTask<ConnectResult>(ConnectResult.Success);
#else
return Task.FromResult(ConnectResult.Success);
Expand Down
8 changes: 6 additions & 2 deletions src/Grpc.Net.Client/Grpc.Net.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,18 @@

<IsGrpcPublishedPackage>true</IsGrpcPublishedPackage>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<TargetFrameworks>netstandard2.0;netstandard2.1;net5.0;net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>net462;netstandard2.0;netstandard2.1;net5.0;net6.0;net7.0</TargetFrameworks>
<PackageReadmeFile>README.md</PackageReadmeFile>
</PropertyGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0' OR '$(TargetFramework)' == 'netstandard2.1'">
<ItemGroup Condition="'$(TargetFramework)' == 'net462' OR '$(TargetFramework)' == 'netstandard2.0' OR '$(TargetFramework)' == 'netstandard2.1'">
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="$(SystemDiagnosticsDiagnosticSourcePackageVersion)" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net462'">
<PackageReference Include="System.Net.Http.WinHttpHandler" Version="$(SystemNetHttpWinHttpHandlerPackageVersion)" />
</ItemGroup>

<PropertyGroup Condition="'$(TargetFramework)' == 'net5.0' OR '$(TargetFramework)' == 'net6.0' OR '$(TargetFramework)' == 'net7.0'">
<DefineConstants>SUPPORT_LOAD_BALANCING;$(DefineConstants)</DefineConstants>
</PropertyGroup>
Expand Down
4 changes: 4 additions & 0 deletions src/Grpc.Net.Client/GrpcChannel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,11 @@ private static HttpHandlerContext CalculateHandlerContext(ILogger logger, Uri ad
{
// No way to know what handler a HttpClient is using so assume custom.
var type = channelOptions.HttpClient == null
#if NET462
? HttpHandlerType.WinHttpHandler
#else
? HttpHandlerType.SocketsHttpHandler
#endif
: HttpHandlerType.Custom;

return new HttpHandlerContext(type);
Expand Down
6 changes: 3 additions & 3 deletions src/Grpc.Net.Client/Internal/ArrayBufferWriter.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#region Copyright notice and license
#region Copyright notice and license

// Copyright 2019 The gRPC Authors
//
Expand All @@ -18,7 +18,7 @@

using System.Diagnostics;

#if NETSTANDARD2_0
#if NETSTANDARD2_0 || NET462

// Copied with permission from https://github.com/dotnet/runtime/blob/589d0dc326bf0699149f76033fa66d4b22b9a7fd/src/libraries/Common/src/System/Buffers/ArrayBufferWriter.cs
// This copy of ArrayBufferWriter is only used with .NET Stardard 2.0. Later versions of .NET ship with this type.
Expand Down Expand Up @@ -227,4 +227,4 @@ private static void ThrowOutOfMemoryException(uint capacity)
}
}

#endif
#endif
4 changes: 2 additions & 2 deletions src/Grpc.Net.Client/Internal/GrpcCall.NonGeneric.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ private static StatusCode MapHttpStatusToGrpcCode(HttpStatusCode httpStatusCode)
switch (httpStatusCode)
{
case HttpStatusCode.BadRequest: // 400
#if !NETSTANDARD2_0
#if !NETSTANDARD2_0 && !NET462
case HttpStatusCode.RequestHeaderFieldsTooLarge: // 431
#else
case (HttpStatusCode)431:
Expand All @@ -205,7 +205,7 @@ private static StatusCode MapHttpStatusToGrpcCode(HttpStatusCode httpStatusCode)
return StatusCode.PermissionDenied;
case HttpStatusCode.NotFound: // 404
return StatusCode.Unimplemented;
#if !NETSTANDARD2_0
#if !NETSTANDARD2_0 && !NET462
case HttpStatusCode.TooManyRequests: // 429
#else
case (HttpStatusCode)429:
Expand Down
4 changes: 2 additions & 2 deletions src/Grpc.Net.Client/Internal/GrpcCall.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
using Grpc.Net.Client.Balancer.Internal;
#endif

#if NETSTANDARD2_0
#if NETSTANDARD2_0 || NET462
using ValueTask = System.Threading.Tasks.Task;
#endif

Expand Down Expand Up @@ -1116,7 +1116,7 @@ internal ValueTask WriteMessageAsync(
callOptions);
}

#if !NETSTANDARD2_0
#if !NETSTANDARD2_0 && !NET462
internal async ValueTask<TResponse?> ReadMessageAsync(
#else
internal async Task<TResponse?> ReadMessageAsync(
Expand Down
4 changes: 2 additions & 2 deletions src/Grpc.Net.Client/Internal/GrpcCallSerializationContext.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#region Copyright notice and license
#region Copyright notice and license

// Copyright 2019 The gRPC Authors
//
Expand Down Expand Up @@ -295,7 +295,7 @@ private ReadOnlySpan<byte> CompressMessage(ReadOnlySpan<byte> messageData)
// GZipStream writes final Adler32 at the end of the stream on dispose.
using (var compressionStream = _compressionProvider.CreateCompressionStream(output, CompressionLevel.Fastest))
{
#if !NETSTANDARD2_0
#if !NETSTANDARD2_0 && !NET462
compressionStream.Write(messageData);
#else
var array = messageData.ToArray();
Expand Down
6 changes: 3 additions & 3 deletions src/Grpc.Net.Client/Internal/GrpcEventSource.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#region Copyright notice and license
#region Copyright notice and license

// Copyright 2019 The gRPC Authors
//
Expand Down Expand Up @@ -27,7 +27,7 @@ internal sealed class GrpcEventSource : EventSource
{
public static readonly GrpcEventSource Log = new GrpcEventSource();

#if !NETSTANDARD2_0
#if !NETSTANDARD2_0 && !NET462
private PollingCounter? _totalCallsCounter;
private PollingCounter? _currentCallsCounter;
private PollingCounter? _messagesSentCounter;
Expand Down Expand Up @@ -146,7 +146,7 @@ protected override void OnEventCommand(EventCommandEventArgs command)
// This is the convention for initializing counters in the RuntimeEventSource (lazily on the first enable command).
// They aren't disabled afterwards...

#if !NETSTANDARD2_0
#if !NETSTANDARD2_0 && !NET462
_totalCallsCounter ??= new PollingCounter("total-calls", this, () => Volatile.Read(ref _totalCalls))
{
DisplayName = "Total Calls",
Expand Down
6 changes: 3 additions & 3 deletions src/Grpc.Net.Client/Internal/GrpcProtocolConstants.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#region Copyright notice and license
#region Copyright notice and license

// Copyright 2019 The gRPC Authors
//
Expand All @@ -24,7 +24,7 @@ namespace Grpc.Net.Client.Internal;

internal static class GrpcProtocolConstants
{
#if !NETSTANDARD2_0
#if !NETSTANDARD2_0 && !NET462
public static readonly Version Http2Version = System.Net.HttpVersion.Version20;
#else
public static readonly Version Http2Version = new Version(2, 0);
Expand Down Expand Up @@ -76,7 +76,7 @@ internal static class GrpcProtocolConstants
internal static string GetMessageAcceptEncoding(Dictionary<string, ICompressionProvider> compressionProviders)
{
return IdentityGrpcEncoding + "," +
#if !NETSTANDARD2_0
#if !NETSTANDARD2_0 && !NET462
string.Join(',', compressionProviders.Select(p => p.Key));
#else
string.Join(",", compressionProviders.Select(p => p.Key));
Expand Down
2 changes: 1 addition & 1 deletion src/Grpc.Net.Client/Internal/Http/PushStreamContent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

using System.Net;

#if NETSTANDARD2_0
#if NETSTANDARD2_0 || NET462
using ValueTask = System.Threading.Tasks.Task;
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/Grpc.Net.Client/Internal/Http/PushUnaryContent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
using System.Net;
using Grpc.Shared;

#if NETSTANDARD2_0
#if NETSTANDARD2_0 || NET462
using ValueTask = System.Threading.Tasks.Task;
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/Grpc.Net.Client/Internal/Http/WinHttpUnaryContent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
using Grpc.Shared;
using System.Net;

#if NETSTANDARD2_0
#if NETSTANDARD2_0 || NET462
using ValueTask = System.Threading.Tasks.Task;
#endif

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
using Grpc.Shared;
using Log = Grpc.Net.Client.Internal.ClientStreamWriterBaseLog;

#if NETSTANDARD2_0
#if NETSTANDARD2_0 || NET462
using ValueTask = System.Threading.Tasks.Task;
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/Grpc.Net.Client/Internal/IGrpcCall.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
using System.Diagnostics.CodeAnalysis;
using Grpc.Core;

#if NETSTANDARD2_0
#if NETSTANDARD2_0 || NET462
using ValueTask = System.Threading.Tasks.Task;
#endif

Expand Down
4 changes: 2 additions & 2 deletions src/Grpc.Net.Client/Internal/Retry/RetryCallBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
using Microsoft.Extensions.Logging;
using Log = Grpc.Net.Client.Internal.Retry.RetryCallBaseLog;

#if NETSTANDARD2_0
#if NETSTANDARD2_0 || NET462
using ValueTask = System.Threading.Tasks.Task;
#endif

Expand Down Expand Up @@ -202,7 +202,7 @@ private PushStreamContent<TRequest, TResponse> CreatePushStreamContent(GrpcCall<

if (BufferedMessages.Count == 0)
{
#if NETSTANDARD2_0
#if NETSTANDARD2_0 || NET462
writeTask = Task.CompletedTask;
#else
writeTask = default;
Expand Down
2 changes: 1 addition & 1 deletion src/Grpc.Net.Client/Internal/Retry/StatusGrpcCall.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
using System.Diagnostics.CodeAnalysis;
using Grpc.Core;

#if NETSTANDARD2_0
#if NETSTANDARD2_0 || NET462
using ValueTask = System.Threading.Tasks.Task;
#endif

Expand Down
6 changes: 3 additions & 3 deletions src/Grpc.Net.Client/Internal/StreamExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
using Grpc.Shared;
using Microsoft.Extensions.Logging;

#if NETSTANDARD2_0
#if NETSTANDARD2_0 || NET462
using ValueTask = System.Threading.Tasks.Task;
#endif

Expand All @@ -42,7 +42,7 @@ private static Status CreateUnknownMessageEncodingMessageStatus(string unsupport
return new Status(StatusCode.Unimplemented, $"Unsupported grpc-encoding value '{unsupportedEncoding}'. Supported encodings: {string.Join(", ", supportedEncodings)}");
}

#if !NETSTANDARD2_0
#if !NETSTANDARD2_0 && !NET462
public static async ValueTask<TResponse?> ReadMessageAsync<TResponse>(
#else
public static async Task<TResponse?> ReadMessageAsync<TResponse>(
Expand Down Expand Up @@ -194,7 +194,7 @@ private static Status CreateUnknownMessageEncodingMessageStatus(string unsupport
}
}

#if NETSTANDARD2_0
#if NETSTANDARD2_0 || NET462
public static Task<int> ReadAsync(this Stream stream, Memory<byte> buffer, CancellationToken cancellationToken = default)
{
if (MemoryMarshal.TryGetArray<byte>(buffer, out var segment))
Expand Down
4 changes: 2 additions & 2 deletions src/Grpc.Net.Client/Internal/UserAgentGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ private static string GetFrameworkName(string? frameworkName)
}

var splitFramework = frameworkName!.Split(',');
#if !NETSTANDARD2_0
#if !NETSTANDARD2_0 && !NET462
var version = Version.Parse(splitFramework[1].AsSpan("Version=v".Length));
#else
var version = Version.Parse(splitFramework[1].Substring("Version=v".Length));
Expand All @@ -145,7 +145,7 @@ private static string GetFrameworkName(string? frameworkName)
{
".NETCoreApp" when version.Major < 5 => $"netcoreapp{version.ToString(2)}",
".NETCoreApp" when version.Major >= 5 => $"net{version.ToString(2)}",
#if !NETSTANDARD2_0
#if !NETSTANDARD2_0 && !NET462
".NETFramework" => $"net{version.ToString().Replace(".", string.Empty, StringComparison.OrdinalIgnoreCase)}",
#else
".NETFramework" => $"net{version.ToString().Replace(".", string.Empty)}",
Expand Down
6 changes: 3 additions & 3 deletions src/Grpc.Net.Common/AsyncStreamReaderExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#region Copyright notice and license
#region Copyright notice and license

// Copyright 2019 The gRPC Authors
//
Expand All @@ -16,7 +16,7 @@

#endregion

#if !NETSTANDARD2_0
#if !NETSTANDARD2_0 && !NET462

using System.Collections.Generic;
using System.Runtime.CompilerServices;
Expand Down Expand Up @@ -55,4 +55,4 @@ private static async IAsyncEnumerable<T> ReadAllAsyncCore<T>(IAsyncStreamReader<
}
}

#endif
#endif
10 changes: 5 additions & 5 deletions src/Shared/CompatibilityHelpers.cs
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.

using System.Diagnostics;
Expand All @@ -17,14 +17,14 @@ public static void Assert([DoesNotReturnIf(false)] bool condition, string? messa
public static bool IsCompletedSuccessfully(this Task task)
{
// IsCompletedSuccessfully is the faster method, but only currently exposed on .NET Core 2.0+
#if !NETSTANDARD2_0
#if !NETSTANDARD2_0 && !NET462
return task.IsCompletedSuccessfully;
#else
return task.Status == TaskStatus.RanToCompletion;
#endif
}

#if !NETSTANDARD2_0
#if !NETSTANDARD2_0 && !NET462
public static bool IsCompletedSuccessfully(this ValueTask task)
{
return task.IsCompletedSuccessfully;
Expand All @@ -38,7 +38,7 @@ public static bool IsCompletedSuccessfully<T>(this ValueTask<T> task)

public static int IndexOf(string s, char value, StringComparison comparisonType)
{
#if NETSTANDARD2_0
#if NETSTANDARD2_0 || NET462
return s.IndexOf(value);
#else
return s.IndexOf(value, comparisonType);
Expand Down Expand Up @@ -66,4 +66,4 @@ public static CancellationTokenRegistration RegisterWithCancellationTokenCallbac
return cancellationToken.Register((state) => callback(state, cancellationToken), state);
#endif
}
}
}
6 changes: 4 additions & 2 deletions src/Shared/HttpHandlerFactory.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#region Copyright notice and license
#region Copyright notice and license

// Copyright 2019 The gRPC Authors
//
Expand Down Expand Up @@ -37,7 +37,9 @@ public static HttpMessageHandler CreatePrimaryHandler()
}
#endif

#if !NETSTANDARD2_0
#if NET462
return new WinHttpHandler();
#elif !NETSTANDARD2_0
return new HttpClientHandler();
#else
var message =
Expand Down
4 changes: 2 additions & 2 deletions src/Shared/IsExternalInit.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#region Copyright notice and license
#region Copyright notice and license

// Copyright 2019 The gRPC Authors
//
Expand All @@ -18,7 +18,7 @@

namespace System.Runtime.CompilerServices;

#if NETCOREAPP3_0 || NETSTANDARD2_0_OR_GREATER
#if NETCOREAPP3_0 || NETSTANDARD2_0_OR_GREATER || NET462
internal static class IsExternalInit
{
}
Expand Down
Loading
Loading