@@ -578,58 +578,63 @@ public void NotifyHeartbeatThread()
578578
579579 public void MainLoop ( )
580580 {
581- bool shutdownCleanly = false ;
582581 try
583582 {
584- while ( m_running )
583+ bool shutdownCleanly = false ;
584+ try
585585 {
586- try {
587- MainLoopIteration ( ) ;
588- } catch ( SoftProtocolException spe ) {
589- QuiesceChannel ( spe ) ;
586+ while ( m_running )
587+ {
588+ try {
589+ MainLoopIteration ( ) ;
590+ } catch ( SoftProtocolException spe ) {
591+ QuiesceChannel ( spe ) ;
592+ }
590593 }
594+ shutdownCleanly = true ;
595+ }
596+ catch ( EndOfStreamException eose )
597+ {
598+ // Possible heartbeat exception
599+ HandleMainLoopException ( new ShutdownEventArgs (
600+ ShutdownInitiator . Library ,
601+ 0 ,
602+ "End of stream" ,
603+ eose ) ) ;
604+ }
605+ catch ( HardProtocolException hpe )
606+ {
607+ shutdownCleanly = HardProtocolExceptionHandler ( hpe ) ;
608+ }
609+ catch ( SocketException se )
610+ {
611+ // Possibly due to handshake timeout
612+ HandleMainLoopException ( new ShutdownEventArgs ( ShutdownInitiator . Library ,
613+ 0 ,
614+ "Socket exception" ,
615+ se ) ) ;
616+ }
617+ catch ( Exception ex )
618+ {
619+ HandleMainLoopException ( new ShutdownEventArgs ( ShutdownInitiator . Library ,
620+ CommonFraming . Constants . InternalError ,
621+ "Unexpected Exception" ,
622+ ex ) ) ;
591623 }
592- shutdownCleanly = true ;
593- }
594- catch ( EndOfStreamException eose )
595- {
596- // Possible heartbeat exception
597- HandleMainLoopException ( new ShutdownEventArgs (
598- ShutdownInitiator . Library ,
599- 0 ,
600- "End of stream" ,
601- eose ) ) ;
602- }
603- catch ( HardProtocolException hpe )
604- {
605- shutdownCleanly = HardProtocolExceptionHandler ( hpe ) ;
606- }
607- catch ( SocketException se )
608- {
609- // Possibly due to handshake timeout
610- HandleMainLoopException ( new ShutdownEventArgs ( ShutdownInitiator . Library ,
611- 0 ,
612- "Socket exception" ,
613- se ) ) ;
614- }
615- catch ( Exception ex )
616- {
617- HandleMainLoopException ( new ShutdownEventArgs ( ShutdownInitiator . Library ,
618- CommonFraming . Constants . InternalError ,
619- "Unexpected Exception" ,
620- ex ) ) ;
621- }
622624
623- // If allowed for clean shutdown, run main loop until the
624- // connection closes.
625- if ( shutdownCleanly )
625+ // If allowed for clean shutdown, run main loop until the
626+ // connection closes.
627+ if ( shutdownCleanly )
628+ {
629+ ClosingLoop ( ) ;
630+ }
631+
632+ FinishClose ( ) ;
633+ }
634+ finally
626635 {
627- ClosingLoop ( ) ;
636+ m_appContinuation . Set ( ) ;
628637 }
629-
630- FinishClose ( ) ;
631-
632- m_appContinuation . Set ( ) ;
633638 }
634639
635640 public void MainLoopIteration ( )
0 commit comments