@@ -958,32 +958,70 @@ public void ConfirmSelect()
958
958
_Private_ConfirmSelect ( false ) ;
959
959
}
960
960
961
- public bool WaitForConfirms ( )
962
- {
963
- lock ( m_unconfirmedSet . SyncRoot ) {
964
- while ( true ) {
965
- if ( CloseReason != null )
966
- throw new AlreadyClosedException ( CloseReason ) ;
967
-
968
- if ( m_unconfirmedSet . Count == 0 ) {
969
- bool aux = m_onlyAcksReceived ;
970
- m_onlyAcksReceived = true ;
971
- return aux ;
972
- }
973
- Monitor . Wait ( m_unconfirmedSet . SyncRoot ) ;
974
- }
975
- }
961
+ public bool WaitForConfirms ( TimeSpan timeout , out bool timedOut )
962
+ {
963
+ var isWaitInfinite = ( timeout . TotalMilliseconds == Timeout . Infinite ) ;
964
+ var stopwatch = Stopwatch . StartNew ( ) ;
965
+ lock ( m_unconfirmedSet . SyncRoot )
966
+ {
967
+ while ( true )
968
+ {
969
+ if ( CloseReason != null )
970
+ throw new AlreadyClosedException ( CloseReason ) ;
971
+
972
+ if ( m_unconfirmedSet . Count == 0 )
973
+ {
974
+ bool aux = m_onlyAcksReceived ;
975
+ m_onlyAcksReceived = true ;
976
+ timedOut = false ;
977
+ return aux ;
978
+ }
979
+ if ( isWaitInfinite )
980
+ Monitor . Wait ( m_unconfirmedSet . SyncRoot ) ;
981
+ else
982
+ {
983
+ var elapsed = stopwatch . Elapsed ;
984
+ if ( elapsed > timeout || ! Monitor . Wait (
985
+ m_unconfirmedSet . SyncRoot , timeout - elapsed ) )
986
+ {
987
+ timedOut = true ;
988
+ return true ;
989
+ }
990
+ }
991
+ }
992
+ }
976
993
}
977
994
978
- public void WaitForConfirmsOrDie ( )
979
- {
980
- if ( ! WaitForConfirms ( ) ) {
995
+ public bool WaitForConfirms ( )
996
+ {
997
+ bool timedOut ;
998
+ return WaitForConfirms ( TimeSpan . FromMilliseconds ( Timeout . Infinite ) , out timedOut ) ;
999
+ }
1000
+
1001
+ public void WaitForConfirmsOrDie ( )
1002
+ {
1003
+ WaitForConfirmsOrDie ( TimeSpan . FromMilliseconds ( Timeout . Infinite ) ) ;
1004
+ }
1005
+
1006
+ public void WaitForConfirmsOrDie ( TimeSpan timeout )
1007
+ {
1008
+ bool timedOut ;
1009
+ bool onlyAcksReceived = WaitForConfirms ( timeout , out timedOut ) ;
1010
+ if ( ! onlyAcksReceived ) {
981
1011
Close ( new ShutdownEventArgs ( ShutdownInitiator . Application ,
982
1012
CommonFraming . Constants . ReplySuccess ,
983
1013
"Nacks Received" , new IOException ( "nack received" ) ) ,
984
1014
false ) ;
985
1015
throw new IOException ( "Nacks Received" ) ;
986
1016
}
1017
+ if ( timedOut ) {
1018
+ Close ( new ShutdownEventArgs ( ShutdownInitiator . Application ,
1019
+ CommonFraming . Constants . ReplySuccess ,
1020
+ "Timed out waiting for acks" ,
1021
+ new IOException ( "timed out waiting for acks" ) ) ,
1022
+ false ) ;
1023
+ throw new IOException ( "Timed out waiting for acks" ) ;
1024
+ }
987
1025
}
988
1026
989
1027
public abstract void _Private_ConfirmSelect ( bool nowait ) ;
0 commit comments