From 9fa9388c59f7b7583ee2cc86e46e02f02a7de895 Mon Sep 17 00:00:00 2001 From: Lawrence LCI Date: Tue, 21 Sep 2021 18:44:24 -0700 Subject: [PATCH 1/3] Update reference to the merged TimeoutTimer.cs --- .../src/Microsoft.Data.SqlClient.csproj | 2 +- .../netfx/src/Microsoft.Data.SqlClient.csproj | 8 +- .../Data/ProviderBase/TimeoutTimer.cs | 187 ------------------ .../Data/ProviderBase/TimeoutTimer.cs | 0 4 files changed, 6 insertions(+), 191 deletions(-) delete mode 100644 src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/ProviderBase/TimeoutTimer.cs rename src/Microsoft.Data.SqlClient/{netcore/src/Common => }/src/Microsoft/Data/ProviderBase/TimeoutTimer.cs (100%) diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj index d918134b15..dd55e7f0cf 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj @@ -444,7 +444,7 @@ Common\Microsoft\Data\ProviderBase\DbConnectionPoolGroup.cs - + Common\Microsoft\Data\ProviderBase\TimeoutTimer.cs diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj index f54e7630c6..12a72a21f1 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj +++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj @@ -89,6 +89,9 @@ + + Microsoft\Data\ProviderBase\TimeoutTimer.cs + Microsoft\Data\SqlClient\LocalAppContextSwitches.cs @@ -430,7 +433,7 @@ - + @@ -527,7 +530,6 @@ - @@ -621,4 +623,4 @@ - + \ No newline at end of file diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/ProviderBase/TimeoutTimer.cs b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/ProviderBase/TimeoutTimer.cs deleted file mode 100644 index 73b6656dd5..0000000000 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/ProviderBase/TimeoutTimer.cs +++ /dev/null @@ -1,187 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -namespace Microsoft.Data.ProviderBase -{ - using System; - using System.Diagnostics; - using Microsoft.Data.Common; - - // Purpose: - // Manages determining and tracking timeouts - // - // Intended use: - // Call StartXXXXTimeout() to get a timer with the given expiration point - // Get remaining time in appropriate format to pass to subsystem timeouts - // Check for timeout via IsExpired for checks in managed code. - // Simply abandon to GC when done. - internal class TimeoutTimer - { - //------------------- - // Fields - //------------------- - private long _timerExpire; - private bool _isInfiniteTimeout; - private long _originalTimerTicks; - - //------------------- - // Timeout-setting methods - //------------------- - - // Get a new timer that will expire in the given number of seconds - // For input, a value of zero seconds indicates infinite timeout - internal static TimeoutTimer StartSecondsTimeout(int seconds) - { - //-------------------- - // Preconditions: None (seconds must conform to SetTimeoutSeconds requirements) - - //-------------------- - // Method body - var timeout = new TimeoutTimer(); - timeout.SetTimeoutSeconds(seconds); - - //--------------------- - // Postconditions - Debug.Assert(timeout != null); // Need a valid timeouttimer if no error - - return timeout; - } - - // Get a new timer that will expire in the given number of milliseconds - // No current need to support infinite milliseconds timeout - internal static TimeoutTimer StartMillisecondsTimeout(long milliseconds) - { - //-------------------- - // Preconditions - Debug.Assert(0 <= milliseconds); - - //-------------------- - // Method body - var timeout = new TimeoutTimer(); - timeout._originalTimerTicks = milliseconds * TimeSpan.TicksPerMillisecond; - timeout._timerExpire = checked(ADP.TimerCurrent() + timeout._originalTimerTicks); - timeout._isInfiniteTimeout = false; - - //--------------------- - // Postconditions - Debug.Assert(timeout != null); // Need a valid timeouttimer if no error - - return timeout; - } - - //------------------- - // Methods for changing timeout - //------------------- - - internal void SetTimeoutSeconds(int seconds) - { - //-------------------- - // Preconditions - Debug.Assert(0 <= seconds || InfiniteTimeout == seconds); // no need to support negative seconds at present - - //-------------------- - // Method body - if (InfiniteTimeout == seconds) - { - _isInfiniteTimeout = true; - } - else - { - // Stash current time + timeout - _originalTimerTicks = ADP.TimerFromSeconds(seconds); - _timerExpire = checked(ADP.TimerCurrent() + _originalTimerTicks); - _isInfiniteTimeout = false; - } - - //--------------------- - // Postconditions:None - } - - // Reset timer to original duration. - internal void Reset() - { - if (InfiniteTimeout == _originalTimerTicks) - { - _isInfiniteTimeout = true; - } - else - { - _timerExpire = checked(ADP.TimerCurrent() + _originalTimerTicks); - _isInfiniteTimeout = false; - } - } - - //------------------- - // Timeout info properties - //------------------- - - // Indicator for infinite timeout when starting a timer - internal static readonly long InfiniteTimeout = 0; - - // Is this timer in an expired state? - internal bool IsExpired - { - get - { - return !IsInfinite && ADP.TimerHasExpired(_timerExpire); - } - } - - // is this an infinite-timeout timer? - internal bool IsInfinite - { - get - { - return _isInfiniteTimeout; - } - } - - // Special accessor for TimerExpire for use when thunking to legacy timeout methods. - internal long LegacyTimerExpire - { - get - { - return (_isInfiniteTimeout) ? Int64.MaxValue : _timerExpire; - } - } - - // Returns milliseconds remaining trimmed to zero for none remaining - // and long.MaxValue for infinite - // This method should be prefered for internal calculations that are not - // yet common enough to code into the TimeoutTimer class itself. - internal long MillisecondsRemaining - { - get - { - //------------------- - // Preconditions: None - - //------------------- - // Method Body - long milliseconds; - if (_isInfiniteTimeout) - { - milliseconds = long.MaxValue; - } - else - { - milliseconds = ADP.TimerRemainingMilliseconds(_timerExpire); - if (0 > milliseconds) - { - milliseconds = 0; - } - } - - //-------------------- - // Postconditions - Debug.Assert(0 <= milliseconds); // This property guarantees no negative return values - - return milliseconds; - } - } - - } - -} - diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Microsoft/Data/ProviderBase/TimeoutTimer.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/TimeoutTimer.cs similarity index 100% rename from src/Microsoft.Data.SqlClient/netcore/src/Common/src/Microsoft/Data/ProviderBase/TimeoutTimer.cs rename to src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/TimeoutTimer.cs From 0cb1245d607e8f926b13e04107442400fd72a052 Mon Sep 17 00:00:00 2001 From: Lawrence LCI Date: Wed, 22 Sep 2021 13:41:17 -0700 Subject: [PATCH 2/3] Move the compile link of TimeoutToken to the correct section in the csproj --- .../netcore/src/Microsoft.Data.SqlClient.csproj | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj index dd55e7f0cf..d9aa431e32 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj @@ -76,6 +76,9 @@ Microsoft\Data\ProviderBase\FieldNameLookup.cs + + Microsoft\Data\ProviderBase\TimeoutTimer.cs + Microsoft\Data\SqlClient\ActiveDirectoryAuthenticationTimeoutRetryHelper.cs @@ -444,9 +447,6 @@ Common\Microsoft\Data\ProviderBase\DbConnectionPoolGroup.cs - - Common\Microsoft\Data\ProviderBase\TimeoutTimer.cs - Common\Microsoft\Data\ProviderBase\DbReferenceCollection.cs From cc4d01c3adf4d0b25c58eb64a62e026d8b24cf12 Mon Sep 17 00:00:00 2001 From: Lawrence LCI Date: Wed, 22 Sep 2021 13:56:15 -0700 Subject: [PATCH 3/3] Move the compile link of TimeoutTimer to the correct section with the rest of the ProviderBase in the netfx csproj --- .../netfx/src/Microsoft.Data.SqlClient.csproj | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj index 12a72a21f1..0592b9c239 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj +++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj @@ -89,9 +89,6 @@ - - Microsoft\Data\ProviderBase\TimeoutTimer.cs - Microsoft\Data\SqlClient\LocalAppContextSwitches.cs @@ -137,6 +134,9 @@ Microsoft\Data\ProviderBase\FieldNameLookup.cs + + Microsoft\Data\ProviderBase\TimeoutTimer.cs + Microsoft\Data\SqlClient\ActiveDirectoryAuthenticationTimeoutRetryHelper.cs @@ -623,4 +623,4 @@ - \ No newline at end of file +