@@ -86,9 +86,9 @@ internal sealed class Connection : IConnection
86
86
87
87
private TimeSpan _heartbeat = TimeSpan . Zero ;
88
88
private TimeSpan _heartbeatTimeSpan = TimeSpan . FromSeconds ( 0 ) ;
89
- private int _missedHeartbeats = 0 ;
89
+ private int _missedHeartbeats ;
90
90
private int _heartbeatCounter ;
91
- private int _lastHeartbeat ;
91
+ private int _lastHeartbeatCounter ;
92
92
93
93
private Timer _heartbeatWriteTimer ;
94
94
private Timer _heartbeatReadTimer ;
@@ -618,7 +618,12 @@ public void MainLoopIteration()
618
618
619
619
public void NotifyHeartbeatListener ( )
620
620
{
621
- _heartbeatCounter ++ ;
621
+ // https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/checked-and-unchecked
622
+ // No worries if this overflows. What matters is that the value changes.
623
+ unchecked
624
+ {
625
+ _heartbeatCounter ++ ;
626
+ }
622
627
}
623
628
624
629
public void NotifyReceivedCloseOk ( )
@@ -845,7 +850,7 @@ public void HeartbeatReadTimerCallback(object state)
845
850
{
846
851
if ( ! _closed )
847
852
{
848
- if ( _lastHeartbeat == _heartbeatCounter )
853
+ if ( _lastHeartbeatCounter == _heartbeatCounter )
849
854
{
850
855
_missedHeartbeats ++ ;
851
856
}
@@ -854,7 +859,7 @@ public void HeartbeatReadTimerCallback(object state)
854
859
_missedHeartbeats = 0 ;
855
860
}
856
861
857
- _lastHeartbeat = _heartbeatCounter ;
862
+ _lastHeartbeatCounter = _heartbeatCounter ;
858
863
859
864
// We check against 8 = 2 * 4 because we need to wait for at
860
865
// least two complete heartbeat setting intervals before
0 commit comments