Skip to content

Commit 1f00a16

Browse files
committed
AllowAutomaticReconnect -> AllowReconnect
1 parent b77123a commit 1f00a16

File tree

13 files changed

+86
-62
lines changed

13 files changed

+86
-62
lines changed

src/SignalR/clients/csharp/Client.Core/src/HubConnection.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1165,7 +1165,7 @@ async Task StartProcessingInvocationMessages(ChannelReader<InvocationMessage> in
11651165
}
11661166

11671167
// Stopping being true indicates the client shouldn't try to reconnect even if automatic reconnects are enabled.
1168-
if (!closeMessage.AllowAutomaticReconnect)
1168+
if (!closeMessage.AllowReconnect)
11691169
{
11701170
connectionState.Stopping = true;
11711171
}
@@ -1645,7 +1645,7 @@ private class ConnectionState : IInvocationBinder
16451645
public CancellationToken UploadStreamToken { get; set; }
16461646

16471647
// Indicates the connection is stopping AND the client should NOT attempt to reconnect even if automatic reconnects are enabled.
1648-
// This means either HubConnection.DisposeAsync/StopAsync was called OR a CloseMessage with AllowAutomaticReconnects set to false was received.
1648+
// This means either HubConnection.DisposeAsync/StopAsync was called OR a CloseMessage with AllowReconnects set to false was received.
16491649
public bool Stopping
16501650
{
16511651
get => _stopping;

src/SignalR/clients/csharp/Client/test/UnitTests/HubConnectionTests.Reconnect.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ bool ExpectedErrors(WriteContext writeContext)
369369
}
370370

371371
[Fact]
372-
public async Task CanBeInducedByCloseMessageWithAllowAutoReconnectSet()
372+
public async Task CanBeInducedByCloseMessageWithAllowReconnectSet()
373373
{
374374
bool ExpectedErrors(WriteContext writeContext)
375375
{
@@ -455,7 +455,7 @@ await currentConnection.ReceiveJsonMessage(new
455455
}
456456

457457
[Fact]
458-
public async Task CannotBeInducedByCloseMessageWithAllowAutoReconnectOmitted()
458+
public async Task CannotBeInducedByCloseMessageWithAllowReconnectOmitted()
459459
{
460460
bool ExpectedErrors(WriteContext writeContext)
461461
{

src/SignalR/common/Protocols.Json/src/Protocol/JsonHubProtocol.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ public sealed class JsonHubProtocol : IHubProtocol
3131
private static JsonEncodedText TypePropertyNameBytes = JsonEncodedText.Encode(TypePropertyName);
3232
private const string ErrorPropertyName = "error";
3333
private static JsonEncodedText ErrorPropertyNameBytes = JsonEncodedText.Encode(ErrorPropertyName);
34-
private const string AllowAutomaticReconnectPropertyName = "allowReconnect";
35-
private static JsonEncodedText AllowAutomaticReconnectPropertyNameBytes = JsonEncodedText.Encode(AllowAutomaticReconnectPropertyName);
34+
private const string AllowReconnectPropertyName = "allowReconnect";
35+
private static JsonEncodedText AllowReconnectPropertyNameBytes = JsonEncodedText.Encode(AllowReconnectPropertyName);
3636
private const string TargetPropertyName = "target";
3737
private static JsonEncodedText TargetPropertyNameBytes = JsonEncodedText.Encode(TargetPropertyName);
3838
private const string ArgumentsPropertyName = "arguments";
@@ -134,7 +134,7 @@ private HubMessage ParseMessage(ReadOnlySequence<byte> input, IInvocationBinder
134134
ExceptionDispatchInfo argumentBindingException = null;
135135
Dictionary<string, string> headers = null;
136136
var completed = false;
137-
var allowAutomaticReconnect = false;
137+
var allowReconnect = false;
138138

139139
var reader = new Utf8JsonReader(input, isFinalBlock: true, state: default);
140140

@@ -189,9 +189,9 @@ private HubMessage ParseMessage(ReadOnlySequence<byte> input, IInvocationBinder
189189
{
190190
error = reader.ReadAsString(ErrorPropertyName);
191191
}
192-
else if (reader.ValueTextEquals(AllowAutomaticReconnectPropertyNameBytes.EncodedUtf8Bytes))
192+
else if (reader.ValueTextEquals(AllowReconnectPropertyNameBytes.EncodedUtf8Bytes))
193193
{
194-
allowAutomaticReconnect = reader.ReadAsBoolean(AllowAutomaticReconnectPropertyName);
194+
allowReconnect = reader.ReadAsBoolean(AllowReconnectPropertyName);
195195
}
196196
else if (reader.ValueTextEquals(ResultPropertyNameBytes.EncodedUtf8Bytes))
197197
{
@@ -379,7 +379,7 @@ private HubMessage ParseMessage(ReadOnlySequence<byte> input, IInvocationBinder
379379
case HubProtocolConstants.PingMessageType:
380380
return PingMessage.Instance;
381381
case HubProtocolConstants.CloseMessageType:
382-
return BindCloseMessage(error, allowAutomaticReconnect);
382+
return BindCloseMessage(error, allowReconnect);
383383
case null:
384384
throw new InvalidDataException($"Missing required property '{TypePropertyName}'.");
385385
default:
@@ -552,9 +552,9 @@ private void WriteCloseMessage(CloseMessage message, Utf8JsonWriter writer)
552552
writer.WriteString(ErrorPropertyNameBytes, message.Error);
553553
}
554554

555-
if (message.AllowAutomaticReconnect)
555+
if (message.AllowReconnect)
556556
{
557-
writer.WriteBoolean(AllowAutomaticReconnectPropertyNameBytes, false);
557+
writer.WriteBoolean(AllowReconnectPropertyNameBytes, true);
558558
}
559559
}
560560

@@ -734,15 +734,15 @@ private object[] BindTypes(ref Utf8JsonReader reader, IReadOnlyList<Type> paramT
734734
return arguments ?? Array.Empty<object>();
735735
}
736736

737-
private CloseMessage BindCloseMessage(string error, bool allowAutomaticReconnect)
737+
private CloseMessage BindCloseMessage(string error, bool allowReconnect)
738738
{
739739
// An empty string is still an error
740-
if (error == null && !allowAutomaticReconnect)
740+
if (error == null && !allowReconnect)
741741
{
742742
return CloseMessage.Empty;
743743
}
744744

745-
return new CloseMessage(error, allowAutomaticReconnect);
745+
return new CloseMessage(error, allowReconnect);
746746
}
747747

748748
private HubMessage ApplyHeaders(HubMessage message, Dictionary<string, string> headers)

src/SignalR/common/Protocols.MessagePack/src/Protocol/MessagePackHubProtocol.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -264,20 +264,20 @@ private static CancelInvocationMessage CreateCancelInvocationMessage(byte[] inpu
264264
private static CloseMessage CreateCloseMessage(byte[] input, ref int offset, int itemCount)
265265
{
266266
var error = ReadString(input, ref offset, "error");
267-
var allowAutomaticReconnect = true;
267+
var allowReconnect = false;
268268

269269
if (itemCount > 2)
270270
{
271-
allowAutomaticReconnect = ReadBoolean(input, ref offset, "allowReconnect");
271+
allowReconnect = ReadBoolean(input, ref offset, "allowReconnect");
272272
}
273273

274274
// An empty string is still an error
275-
if (error == null && !allowAutomaticReconnect)
275+
if (error == null && !allowReconnect)
276276
{
277277
return CloseMessage.Empty;
278278
}
279279

280-
return new CloseMessage(error, allowAutomaticReconnect);
280+
return new CloseMessage(error, allowReconnect);
281281
}
282282

283283
private static Dictionary<string, string> ReadHeaders(byte[] input, ref int offset)
@@ -557,7 +557,7 @@ private void WriteCloseMessage(CloseMessage message, Stream packer)
557557
MessagePackBinary.WriteString(packer, message.Error);
558558
}
559559

560-
MessagePackBinary.WriteBoolean(packer, message.AllowAutomaticReconnect);
560+
MessagePackBinary.WriteBoolean(packer, message.AllowReconnect);
561561
}
562562

563563
private void WritePingMessage(PingMessage pingMessage, Stream packer)

src/SignalR/common/Protocols.NewtonsoftJson/src/Protocol/NewtonsoftJsonHubProtocol.cs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public class NewtonsoftJsonHubProtocol : IHubProtocol
3030
private const string TargetPropertyName = "target";
3131
private const string ArgumentsPropertyName = "arguments";
3232
private const string HeadersPropertyName = "headers";
33-
private const string AllowAutomaticReconnectPropertyName = "allowReconnect";
33+
private const string AllowReconnectPropertyName = "allowReconnect";
3434

3535
private static readonly string ProtocolName = "json";
3636
private static readonly int ProtocolVersion = 1;
@@ -132,7 +132,7 @@ private HubMessage ParseMessage(Utf8BufferTextReader textReader, IInvocationBind
132132
ExceptionDispatchInfo argumentBindingException = null;
133133
Dictionary<string, string> headers = null;
134134
var completed = false;
135-
var allowAutomaticReconnect = false;
135+
var allowReconnect = false;
136136

137137
using (var reader = JsonUtils.CreateJsonTextReader(textReader))
138138
{
@@ -189,8 +189,8 @@ private HubMessage ParseMessage(Utf8BufferTextReader textReader, IInvocationBind
189189
case ErrorPropertyName:
190190
error = JsonUtils.ReadAsString(reader, ErrorPropertyName);
191191
break;
192-
case AllowAutomaticReconnectPropertyName:
193-
allowAutomaticReconnect = JsonUtils.ReadAsBoolean(reader, AllowAutomaticReconnectPropertyName);
192+
case AllowReconnectPropertyName:
193+
allowReconnect = JsonUtils.ReadAsBoolean(reader, AllowReconnectPropertyName);
194194
break;
195195
case ResultPropertyName:
196196
hasResult = true;
@@ -378,7 +378,7 @@ private HubMessage ParseMessage(Utf8BufferTextReader textReader, IInvocationBind
378378
case HubProtocolConstants.PingMessageType:
379379
return PingMessage.Instance;
380380
case HubProtocolConstants.CloseMessageType:
381-
return BindCloseMessage(error, allowAutomaticReconnect);
381+
return BindCloseMessage(error, allowReconnect);
382382
case null:
383383
throw new InvalidDataException($"Missing required property '{TypePropertyName}'.");
384384
default:
@@ -555,6 +555,12 @@ private void WriteCloseMessage(CloseMessage message, JsonTextWriter writer)
555555
writer.WritePropertyName(ErrorPropertyName);
556556
writer.WriteValue(message.Error);
557557
}
558+
559+
if (message.AllowReconnect)
560+
{
561+
writer.WritePropertyName(AllowReconnectPropertyName);
562+
writer.WriteValue(true);
563+
}
558564
}
559565

560566
private void WriteArguments(object[] arguments, JsonTextWriter writer)
@@ -738,15 +744,15 @@ private object[] BindArguments(JsonTextReader reader, IReadOnlyList<Type> paramT
738744
throw new JsonReaderException("Unexpected end when reading JSON");
739745
}
740746

741-
private CloseMessage BindCloseMessage(string error, bool allowAutomaticReconnect)
747+
private CloseMessage BindCloseMessage(string error, bool allowReconnect)
742748
{
743749
// An empty string is still an error
744-
if (error == null && !allowAutomaticReconnect)
750+
if (error == null && !allowReconnect)
745751
{
746752
return CloseMessage.Empty;
747753
}
748754

749-
return new CloseMessage(error, allowAutomaticReconnect);
755+
return new CloseMessage(error, allowReconnect);
750756
}
751757

752758
private object[] BindArguments(JArray args, IReadOnlyList<Type> paramTypes)

src/SignalR/common/Shared/JsonUtils.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,6 @@ public static bool ReadAsBoolean(JsonTextReader reader, string propertyName)
123123
throw new InvalidDataException($"Expected '{propertyName}' to be of type {JTokenType.Boolean}.");
124124
}
125125

126-
// REVIEW: I'm trying to keep this similar to ReadAsInt32, but why not just call reader.ReadAsBoolean() and verify it's not null?
127126
return Convert.ToBoolean(reader.Value, CultureInfo.InvariantCulture);
128127
}
129128

src/SignalR/common/SignalR.Common/ref/Microsoft.AspNetCore.SignalR.Common.netcoreapp.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ public partial class CloseMessage : Microsoft.AspNetCore.SignalR.Protocol.HubMes
3131
{
3232
public static readonly Microsoft.AspNetCore.SignalR.Protocol.CloseMessage Empty;
3333
public CloseMessage(string error) { }
34-
public CloseMessage(string error, bool allowAutomaticReconnect) { }
35-
public bool AllowAutomaticReconnect { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } }
34+
public CloseMessage(string error, bool allowReconnect) { }
35+
public bool AllowReconnect { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } }
3636
public string Error { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } }
3737
}
3838
public partial class CompletionMessage : Microsoft.AspNetCore.SignalR.Protocol.HubInvocationMessage

src/SignalR/common/SignalR.Common/ref/Microsoft.AspNetCore.SignalR.Common.netstandard2.0.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ public partial class CloseMessage : Microsoft.AspNetCore.SignalR.Protocol.HubMes
3131
{
3232
public static readonly Microsoft.AspNetCore.SignalR.Protocol.CloseMessage Empty;
3333
public CloseMessage(string error) { }
34-
public CloseMessage(string error, bool allowAutomaticReconnect) { }
35-
public bool AllowAutomaticReconnect { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } }
34+
public CloseMessage(string error, bool allowReconnect) { }
35+
public bool AllowReconnect { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } }
3636
public string Error { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } }
3737
}
3838
public partial class CompletionMessage : Microsoft.AspNetCore.SignalR.Protocol.HubInvocationMessage

src/SignalR/common/SignalR.Common/src/Protocol/CloseMessage.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ namespace Microsoft.AspNetCore.SignalR.Protocol
1212
public class CloseMessage : HubMessage
1313
{
1414
/// <summary>
15-
/// An empty close message with no error and <see cref="AllowAutomaticReconnect"/> set to <see langword="false"/>.
15+
/// An empty close message with no error and <see cref="AllowReconnect"/> set to <see langword="false"/>.
1616
/// </summary>
17-
public static readonly CloseMessage Empty = new CloseMessage(error: null, allowAutomaticReconnect: false);
17+
public static readonly CloseMessage Empty = new CloseMessage(error: null, allowReconnect: false);
1818

1919
/// <summary>
2020
/// Gets the optional error message.
@@ -24,14 +24,14 @@ public class CloseMessage : HubMessage
2424
/// <summary>
2525
/// If <see langword="false"/>, clients with automatic reconnects enabled should not attempt to automatically reconnect after receiving the <see cref="CloseMessage"/>.
2626
/// </summary>
27-
public bool AllowAutomaticReconnect { get; }
27+
public bool AllowReconnect { get; }
2828

2929
/// <summary>
30-
/// Initializes a new instance of the <see cref="CloseMessage"/> class with an optional error message and <see cref="AllowAutomaticReconnect"/> set to <see langword="false"/>.
30+
/// Initializes a new instance of the <see cref="CloseMessage"/> class with an optional error message and <see cref="AllowReconnect"/> set to <see langword="false"/>.
3131
/// </summary>
3232
/// <param name="error">An optional error message.</param>
3333
public CloseMessage(string error)
34-
: this(error, allowAutomaticReconnect: false)
34+
: this(error, allowReconnect: false)
3535
{
3636
}
3737

@@ -40,14 +40,14 @@ public CloseMessage(string error)
4040
/// automatic reconnects enabled should attempt to reconnect upon receiving the message.
4141
/// </summary>
4242
/// <param name="error">An optional error message.</param>
43-
/// <param name="allowAutomaticReconnect">
43+
/// <param name="allowReconnect">
4444
/// <see langword="true"/>, if client with automatic reconnects enabled should attempt to reconnect after receiving the <see cref="CloseMessage"/>;
4545
/// <see langword="false"/>, if the client should not try to reconnect whether or not automatic reconnects are enabled.
4646
/// </param>
47-
public CloseMessage(string error, bool allowAutomaticReconnect)
47+
public CloseMessage(string error, bool allowReconnect)
4848
{
4949
Error = error;
50-
AllowAutomaticReconnect = allowAutomaticReconnect;
50+
AllowReconnect = allowReconnect;
5151
}
5252
}
5353
}

src/SignalR/common/SignalR.Common/test/Internal/Protocol/JsonHubProtocolTestsBase.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ public abstract class JsonHubProtocolTestsBase
6767
new JsonProtocolTestData("CloseMessage_HasError", new CloseMessage("Error!"), false, true, "{\"type\":7,\"error\":\"Error!\"}"),
6868
new JsonProtocolTestData("CloseMessage_HasErrorEmptyString", new CloseMessage(""), false, true, "{\"type\":7,\"error\":\"\"}"),
6969
new JsonProtocolTestData("CloseMessage_HasErrorWithCamelCase", new CloseMessage("Error!"), true, true, "{\"type\":7,\"error\":\"Error!\"}"),
70+
new JsonProtocolTestData("CloseMessage_HasAllowReconnect", new CloseMessage(error: null, allowReconnect: true), true, true, "{\"type\":7,\"allowReconnect\":true}"),
71+
new JsonProtocolTestData("CloseMessage_HasErrorAndAllowReconnect", new CloseMessage("Error!", allowReconnect: true), true, true, "{\"type\":7,\"error\":\"Error!\",\"allowReconnect\":true}"),
7072

7173
}.ToDictionary(t => t.Name);
7274

0 commit comments

Comments
 (0)