Skip to content

Commit c2274eb

Browse files
authored
Add .editorconfig and fix warnings (#2055)
1 parent a456d47 commit c2274eb

File tree

9 files changed

+726
-306
lines changed

9 files changed

+726
-306
lines changed

.editorconfig

+406
Large diffs are not rendered by default.

perf/benchmarkapps/QpsWorker/Infrastructure/TimeStats.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#endregion
1818

1919
using System.Diagnostics;
20+
using System.Globalization;
2021

2122
// Copied from https://github.com/grpc/grpc/tree/master/src/csharp/Grpc.IntegrationTesting
2223
namespace QpsWorker.Infrastructure;
@@ -72,7 +73,7 @@ public Snapshot(TimeSpan wallClockTime, TimeSpan userProcessorTime, TimeSpan pri
7273

7374
public override string ToString()
7475
{
75-
return string.Format("[TimeStats.Snapshot: wallClock {0}, userProcessor {1}, privilegedProcessor {2}]", WallClockTime, UserProcessorTime, PrivilegedProcessorTime);
76+
return string.Format(CultureInfo.InvariantCulture, "[TimeStats.Snapshot: wallClock {0}, userProcessor {1}, privilegedProcessor {2}]", WallClockTime, UserProcessorTime, PrivilegedProcessorTime);
7677
}
7778
}
7879
}

src/Grpc.AspNetCore.Server/Internal/HttpContextStreamWriter.cs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#region Copyright notice and license
1+
#region Copyright notice and license
22

33
// Copyright 2019 The gRPC Authors
44
//
@@ -17,8 +17,6 @@
1717
#endregion
1818

1919
using Grpc.Core;
20-
using Microsoft.AspNetCore.Http;
21-
using Microsoft.Extensions.Logging;
2220

2321
namespace Grpc.AspNetCore.Server.Internal;
2422

src/Grpc.AspNetCore.Server/Internal/PipeExtensions.cs

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#region Copyright notice and license
1+
#region Copyright notice and license
22

33
// Copyright 2019 The gRPC Authors
44
//
@@ -19,9 +19,10 @@
1919
using System.Buffers;
2020
using System.Buffers.Binary;
2121
using System.Diagnostics;
22-
using System.Diagnostics.CodeAnalysis;
2322
using System.IO.Pipelines;
23+
#if NET6_0_OR_GREATER
2424
using System.Runtime.CompilerServices;
25+
#endif
2526
using Grpc.Core;
2627
using Grpc.Net.Compression;
2728
using Microsoft.Extensions.Logging;
@@ -87,7 +88,7 @@ public static async Task WriteStreamedMessageAsync<TResponse>(this PipeWriter pi
8788
var httpResponse = serverCallContext.HttpContext.Response;
8889
if (!httpResponse.HasStarted)
8990
{
90-
await httpResponse.StartAsync();
91+
await httpResponse.StartAsync(cancellationToken);
9192
}
9293

9394
GrpcServerLog.SendingMessage(logger);
@@ -102,7 +103,7 @@ public static async Task WriteStreamedMessageAsync<TResponse>(this PipeWriter pi
102103

103104
if (flush)
104105
{
105-
var flushResult = await pipeWriter.FlushAsync();
106+
var flushResult = await pipeWriter.FlushAsync(cancellationToken);
106107

107108
// Workaround bug where FlushAsync doesn't return IsCanceled = true on request abort.
108109
// https://github.com/dotnet/aspnetcore/issues/40788

src/Grpc.AspNetCore.Server/Internal/ReadOnlySequenceStream.cs

+17-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#region Copyright notice and license
1+
#region Copyright notice and license
22

33
// Copyright 2019 The gRPC Authors
44
//
@@ -62,18 +62,23 @@ public override Task FlushAsync(CancellationToken cancellationToken)
6262
}
6363

6464
public override int Read(byte[] buffer, int offset, int count)
65+
{
66+
return Read(buffer.AsSpan(offset, count));
67+
}
68+
69+
public override int Read(Span<byte> buffer)
6570
{
6671
var remaining = _readOnlySequence.Slice(_position);
67-
var toCopy = remaining.Slice(0, Math.Min(count, remaining.Length));
72+
var toCopy = remaining.Slice(0, Math.Min(buffer.Length, remaining.Length));
6873
_position = toCopy.End;
69-
toCopy.CopyTo(buffer.AsSpan(offset, count));
74+
toCopy.CopyTo(buffer);
7075
return (int)toCopy.Length;
7176
}
7277

7378
public override Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
7479
{
7580
cancellationToken.ThrowIfCancellationRequested();
76-
var bytesRead = Read(buffer, offset, count);
81+
var bytesRead = Read(buffer.AsSpan(offset, count));
7782
if (bytesRead == 0)
7883
{
7984
return TaskOfZero;
@@ -89,6 +94,12 @@ public override Task<int> ReadAsync(byte[] buffer, int offset, int count, Cancel
8994
}
9095
}
9196

97+
public override ValueTask<int> ReadAsync(Memory<byte> buffer, CancellationToken cancellationToken = default)
98+
{
99+
cancellationToken.ThrowIfCancellationRequested();
100+
return new ValueTask<int>(Read(buffer.Span));
101+
}
102+
92103
public override int ReadByte()
93104
{
94105
var remaining = _readOnlySequence.Slice(_position);
@@ -152,6 +163,8 @@ public override long Seek(long offset, SeekOrigin origin)
152163

153164
public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) => throw new NotSupportedException();
154165

166+
public override ValueTask WriteAsync(ReadOnlyMemory<byte> buffer, CancellationToken cancellationToken = default) => throw new NotSupportedException();
167+
155168
public override async Task CopyToAsync(Stream destination, int bufferSize, CancellationToken cancellationToken)
156169
{
157170
foreach (var segment in _readOnlySequence)

src/Grpc.Reflection/SymbolRegistry.cs

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#region Copyright notice and license
1+
#region Copyright notice and license
22
// Copyright 2015 gRPC authors.
33
//
44
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -14,9 +14,8 @@
1414
// limitations under the License.
1515
#endregion
1616

17-
using System.Collections.Generic;
18-
using Grpc.Core.Utils;
1917
using Google.Protobuf.Reflection;
18+
using Grpc.Core.Utils;
2019

2120
namespace Grpc.Reflection;
2221

@@ -71,7 +70,7 @@ public FileDescriptor FileContainingSymbol(string symbol)
7170
/// <summary>
7271
/// Builder class which isn't exposed, but acts as a convenient alternative to passing round two dictionaries in recursive calls.
7372
/// </summary>
74-
private class Builder
73+
private sealed class Builder
7574
{
7675
private readonly Dictionary<string, FileDescriptor> filesByName;
7776
private readonly Dictionary<string, FileDescriptor> filesBySymbol;

0 commit comments

Comments
 (0)