Skip to content

Commit

Permalink
Add .editorconfig and fix warnings (#2055)
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesNK authored Feb 25, 2023
1 parent a456d47 commit c2274eb
Show file tree
Hide file tree
Showing 9 changed files with 726 additions and 306 deletions.
406 changes: 406 additions & 0 deletions .editorconfig

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion perf/benchmarkapps/QpsWorker/Infrastructure/TimeStats.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#endregion

using System.Diagnostics;
using System.Globalization;

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

public override string ToString()
{
return string.Format("[TimeStats.Snapshot: wallClock {0}, userProcessor {1}, privilegedProcessor {2}]", WallClockTime, UserProcessorTime, PrivilegedProcessorTime);
return string.Format(CultureInfo.InvariantCulture, "[TimeStats.Snapshot: wallClock {0}, userProcessor {1}, privilegedProcessor {2}]", WallClockTime, UserProcessorTime, PrivilegedProcessorTime);
}
}
}
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 @@ -17,8 +17,6 @@
#endregion

using Grpc.Core;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;

namespace Grpc.AspNetCore.Server.Internal;

Expand Down
9 changes: 5 additions & 4 deletions src/Grpc.AspNetCore.Server/Internal/PipeExtensions.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 @@ -19,9 +19,10 @@
using System.Buffers;
using System.Buffers.Binary;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.IO.Pipelines;
#if NET6_0_OR_GREATER
using System.Runtime.CompilerServices;
#endif
using Grpc.Core;
using Grpc.Net.Compression;
using Microsoft.Extensions.Logging;
Expand Down Expand Up @@ -87,7 +88,7 @@ public static async Task WriteStreamedMessageAsync<TResponse>(this PipeWriter pi
var httpResponse = serverCallContext.HttpContext.Response;
if (!httpResponse.HasStarted)
{
await httpResponse.StartAsync();
await httpResponse.StartAsync(cancellationToken);
}

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

if (flush)
{
var flushResult = await pipeWriter.FlushAsync();
var flushResult = await pipeWriter.FlushAsync(cancellationToken);

// Workaround bug where FlushAsync doesn't return IsCanceled = true on request abort.
// https://github.com/dotnet/aspnetcore/issues/40788
Expand Down
21 changes: 17 additions & 4 deletions src/Grpc.AspNetCore.Server/Internal/ReadOnlySequenceStream.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 @@ -62,18 +62,23 @@ public override Task FlushAsync(CancellationToken cancellationToken)
}

public override int Read(byte[] buffer, int offset, int count)
{
return Read(buffer.AsSpan(offset, count));
}

public override int Read(Span<byte> buffer)
{
var remaining = _readOnlySequence.Slice(_position);
var toCopy = remaining.Slice(0, Math.Min(count, remaining.Length));
var toCopy = remaining.Slice(0, Math.Min(buffer.Length, remaining.Length));
_position = toCopy.End;
toCopy.CopyTo(buffer.AsSpan(offset, count));
toCopy.CopyTo(buffer);
return (int)toCopy.Length;
}

public override Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
{
cancellationToken.ThrowIfCancellationRequested();
var bytesRead = Read(buffer, offset, count);
var bytesRead = Read(buffer.AsSpan(offset, count));
if (bytesRead == 0)
{
return TaskOfZero;
Expand All @@ -89,6 +94,12 @@ public override Task<int> ReadAsync(byte[] buffer, int offset, int count, Cancel
}
}

public override ValueTask<int> ReadAsync(Memory<byte> buffer, CancellationToken cancellationToken = default)
{
cancellationToken.ThrowIfCancellationRequested();
return new ValueTask<int>(Read(buffer.Span));
}

public override int ReadByte()
{
var remaining = _readOnlySequence.Slice(_position);
Expand Down Expand Up @@ -152,6 +163,8 @@ public override long Seek(long offset, SeekOrigin origin)

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

public override ValueTask WriteAsync(ReadOnlyMemory<byte> buffer, CancellationToken cancellationToken = default) => throw new NotSupportedException();

public override async Task CopyToAsync(Stream destination, int bufferSize, CancellationToken cancellationToken)
{
foreach (var segment in _readOnlySequence)
Expand Down
7 changes: 3 additions & 4 deletions src/Grpc.Reflection/SymbolRegistry.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 2015 gRPC authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -14,9 +14,8 @@
// limitations under the License.
#endregion

using System.Collections.Generic;
using Grpc.Core.Utils;
using Google.Protobuf.Reflection;
using Grpc.Core.Utils;

namespace Grpc.Reflection;

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

0 comments on commit c2274eb

Please sign in to comment.