@@ -87,10 +87,11 @@ internal sealed class Connection : IConnection
87
87
private TimeSpan _heartbeat = TimeSpan . Zero ;
88
88
private TimeSpan _heartbeatTimeSpan = TimeSpan . FromSeconds ( 0 ) ;
89
89
private int _missedHeartbeats = 0 ;
90
+ private int _heartbeatCounter ;
91
+ private int _lastHeartbeat ;
90
92
91
93
private Timer _heartbeatWriteTimer ;
92
94
private Timer _heartbeatReadTimer ;
93
- private readonly AutoResetEvent _heartbeatRead = new AutoResetEvent ( false ) ;
94
95
95
96
private Task _mainLoopTask ;
96
97
@@ -617,10 +618,7 @@ public void MainLoopIteration()
617
618
618
619
public void NotifyHeartbeatListener ( )
619
620
{
620
- if ( _heartbeat != TimeSpan . Zero )
621
- {
622
- _heartbeatRead . Set ( ) ;
623
- }
621
+ _heartbeatCounter ++ ;
624
622
}
625
623
626
624
public void NotifyReceivedCloseOk ( )
@@ -847,7 +845,7 @@ public void HeartbeatReadTimerCallback(object state)
847
845
{
848
846
if ( ! _closed )
849
847
{
850
- if ( ! _heartbeatRead . WaitOne ( 0 ) )
848
+ if ( _lastHeartbeat == _heartbeatCounter )
851
849
{
852
850
_missedHeartbeats ++ ;
853
851
}
@@ -856,6 +854,8 @@ public void HeartbeatReadTimerCallback(object state)
856
854
_missedHeartbeats = 0 ;
857
855
}
858
856
857
+ _lastHeartbeat = _heartbeatCounter ;
858
+
859
859
// We check against 8 = 2 * 4 because we need to wait for at
860
860
// least two complete heartbeat setting intervals before
861
861
// complaining, and we've set the socket timeout to a quarter
0 commit comments