@@ -24,10 +24,7 @@ sealed internal class LastIOTimer
2424
2525 sealed internal class TdsParserStateObject
2626 {
27- private const int TimeoutStopped = 0 ;
28- private const int TimeoutRunning = 1 ;
29- private const int TimeoutExpiredAsync = 2 ;
30- private const int TimeoutExpiredSync = 3 ;
27+
3128
3229 private const int AttentionTimeoutSeconds = 5 ;
3330
@@ -40,6 +37,11 @@ sealed internal class TdsParserStateObject
4037
4138 private sealed class TimeoutState
4239 {
40+ public const int Stopped = 0 ;
41+ public const int Running = 1 ;
42+ public const int ExpiredAsync = 2 ;
43+ public const int ExpiredSync = 3 ;
44+
4345 private readonly int _value ;
4446
4547 public TimeoutState ( int value )
@@ -2356,7 +2358,7 @@ internal void OnConnectionClosed()
23562358
23572359 public void SetTimeoutStateStopped ( )
23582360 {
2359- Interlocked . Exchange ( ref _timeoutState , TimeoutStopped ) ;
2361+ Interlocked . Exchange ( ref _timeoutState , TimeoutState . Stopped ) ;
23602362 _timeoutIdentityValue = 0 ;
23612363 }
23622364
@@ -2365,7 +2367,7 @@ public bool IsTimeoutStateExpired
23652367 get
23662368 {
23672369 int state = _timeoutState ;
2368- return state == TimeoutExpiredAsync || state == TimeoutExpiredSync ;
2370+ return state == TimeoutState . ExpiredAsync || state == TimeoutState . ExpiredSync ;
23692371 }
23702372 }
23712373
@@ -2382,7 +2384,7 @@ private void OnTimeoutAsync(object state)
23822384 {
23832385 // the return value is not useful here because no choice is going to be made using it
23842386 // we only want to make this call to set the state knowing that it will be seen later
2385- OnTimeoutCore ( TimeoutRunning , TimeoutExpiredAsync ) ;
2387+ OnTimeoutCore ( TimeoutState . Running , TimeoutState . ExpiredAsync ) ;
23862388 }
23872389 else
23882390 {
@@ -2392,7 +2394,7 @@ private void OnTimeoutAsync(object state)
23922394
23932395 private bool OnTimeoutSync ( )
23942396 {
2395- return OnTimeoutCore ( TimeoutRunning , TimeoutExpiredSync ) ;
2397+ return OnTimeoutCore ( TimeoutState . Running , TimeoutState . ExpiredSync ) ;
23962398 }
23972399
23982400 /// <summary>
@@ -2404,7 +2406,7 @@ private bool OnTimeoutSync()
24042406 /// <returns>boolean value indicating whether the call changed the timeout state</returns>
24052407 private bool OnTimeoutCore ( int expectedState , int targetState )
24062408 {
2407- Debug . Assert ( targetState == TimeoutExpiredAsync || targetState == TimeoutExpiredSync , "OnTimeoutCore must have an expiry state as the targetState" ) ;
2409+ Debug . Assert ( targetState == TimeoutState . ExpiredAsync || targetState == TimeoutState . ExpiredSync , "OnTimeoutCore must have an expiry state as the targetState" ) ;
24082410
24092411 bool retval = false ;
24102412 if ( Interlocked . CompareExchange ( ref _timeoutState , targetState , expectedState ) == expectedState )
@@ -2545,8 +2547,8 @@ internal void ReadSni(TaskCompletionSource<object> completion)
25452547 // if the state is currently stopped then change it to running and allocate a new identity value from
25462548 // the identity source. The identity value is used to correlate timer callback events to the currently
25472549 // running timeout and prevents a late timer callback affecting a result it does not relate to
2548- int previousTimeoutState = Interlocked . CompareExchange ( ref _timeoutState , TimeoutRunning , TimeoutStopped ) ;
2549- if ( previousTimeoutState == TimeoutStopped )
2550+ int previousTimeoutState = Interlocked . CompareExchange ( ref _timeoutState , TimeoutState . Running , TimeoutState . Stopped ) ;
2551+ if ( previousTimeoutState == TimeoutState . Stopped )
25502552 {
25512553 Debug . Assert ( _timeoutIdentityValue == 0 , "timer was previously stopped without resetting the _identityValue" ) ;
25522554 _timeoutIdentityValue = Interlocked . Increment ( ref _timeoutIdentitySource ) ;
@@ -2566,7 +2568,7 @@ internal void ReadSni(TaskCompletionSource<object> completion)
25662568 // >0 == Actual timeout remaining
25672569 int msecsRemaining = GetTimeoutRemaining ( ) ;
25682570
2569- Debug . Assert ( previousTimeoutState == TimeoutStopped , "previous timeout state was not Stopped" ) ;
2571+ Debug . Assert ( previousTimeoutState == TimeoutState . Stopped , "previous timeout state was not Stopped" ) ;
25702572 if ( msecsRemaining > 0 )
25712573 {
25722574 ChangeNetworkPacketTimeout ( msecsRemaining , Timeout . Infinite ) ;
@@ -2983,11 +2985,11 @@ public void ReadAsyncCallback(IntPtr key, IntPtr packet, UInt32 error)
29832985
29842986 // try to change to the stopped state but only do so if currently in the running state
29852987 // and use cmpexch so that all changes out of the running state are atomic
2986- int previousState = Interlocked . CompareExchange ( ref _timeoutState , TimeoutRunning , TimeoutStopped ) ;
2988+ int previousState = Interlocked . CompareExchange ( ref _timeoutState , TimeoutState . Running , TimeoutState . Stopped ) ;
29872989
29882990 // if the state is anything other than running then this query has reached an end so
29892991 // set the correlation _timeoutIdentityValue to 0 to prevent late callbacks executing
2990- if ( _timeoutState != TimeoutRunning )
2992+ if ( _timeoutState != TimeoutState . Running )
29912993 {
29922994 _timeoutIdentityValue = 0 ;
29932995 }
@@ -4127,7 +4129,7 @@ internal void AssertStateIsClean()
41274129 // Attention\Cancellation\Timeouts
41284130 Debug . Assert ( ! _attentionReceived && ! _attentionSent && ! _attentionSending , $ "StateObj is still dealing with attention: Sent: { _attentionSent } , Received: { _attentionReceived } , Sending: { _attentionSending } ") ;
41294131 Debug . Assert ( ! _cancelled , "StateObj still has cancellation set" ) ;
4130- Debug . Assert ( _timeoutState == TimeoutStopped , "StateObj still has internal timeout set" ) ;
4132+ Debug . Assert ( _timeoutState == TimeoutState . Stopped , "StateObj still has internal timeout set" ) ;
41314133 // Errors and Warnings
41324134 Debug . Assert ( ! _hasErrorOrWarning , "StateObj still has stored errors or warnings" ) ;
41334135 }
0 commit comments