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