Skip to content

Commit

Permalink
Use constants
Browse files Browse the repository at this point in the history
  • Loading branch information
lukebakken committed Feb 25, 2022
1 parent 23f6613 commit dfcc183
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 8 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ TestResult.xml
/NuGet
.vscode/
*.lock.json
api/

test.sh
*.VisualState.xml
Expand Down
8 changes: 4 additions & 4 deletions projects/RabbitMQ.Client/client/api/IConnectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public static class IConnectionExtensions
/// </remarks>
public static void Close(this IConnection connection)
{
connection.Close(Constants.ReplySuccess, "Goodbye", TimeSpan.FromSeconds(30), false);
connection.Close(Constants.ReplySuccess, "Goodbye", InternalConstants.DefaultConnectionCloseTimeout, false);
}

/// <summary>
Expand All @@ -37,7 +37,7 @@ public static void Close(this IConnection connection)
/// </remarks>
public static void Close(this IConnection connection, ushort reasonCode, string reasonText)
{
connection.Close(reasonCode, reasonText, TimeSpan.FromSeconds(30), false);
connection.Close(reasonCode, reasonText, InternalConstants.DefaultConnectionCloseTimeout, false);
}

/// <summary>
Expand Down Expand Up @@ -93,7 +93,7 @@ public static void Close(this IConnection connection, ushort reasonCode, string
/// </remarks>
public static void Abort(this IConnection connection)
{
connection.Close(Constants.ReplySuccess, "Connection close forced", TimeSpan.FromSeconds(5), true);
connection.Close(Constants.ReplySuccess, "Connection close forced", InternalConstants.DefaultConnectionAbortTimeout, true);
}

/// <summary>
Expand All @@ -111,7 +111,7 @@ public static void Abort(this IConnection connection)
/// </remarks>
public static void Abort(this IConnection connection, ushort reasonCode, string reasonText)
{
connection.Close(reasonCode, reasonText, TimeSpan.FromSeconds(5), true);
connection.Close(reasonCode, reasonText, InternalConstants.DefaultConnectionAbortTimeout, true);
}

/// <summary>
Expand Down
41 changes: 41 additions & 0 deletions projects/RabbitMQ.Client/client/api/InternalConstants.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// This source code is dual-licensed under the Apache License, version
// 2.0, and the Mozilla Public License, version 2.0.
//
// The APL v2.0:
//
//---------------------------------------------------------------------------
// Copyright (c) 2007-2020 VMware, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//---------------------------------------------------------------------------
//
// The MPL v2.0:
//
//---------------------------------------------------------------------------
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
//
// Copyright (c) 2007-2020 VMware, Inc. All rights reserved.
//---------------------------------------------------------------------------

using System;

namespace RabbitMQ.Client
{
internal static class InternalConstants
{
internal static readonly TimeSpan DefaultConnectionAbortTimeout = TimeSpan.FromSeconds(5);
internal static readonly TimeSpan DefaultConnectionCloseTimeout = TimeSpan.FromSeconds(30);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ public void Dispose()

try
{
this.Abort(TimeSpan.FromSeconds(15));
this.Abort(InternalConstants.DefaultConnectionAbortTimeout);
}
catch (Exception)
{
Expand Down
2 changes: 1 addition & 1 deletion projects/RabbitMQ.Client/client/impl/Connection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ public void Dispose()

try
{
this.Abort(TimeSpan.FromSeconds(15));
this.Abort(InternalConstants.DefaultConnectionAbortTimeout);
_mainLoopTask.Wait();
}
catch (OperationInterruptedException)
Expand Down
2 changes: 1 addition & 1 deletion projects/RabbitMQ.Client/client/impl/ModelBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,7 @@ protected void HandleConnectionStart(in IncomingCommand cmd)
if (m_connectionStartCell is null)
{
var reason = new ShutdownEventArgs(ShutdownInitiator.Library, Constants.CommandInvalid, "Unexpected Connection.Start");
Session.Connection.Close(reason, false, TimeSpan.FromSeconds(30));
Session.Connection.Close(reason, false, InternalConstants.DefaultConnectionCloseTimeout);
}

var method = new ConnectionStart(cmd.MethodBytes.Span);
Expand Down

0 comments on commit dfcc183

Please sign in to comment.