@@ -425,38 +425,42 @@ public void Abort(ushort reasonCode, string reasonText,
425
425
public void Close ( ShutdownEventArgs reason , bool abort , int timeout )
426
426
{
427
427
if ( ! SetCloseReason ( reason ) )
428
- if ( abort )
429
- {
430
- if ( ! m_appContinuation . WaitOne ( BlockingCell . validatedTimeout ( timeout ) , true ) )
431
- m_frameHandler . Close ( ) ;
432
- return ;
433
- } else {
434
- throw new AlreadyClosedException ( m_closeReason ) ;
435
- }
436
-
437
- OnShutdown ( ) ;
438
- m_session0 . SetSessionClosing ( false ) ;
439
-
440
- try
441
428
{
442
- // Try to send connection.close
443
- // Wait for CloseOk in the MainLoop
444
- m_session0 . Transmit ( ConnectionCloseWrapper ( reason . ReplyCode ,
445
- reason . ReplyText ) ) ;
429
+ if ( ! abort )
430
+ throw new AlreadyClosedException ( m_closeReason ) ;
446
431
}
447
- catch ( IOException ioe ) {
448
- if ( m_model0 . CloseReason == null )
432
+ else
433
+ {
434
+ OnShutdown ( ) ;
435
+ m_session0 . SetSessionClosing ( false ) ;
436
+
437
+ try
438
+ {
439
+ // Try to send connection.close
440
+ // Wait for CloseOk in the MainLoop
441
+ m_session0 . Transmit ( ConnectionCloseWrapper ( reason . ReplyCode ,
442
+ reason . ReplyText ) ) ;
443
+ }
444
+ catch ( AlreadyClosedException ace )
449
445
{
450
446
if ( ! abort )
451
- throw ioe ;
452
- else
453
- LogCloseError ( "Couldn't close connection cleanly. "
454
- + "Socket closed unexpectedly" , ioe ) ;
447
+ throw ace ;
448
+ }
449
+ catch ( IOException ioe )
450
+ {
451
+ if ( m_model0 . CloseReason == null )
452
+ {
453
+ if ( ! abort )
454
+ throw ioe ;
455
+ else
456
+ LogCloseError ( "Couldn't close connection cleanly. "
457
+ + "Socket closed unexpectedly" , ioe ) ;
458
+ }
459
+ }
460
+ finally
461
+ {
462
+ TerminateMainloop ( ) ;
455
463
}
456
- }
457
- finally
458
- {
459
- TerminateMainloop ( ) ;
460
464
}
461
465
if ( ! m_appContinuation . WaitOne ( BlockingCell . validatedTimeout ( timeout ) , true ) )
462
466
m_frameHandler . Close ( ) ;
0 commit comments