diff options
author | Jens Geyer <jensg@apache.org> | 2022-01-26 22:38:04 +0100 |
---|---|---|
committer | Jens Geyer <jensg@apache.org> | 2022-01-27 08:55:19 +0100 |
commit | 1ef362cc62a761811294f390e0ead2785e12c9b0 (patch) | |
tree | 4db90e31805ac8285baeb1610349ec4624bc28e4 | |
parent | fb87b440cdba9ba53b0db88296c86a92a3ae2503 (diff) | |
download | thrift-1ef362cc62a761811294f390e0ead2785e12c9b0.tar.gz |
THRIFT-5504 CA2254 Message template should be compile time constant
Client netstd
Patch: Jens Geyer
17 files changed, 62 insertions, 40 deletions
diff --git a/lib/netstd/Thrift/GlobalSuppressions.cs b/lib/netstd/Thrift/GlobalSuppressions.cs new file mode 100644 index 000000000..eb7d3d789 --- /dev/null +++ b/lib/netstd/Thrift/GlobalSuppressions.cs @@ -0,0 +1,31 @@ +// Licensed to the Apache Software Foundation(ASF) under one +// or more contributor license agreements.See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership.The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + + +// This file is used by Code Analysis to maintain SuppressMessage +// attributes that are applied to this project. +// Project-level suppressions either have no target or are given +// a specific target and scoped to a namespace, type, member, etc. + +using System.Diagnostics.CodeAnalysis; + +// suppress certain messages for compatibility reasons with older C# versions we want to support +[assembly: SuppressMessage("Style", "IDE0057", Justification = "compatibility", Scope = "module")] +[assembly: SuppressMessage("Style", "IDE0066", Justification = "compatibility", Scope = "module")] +[assembly: SuppressMessage("Style", "IDE0090", Justification = "compatibility", Scope = "module")] +[assembly: SuppressMessage("Style", "IDE0063", Justification = "compatibility", Scope = "module")] + diff --git a/lib/netstd/Thrift/Processor/ITAsyncProcessor.cs b/lib/netstd/Thrift/Processor/ITAsyncProcessor.cs index f5b8d16e3..0ef683d3c 100644 --- a/lib/netstd/Thrift/Processor/ITAsyncProcessor.cs +++ b/lib/netstd/Thrift/Processor/ITAsyncProcessor.cs @@ -23,6 +23,6 @@ namespace Thrift.Processor { public interface ITAsyncProcessor { - Task<bool> ProcessAsync(TProtocol iprot, TProtocol oprot, CancellationToken cancellationToken = default(CancellationToken)); + Task<bool> ProcessAsync(TProtocol iprot, TProtocol oprot, CancellationToken cancellationToken = default); } } diff --git a/lib/netstd/Thrift/Processor/TMultiplexedProcessor.cs b/lib/netstd/Thrift/Processor/TMultiplexedProcessor.cs index b19221054..9759058b3 100644 --- a/lib/netstd/Thrift/Processor/TMultiplexedProcessor.cs +++ b/lib/netstd/Thrift/Processor/TMultiplexedProcessor.cs @@ -65,8 +65,7 @@ namespace Thrift.Processor // Create a new TMessage, something that can be consumed by any TProtocol var serviceName = message.Name.Substring(0, index); - ITAsyncProcessor actualProcessor; - if (!_serviceProcessorMap.TryGetValue(serviceName, out actualProcessor)) + if (!_serviceProcessorMap.TryGetValue(serviceName, out ITAsyncProcessor actualProcessor)) { await FailAsync(oprot, message, TApplicationException.ExceptionType.InternalError, $"Service name not found: {serviceName}. Did you forget to call RegisterProcessor()?", @@ -103,7 +102,7 @@ namespace Thrift.Processor _serviceProcessorMap.Add(serviceName, processor); } - private async Task FailAsync(TProtocol oprot, TMessage message, TApplicationException.ExceptionType extype, + private static async Task FailAsync(TProtocol oprot, TMessage message, TApplicationException.ExceptionType extype, string etxt, CancellationToken cancellationToken) { var appex = new TApplicationException(extype, etxt); diff --git a/lib/netstd/Thrift/Protocol/TBinaryProtocol.cs b/lib/netstd/Thrift/Protocol/TBinaryProtocol.cs index 9c2346919..eee137ca1 100644 --- a/lib/netstd/Thrift/Protocol/TBinaryProtocol.cs +++ b/lib/netstd/Thrift/Protocol/TBinaryProtocol.cs @@ -23,8 +23,6 @@ using System.Threading.Tasks; using Thrift.Protocol.Entities; using Thrift.Transport; -#pragma warning disable IDE0079 // unnecessary suppression -#pragma warning disable IDE0066 // use switch expression namespace Thrift.Protocol { diff --git a/lib/netstd/Thrift/Protocol/TCompactProtocol.cs b/lib/netstd/Thrift/Protocol/TCompactProtocol.cs index 3758174cc..6893ad476 100644 --- a/lib/netstd/Thrift/Protocol/TCompactProtocol.cs +++ b/lib/netstd/Thrift/Protocol/TCompactProtocol.cs @@ -26,8 +26,6 @@ using System.Threading.Tasks; using Thrift.Protocol.Entities; using Thrift.Transport; -#pragma warning disable IDE0079 // unnecessary suppression -#pragma warning disable IDE0066 // use switch expression namespace Thrift.Protocol { diff --git a/lib/netstd/Thrift/Protocol/TJSONProtocol.cs b/lib/netstd/Thrift/Protocol/TJSONProtocol.cs index 081f42e96..8799026ba 100644 --- a/lib/netstd/Thrift/Protocol/TJSONProtocol.cs +++ b/lib/netstd/Thrift/Protocol/TJSONProtocol.cs @@ -27,9 +27,6 @@ using Thrift.Protocol.Entities; using Thrift.Protocol.Utilities; using Thrift.Transport; -#pragma warning disable IDE0079 // unnecessary suppression -#pragma warning disable IDE0063 // simplify using -#pragma warning disable IDE0066 // use switch expression namespace Thrift.Protocol { diff --git a/lib/netstd/Thrift/Protocol/TProtocol.cs b/lib/netstd/Thrift/Protocol/TProtocol.cs index 5b1bec16b..cd9383389 100644 --- a/lib/netstd/Thrift/Protocol/TProtocol.cs +++ b/lib/netstd/Thrift/Protocol/TProtocol.cs @@ -50,6 +50,7 @@ namespace Thrift.Protocol public void Dispose() { Dispose(true); + GC.SuppressFinalize(this); } public void IncrementRecursionDepth() diff --git a/lib/netstd/Thrift/Protocol/ToString.cs b/lib/netstd/Thrift/Protocol/ToString.cs index 14fa5204f..50dd6df6d 100644 --- a/lib/netstd/Thrift/Protocol/ToString.cs +++ b/lib/netstd/Thrift/Protocol/ToString.cs @@ -47,15 +47,15 @@ namespace Thrift.Protocol if (first_child) first_child = false; else - sb.Append(","); + sb.Append(','); sb.Append("{ "); pair.Key.ToString(sb); sb.Append(", "); pair.Value.ToString(sb); - sb.Append("}"); + sb.Append('}'); } - sb.Append("}"); + sb.Append('}'); } else if (self is IEnumerable) { @@ -65,7 +65,7 @@ namespace Thrift.Protocol elm.ToString(sb, first_child); first_child = false; } - sb.Append("}"); + sb.Append('}'); } else if (self is TBase) { diff --git a/lib/netstd/Thrift/Server/TServer.cs b/lib/netstd/Thrift/Server/TServer.cs index 3fd0bc531..3d4f3fc20 100644 --- a/lib/netstd/Thrift/Server/TServer.cs +++ b/lib/netstd/Thrift/Server/TServer.cs @@ -35,7 +35,7 @@ namespace Thrift.Server protected TProtocolFactory OutputProtocolFactory; protected TTransportFactory OutputTransportFactory; - protected TServerEventHandler ServerEventHandler; + protected ITServerEventHandler ServerEventHandler; protected TServerTransport ServerTransport; protected TServer(ITProcessorFactory processorFactory, TServerTransport serverTransport, @@ -52,12 +52,12 @@ namespace Thrift.Server Logger = logger; // null is absolutely legal } - public void SetEventHandler(TServerEventHandler seh) + public void SetEventHandler(ITServerEventHandler seh) { ServerEventHandler = seh; } - public TServerEventHandler GetEventHandler() + public ITServerEventHandler GetEventHandler() { return ServerEventHandler; } @@ -66,7 +66,7 @@ namespace Thrift.Server protected void LogError( string msg) { if (Logger != null) - Logger.LogError(msg); + Logger.LogError("{Msg}",msg); // NOTE: Log message template, not string interpolation! } public abstract void Stop(); diff --git a/lib/netstd/Thrift/Server/TServerEventHandler.cs b/lib/netstd/Thrift/Server/TServerEventHandler.cs index 69314efd6..9226b42a1 100644 --- a/lib/netstd/Thrift/Server/TServerEventHandler.cs +++ b/lib/netstd/Thrift/Server/TServerEventHandler.cs @@ -25,10 +25,18 @@ namespace Thrift.Server //TODO: replacement by event? /// <summary> - /// Interface implemented by server users to handle events from the server + /// Interface implemented by server users to handle events from the server /// </summary> + /// <remarks>Replaced by ITServerEventHandler</remarks> // ReSharper disable once InconsistentNaming - public interface TServerEventHandler + #pragma warning disable IDE1006 + public interface TServerEventHandler : ITServerEventHandler { } + #pragma warning restore IDE1006 + + /// <summary> + /// Interface implemented by server users to handle events from the server + /// </summary> + public interface ITServerEventHandler { /// <summary> /// Called before the server begins */ diff --git a/lib/netstd/Thrift/Server/TSimpleAsyncServer.cs b/lib/netstd/Thrift/Server/TSimpleAsyncServer.cs index d46d58a75..f1f6277d5 100644 --- a/lib/netstd/Thrift/Server/TSimpleAsyncServer.cs +++ b/lib/netstd/Thrift/Server/TSimpleAsyncServer.cs @@ -23,8 +23,6 @@ using Thrift.Processor; using System.Threading.Tasks; using Microsoft.Extensions.Logging; -#pragma warning disable IDE0079 // remove unnecessary pragmas -#pragma warning disable IDE0063 // using can be simplified, we don't namespace Thrift.Server { diff --git a/lib/netstd/Thrift/Server/TThreadPoolAsyncServer.cs b/lib/netstd/Thrift/Server/TThreadPoolAsyncServer.cs index ba1834cde..efa1698da 100644 --- a/lib/netstd/Thrift/Server/TThreadPoolAsyncServer.cs +++ b/lib/netstd/Thrift/Server/TThreadPoolAsyncServer.cs @@ -29,8 +29,6 @@ using Thrift.Processor; using System.Threading.Tasks; using Microsoft.Extensions.Logging; -#pragma warning disable IDE0079 // remove unnecessary pragmas -#pragma warning disable IDE0063 // using can be simplified, we don't namespace Thrift.Server { diff --git a/lib/netstd/Thrift/Transport/Client/THttpTransport.cs b/lib/netstd/Thrift/Transport/Client/THttpTransport.cs index 4ca439e4f..60ed59c67 100644 --- a/lib/netstd/Thrift/Transport/Client/THttpTransport.cs +++ b/lib/netstd/Thrift/Transport/Client/THttpTransport.cs @@ -25,8 +25,6 @@ using System.Security.Cryptography.X509Certificates; using System.Threading; using System.Threading.Tasks; -#pragma warning disable IDE0079 // unnecessary suppression -#pragma warning disable IDE0063 // simplify using namespace Thrift.Transport.Client { diff --git a/lib/netstd/Thrift/Transport/Client/TMemoryBufferTransport.cs b/lib/netstd/Thrift/Transport/Client/TMemoryBufferTransport.cs index a666c7c97..5773d30cb 100644 --- a/lib/netstd/Thrift/Transport/Client/TMemoryBufferTransport.cs +++ b/lib/netstd/Thrift/Transport/Client/TMemoryBufferTransport.cs @@ -21,8 +21,6 @@ using System.IO; using System.Threading; using System.Threading.Tasks; -#pragma warning disable IDE0079 // unused suppression -#pragma warning disable IDE0066 // requires C# 8 namespace Thrift.Transport.Client { diff --git a/lib/netstd/Thrift/Transport/Layered/TBufferedTransport.cs b/lib/netstd/Thrift/Transport/Layered/TBufferedTransport.cs index dee52ddb1..271a9946c 100644 --- a/lib/netstd/Thrift/Transport/Layered/TBufferedTransport.cs +++ b/lib/netstd/Thrift/Transport/Layered/TBufferedTransport.cs @@ -110,8 +110,7 @@ namespace Thrift.Transport // buffer a new chunk of bytes from the underlying transport ReadBuffer.Length = ReadBuffer.Capacity; - ArraySegment<byte> bufSegment; - ReadBuffer.TryGetBuffer(out bufSegment); + ReadBuffer.TryGetBuffer(out ArraySegment<byte> bufSegment); ReadBuffer.Length = await InnerTransport.ReadAsync(bufSegment.Array, 0, bufSegment.Count, cancellationToken); ReadBuffer.Position = 0; @@ -134,8 +133,7 @@ namespace Thrift.Transport var free = WriteBuffer.Capacity - WriteBuffer.Length; if (length > free) { - ArraySegment<byte> bufSegment; - WriteBuffer.TryGetBuffer(out bufSegment); + WriteBuffer.TryGetBuffer(out ArraySegment<byte> bufSegment); await InnerTransport.WriteAsync(bufSegment.Array, 0, bufSegment.Count, cancellationToken); WriteBuffer.SetLength(0); } @@ -163,8 +161,7 @@ namespace Thrift.Transport if (WriteBuffer.Length > 0) { - ArraySegment<byte> bufSegment; - WriteBuffer.TryGetBuffer(out bufSegment); + WriteBuffer.TryGetBuffer(out ArraySegment<byte> bufSegment); await InnerTransport.WriteAsync(bufSegment.Array, 0, bufSegment.Count, cancellationToken); WriteBuffer.SetLength(0); } diff --git a/lib/netstd/Thrift/Transport/Layered/TFramedTransport.cs b/lib/netstd/Thrift/Transport/Layered/TFramedTransport.cs index f56098601..722df7672 100644 --- a/lib/netstd/Thrift/Transport/Layered/TFramedTransport.cs +++ b/lib/netstd/Thrift/Transport/Layered/TFramedTransport.cs @@ -97,8 +97,7 @@ namespace Thrift.Transport ReadBuffer.SetLength(size); ReadBuffer.Seek(0, SeekOrigin.Begin); - ArraySegment<byte> bufSegment; - ReadBuffer.TryGetBuffer(out bufSegment); + ReadBuffer.TryGetBuffer(out ArraySegment<byte> bufSegment); await InnerTransport.ReadAllAsync(bufSegment.Array, 0, size, cancellationToken); } @@ -129,8 +128,7 @@ namespace Thrift.Transport throw new TTransportException(TTransportException.ExceptionType.NotOpen); } - ArraySegment<byte> bufSegment; - WriteBuffer.TryGetBuffer(out bufSegment); + WriteBuffer.TryGetBuffer(out ArraySegment<byte> bufSegment); int dataLen = bufSegment.Count - HeaderSize; if (dataLen < 0) diff --git a/lib/netstd/Thrift/Transport/Server/TServerSocketTransport.cs b/lib/netstd/Thrift/Transport/Server/TServerSocketTransport.cs index d7421c944..3a4fed468 100644 --- a/lib/netstd/Thrift/Transport/Server/TServerSocketTransport.cs +++ b/lib/netstd/Thrift/Transport/Server/TServerSocketTransport.cs @@ -113,8 +113,11 @@ namespace Thrift.Transport.Server try { TTransport tSocketTransport = null; + #if NET6_0_OR_GREATER + var tcpClient = await _server.AcceptTcpClientAsync(cancellationToken); + #else var tcpClient = await _server.AcceptTcpClientAsync(); - + #endif try { tSocketTransport = new TSocketTransport(tcpClient, Configuration) |