Skip to content

Commit 150a5b0

Browse files
author
Steve Powell
committed
Rewrote section to only have to call WaitOne once.
1 parent 93d534d commit 150a5b0

File tree

1 file changed

+31
-39
lines changed

1 file changed

+31
-39
lines changed

projects/client/RabbitMQ.Client/src/client/impl/ConnectionBase.cs

Lines changed: 31 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -424,50 +424,42 @@ public void Abort(ushort reasonCode, string reasonText,
424424
///</remarks>
425425
public void Close(ShutdownEventArgs reason, bool abort, int timeout)
426426
{
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);
439430

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));
455442
}
456-
}
457-
catch (IOException ioe)
458-
{
459-
if (m_model0.CloseReason == null)
443+
catch (AlreadyClosedException ace)
460444
{
461445
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();
466462
}
467-
}
468-
finally
469-
{
470-
TerminateMainloop();
471463
}
472464
if (!m_appContinuation.WaitOne(BlockingCell.validatedTimeout(timeout),true))
473465
m_frameHandler.Close();

0 commit comments

Comments
 (0)