diff --git a/.github/workflows/publish-beta.yml b/.github/workflows/publish-beta.yml index 5977508..2f48959 100644 --- a/.github/workflows/publish-beta.yml +++ b/.github/workflows/publish-beta.yml @@ -14,9 +14,9 @@ jobs: steps: - uses: actions/checkout@v3 - name: Setup .NET - uses: actions/setup-dotnet@v2 + uses: actions/setup-dotnet@v3 with: - dotnet-version: 6.0.x + dotnet-version: 7.0.x - name: Restore run: | dotnet restore NewLife.Thrift/NewLife.Thrift.csproj diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 66f0007..5bdde25 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -13,9 +13,9 @@ jobs: steps: - uses: actions/checkout@v3 - name: Setup .NET - uses: actions/setup-dotnet@v2 + uses: actions/setup-dotnet@v3 with: - dotnet-version: 6.0.x + dotnet-version: 7.0.x - name: Restore run: | dotnet restore NewLife.Thrift/NewLife.Thrift.csproj diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 781ca98..b0ed1df 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -15,9 +15,9 @@ jobs: steps: - uses: actions/checkout@v3 - name: Setup .NET - uses: actions/setup-dotnet@v2 + uses: actions/setup-dotnet@v3 with: - dotnet-version: 6.0.x + dotnet-version: 7.0.x - name: Build run: dotnet build -c Release - name: Test diff --git a/NewLife.Thrift/NewLife.Thrift.csproj b/NewLife.Thrift/NewLife.Thrift.csproj index a464567..504c349 100644 --- a/NewLife.Thrift/NewLife.Thrift.csproj +++ b/NewLife.Thrift/NewLife.Thrift.csproj @@ -4,8 +4,8 @@ Thrift序列化 Thrift序列化支持库 新生命开发团队 - ©2002-2022 新生命开发团队 - 1.0 + ©2002-2023 新生命开发团队 + 1.1 $([System.DateTime]::Now.ToString(`yyyy.MMdd`)) $(VersionPrefix).$(VersionSuffix) $(Version) @@ -40,12 +40,12 @@ - - + + - - + + diff --git a/NewLife.Thrift/Server/TSimpleServer.cs b/NewLife.Thrift/Server/TSimpleServer.cs index ca245aa..05dc61e 100644 --- a/NewLife.Thrift/Server/TSimpleServer.cs +++ b/NewLife.Thrift/Server/TSimpleServer.cs @@ -78,8 +78,7 @@ public override void Serve() } //Fire the preServe server event when server is up but before any client connections - if (serverEventHandler != null) - serverEventHandler.preServe(); + serverEventHandler?.preServe(); while (!stop) { @@ -118,8 +117,7 @@ public override void Serve() //N.B. This is the pattern implemented in C++ and the event fires provisionally. //That is to say it may be many minutes between the event firing and the client request //actually arriving or the client may hang up without ever makeing a request. - if (serverEventHandler != null) - serverEventHandler.processContext(connectionContext, inputTransport); + serverEventHandler?.processContext(connectionContext, inputTransport); //Process client request (blocks until transport is readable) if (!processor.Process(inputProtocol, outputProtocol)) break; @@ -143,8 +141,7 @@ public override void Serve() } //Fire deleteContext server event after client disconnects - if (serverEventHandler != null) - serverEventHandler.deleteContext(connectionContext, inputProtocol, outputProtocol); + serverEventHandler?.deleteContext(connectionContext, inputProtocol, outputProtocol); } } diff --git a/NewLife.Thrift/Server/TThreadPoolServer.cs b/NewLife.Thrift/Server/TThreadPoolServer.cs index 8796a2e..e099700 100644 --- a/NewLife.Thrift/Server/TThreadPoolServer.cs +++ b/NewLife.Thrift/Server/TThreadPoolServer.cs @@ -144,8 +144,7 @@ public override void Serve() } //Fire the preServe server event when server is up but before any client connections - if (serverEventHandler != null) - serverEventHandler.preServe(); + serverEventHandler?.preServe(); while (!stop) { @@ -218,8 +217,7 @@ private void Execute(Object threadContext) //N.B. This is the pattern implemented in C++ and the event fires provisionally. //That is to say it may be many minutes between the event firing and the client request //actually arriving or the client may hang up without ever makeing a request. - if (serverEventHandler != null) - serverEventHandler.processContext(connectionContext, inputTransport); + serverEventHandler?.processContext(connectionContext, inputTransport); //Process client request (blocks until transport is readable) if (!processor.Process(inputProtocol, outputProtocol)) break; @@ -236,27 +234,20 @@ private void Execute(Object threadContext) } //Fire deleteContext server event after client disconnects - if (serverEventHandler != null) - serverEventHandler.deleteContext(connectionContext, inputProtocol, outputProtocol); + serverEventHandler?.deleteContext(connectionContext, inputProtocol, outputProtocol); } finally { //Close transports - if (inputTransport != null) - inputTransport.Close(); - if (outputTransport != null) - outputTransport.Close(); + inputTransport?.Close(); + outputTransport?.Close(); // disposable stuff should be disposed - if (inputProtocol != null) - inputProtocol.Dispose(); - if (outputProtocol != null) - outputProtocol.Dispose(); - if (inputTransport != null) - inputTransport.Dispose(); - if (outputTransport != null) - outputTransport.Dispose(); + inputProtocol?.Dispose(); + outputProtocol?.Dispose(); + inputTransport?.Dispose(); + outputTransport?.Dispose(); } } } diff --git a/NewLife.Thrift/Server/TThreadedServer.cs b/NewLife.Thrift/Server/TThreadedServer.cs index b06264c..1ba1cfe 100644 --- a/NewLife.Thrift/Server/TThreadedServer.cs +++ b/NewLife.Thrift/Server/TThreadedServer.cs @@ -96,8 +96,7 @@ public override void Serve() } //Fire the preServe server event when server is up but before any client connections - if (serverEventHandler != null) - serverEventHandler.preServe(); + serverEventHandler?.preServe(); while (!stop) { @@ -200,8 +199,7 @@ private void ClientWorker(Object context) //N.B. This is the pattern implemented in C++ and the event fires provisionally. //That is to say it may be many minutes between the event firing and the client request //actually arriving or the client may hang up without ever makeing a request. - if (serverEventHandler != null) - serverEventHandler.processContext(connectionContext, inputTransport); + serverEventHandler?.processContext(connectionContext, inputTransport); //Process client request (blocks until transport is readable) if (!processor.Process(inputProtocol, outputProtocol)) break; @@ -218,8 +216,7 @@ private void ClientWorker(Object context) } //Fire deleteContext server event after client disconnects - if (serverEventHandler != null) - serverEventHandler.deleteContext(connectionContext, inputProtocol, outputProtocol); + serverEventHandler?.deleteContext(connectionContext, inputProtocol, outputProtocol); lock (clientLock) { @@ -231,16 +228,12 @@ private void ClientWorker(Object context) finally { //Close transports - if (inputTransport != null) - inputTransport.Close(); - if (outputTransport != null) - outputTransport.Close(); + inputTransport?.Close(); + outputTransport?.Close(); // disposable stuff should be disposed - if (inputProtocol != null) - inputProtocol.Dispose(); - if (outputProtocol != null) - outputProtocol.Dispose(); + inputProtocol?.Dispose(); + outputProtocol?.Dispose(); } } } diff --git a/NewLife.Thrift/Transport/TBufferedTransport.cs b/NewLife.Thrift/Transport/TBufferedTransport.cs index 7bdd7fd..066a271 100644 --- a/NewLife.Thrift/Transport/TBufferedTransport.cs +++ b/NewLife.Thrift/Transport/TBufferedTransport.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.IO; namespace NewLife.Thrift.Transport @@ -143,25 +143,23 @@ protected void CheckNotDisposed() throw new ObjectDisposedException("TBufferedTransport"); } - #region + #region 销毁 protected Boolean _IsDisposed { get; private set; } - /// + /// 销毁 protected override void Dispose(Boolean disposing) { - if (!_IsDisposed) + base.Dispose(disposing); + + if (_IsDisposed) return; + _IsDisposed = true; + + if (disposing) { - if (disposing) - { - if (inputBuffer != null) - inputBuffer.Dispose(); - if (outputBuffer != null) - outputBuffer.Dispose(); - if (transport != null) - transport.Dispose(); - } + inputBuffer?.Dispose(); + outputBuffer?.Dispose(); + transport?.Dispose(); } - _IsDisposed = true; } #endregion } diff --git a/NewLife.Thrift/Transport/TFramedTransport.cs b/NewLife.Thrift/Transport/TFramedTransport.cs index 68cf029..2634606 100644 --- a/NewLife.Thrift/Transport/TFramedTransport.cs +++ b/NewLife.Thrift/Transport/TFramedTransport.cs @@ -155,19 +155,17 @@ private void CheckNotDisposed() /// protected override void Dispose(Boolean disposing) { - if (!_IsDisposed) + base.Dispose(disposing); + + if (_IsDisposed) return; + _IsDisposed = true; + + if (disposing) { - if (disposing) - { - if (readBuffer != null) - readBuffer.Dispose(); - if (writeBuffer != null) - writeBuffer.Dispose(); - if (transport != null) - transport.Dispose(); - } + readBuffer?.Dispose(); + writeBuffer?.Dispose(); + transport?.Dispose(); } - _IsDisposed = true; } #endregion } diff --git a/NewLife.Thrift/Transport/THttpClient.cs b/NewLife.Thrift/Transport/THttpClient.cs index cefc880..2b577bf 100644 --- a/NewLife.Thrift/Transport/THttpClient.cs +++ b/NewLife.Thrift/Transport/THttpClient.cs @@ -372,10 +372,7 @@ internal void UpdateStatusToComplete() _isCompleted = true; //1. set _iscompleted to true lock (_locker) { - if (_evt != null) - { - _evt.Set(); //2. set the event, when it exists - } + _evt?.Set(); //2. set the event, when it exists } } @@ -394,17 +391,16 @@ internal void NotifyCallbackWhenAvailable() // IDisposable protected override void Dispose(Boolean disposing) { - if (!_IsDisposed) + base.Dispose(disposing); + + if (_IsDisposed) return; + _IsDisposed = true; + + if (disposing) { - if (disposing) - { - if (inputStream != null) - inputStream.Dispose(); - if (outputStream != null) - outputStream.Dispose(); - } + inputStream?.Dispose(); + outputStream?.Dispose(); } - _IsDisposed = true; } #endregion } diff --git a/NewLife.Thrift/Transport/TMemoryBuffer.cs b/NewLife.Thrift/Transport/TMemoryBuffer.cs index dc13e18..a06b4be 100644 --- a/NewLife.Thrift/Transport/TMemoryBuffer.cs +++ b/NewLife.Thrift/Transport/TMemoryBuffer.cs @@ -81,15 +81,15 @@ public static T DeSerialize(Byte[] buf) where T : TAbstractBase /// 销毁 protected override void Dispose(Boolean disposing) { - if (!_IsDisposed) + base.Dispose(disposing); + + if (_IsDisposed) return; + _IsDisposed = true; + + if (disposing) { - if (disposing) - { - if (byteStream != null) - byteStream.Dispose(); - } + byteStream?.Dispose(); } - _IsDisposed = true; } } } diff --git a/NewLife.Thrift/Transport/TNamedPipeClientTransport.cs b/NewLife.Thrift/Transport/TNamedPipeClientTransport.cs index 6771e6b..b98c8c1 100644 --- a/NewLife.Thrift/Transport/TNamedPipeClientTransport.cs +++ b/NewLife.Thrift/Transport/TNamedPipeClientTransport.cs @@ -82,7 +82,9 @@ public override void Write(Byte[] buf, Int32 off, Int32 len) protected override void Dispose(Boolean disposing) { - client.Dispose(); + base.Dispose(disposing); + + client?.Dispose(); } } } diff --git a/NewLife.Thrift/Transport/TNamedPipeServerTransport.cs b/NewLife.Thrift/Transport/TNamedPipeServerTransport.cs index dd0f863..bc5dd13 100644 --- a/NewLife.Thrift/Transport/TNamedPipeServerTransport.cs +++ b/NewLife.Thrift/Transport/TNamedPipeServerTransport.cs @@ -159,8 +159,7 @@ public override void Open() public override void Close() { - if (stream != null) - stream.Close(); + stream?.Close(); } public override Int32 Read(Byte[] buf, Int32 off, Int32 len) @@ -264,8 +263,9 @@ public override void Write(Byte[] buf, Int32 off, Int32 len) protected override void Dispose(Boolean disposing) { - if (stream != null) - stream.Dispose(); + base.Dispose(disposing); + + stream?.Dispose(); } } } diff --git a/NewLife.Thrift/Transport/TSocket.cs b/NewLife.Thrift/Transport/TSocket.cs index 1090a62..fdf1e0b 100644 --- a/NewLife.Thrift/Transport/TSocket.cs +++ b/NewLife.Thrift/Transport/TSocket.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Net.Sockets; namespace NewLife.Thrift.Transport @@ -176,22 +176,23 @@ public override void Close() } } - #region + #region 销毁 private Boolean _IsDisposed; - /// + /// 销毁 protected override void Dispose(Boolean disposing) { - if (!_IsDisposed) + base.Dispose(disposing); + + if (_IsDisposed) return; + _IsDisposed = true; + + if (disposing) { - if (disposing) - { - if (TcpClient != null) - ((IDisposable)TcpClient).Dispose(); - base.Dispose(disposing); - } + if (TcpClient != null) + ((IDisposable)TcpClient).Dispose(); + base.Dispose(disposing); } - _IsDisposed = true; } #endregion } diff --git a/NewLife.Thrift/Transport/TStreamTransport.cs b/NewLife.Thrift/Transport/TStreamTransport.cs index ca9a90a..2bc53a9 100644 --- a/NewLife.Thrift/Transport/TStreamTransport.cs +++ b/NewLife.Thrift/Transport/TStreamTransport.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.IO; namespace NewLife.Thrift.Transport @@ -73,23 +73,22 @@ public override void Flush() } - #region + #region 销毁 private Boolean _IsDisposed; - /// + /// 销毁 protected override void Dispose(Boolean disposing) { - if (!_IsDisposed) + base.Dispose(disposing); + + if (_IsDisposed) return; + _IsDisposed = true; + + if (disposing) { - if (disposing) - { - if (InputStream != null) - InputStream.Dispose(); - if (OutputStream != null) - OutputStream.Dispose(); - } + InputStream?.Dispose(); + OutputStream?.Dispose(); } - _IsDisposed = true; } #endregion }