@@ -83,14 +83,13 @@ internal sealed class Connection : IConnection
83
83
//
84
84
// Heartbeats
85
85
//
86
-
87
86
private TimeSpan _heartbeat = TimeSpan . Zero ;
88
87
private TimeSpan _heartbeatTimeSpan = TimeSpan . FromSeconds ( 0 ) ;
89
- private int _missedHeartbeats = 0 ;
88
+ private int _missedHeartbeats ;
89
+ private bool _heartbeatDetected ;
90
90
91
91
private Timer _heartbeatWriteTimer ;
92
92
private Timer _heartbeatReadTimer ;
93
- private readonly AutoResetEvent _heartbeatRead = new AutoResetEvent ( false ) ;
94
93
95
94
private Task _mainLoopTask ;
96
95
@@ -615,12 +614,9 @@ public void MainLoopIteration()
615
614
}
616
615
}
617
616
618
- public void NotifyHeartbeatListener ( )
617
+ private void NotifyHeartbeatListener ( )
619
618
{
620
- if ( _heartbeat != TimeSpan . Zero )
621
- {
622
- _heartbeatRead . Set ( ) ;
623
- }
619
+ _heartbeatDetected = true ;
624
620
}
625
621
626
622
public void NotifyReceivedCloseOk ( )
@@ -847,13 +843,14 @@ public void HeartbeatReadTimerCallback(object state)
847
843
{
848
844
if ( ! _closed )
849
845
{
850
- if ( ! _heartbeatRead . WaitOne ( 0 ) )
846
+ if ( _heartbeatDetected )
851
847
{
852
- _missedHeartbeats ++ ;
848
+ _heartbeatDetected = false ;
849
+ _missedHeartbeats = 0 ;
853
850
}
854
851
else
855
852
{
856
- _missedHeartbeats = 0 ;
853
+ _missedHeartbeats ++ ;
857
854
}
858
855
859
856
// We check against 8 = 2 * 4 because we need to wait for at
@@ -921,7 +918,7 @@ public void HeartbeatWriteTimerCallback(object state)
921
918
}
922
919
}
923
920
924
- void MaybeStopHeartbeatTimers ( )
921
+ private void MaybeStopHeartbeatTimers ( )
925
922
{
926
923
NotifyHeartbeatListener ( ) ;
927
924
_heartbeatReadTimer ? . Dispose ( ) ;
0 commit comments