Skip to content

Commit 5e0f118

Browse files
stebetlukebakken
authored andcommitted
Removing unused ConnectionOpen method.
Adding Timeout extension for ValueTask for connection handshake. Don't target .NET Framework 4.7.2 in Benchmarks, Test Apps and Unit Tests when not building in Windows.
1 parent 290bdf2 commit 5e0f118

File tree

13 files changed

+72
-42
lines changed

13 files changed

+72
-42
lines changed

projects/Benchmarks/Benchmarks.csproj

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

3-
<PropertyGroup>
3+
<PropertyGroup Condition="$([MSBuild]::IsOSPlatform('Windows'))">
44
<TargetFrameworks>net6.0;net472</TargetFrameworks>
5+
</PropertyGroup>
6+
7+
<PropertyGroup Condition="!$([MSBuild]::IsOSPlatform('Windows'))">
8+
<TargetFramework>net6.0</TargetFramework>
9+
</PropertyGroup>
10+
11+
<PropertyGroup>
512
<OutputType>Exe</OutputType>
613
<AssemblyOriginatorKeyFile>../rabbit.snk</AssemblyOriginatorKeyFile>
714
<SignAssembly>true</SignAssembly>

projects/RabbitMQ.Client/client/api/IChannelExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public static void BasicPublish(this IChannel channel, string exchange, string r
9494

9595
public static void BasicPublish(this IChannel channel, CachedString exchange, CachedString routingKey, ReadOnlyMemory<byte> body = default, bool mandatory = false)
9696
=> channel.BasicPublish(exchange, routingKey, in EmptyBasicProperty.Empty, body, mandatory);
97-
97+
9898
public static ValueTask BasicPublishAsync(this IChannel channel, string exchange, string routingKey, ReadOnlyMemory<byte> body = default, bool mandatory = false)
9999
=> channel.BasicPublishAsync(exchange, routingKey, in EmptyBasicProperty.Empty, body, mandatory);
100100

projects/RabbitMQ.Client/client/framing/Channel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public override void _Private_ConnectionOpen(string virtualHost)
109109
{
110110
ChannelSend(new ConnectionOpen(virtualHost));
111111
}
112-
112+
113113
public override ValueTask _Private_ConnectionOpenAsync(string virtualHost)
114114
{
115115
return ModelSendAsync(new ConnectionOpen(virtualHost));

projects/RabbitMQ.Client/client/impl/AutorecoveringChannel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ public void BasicPublish<TProperties>(string exchange, string routingKey, in TPr
317317
public void BasicPublish<TProperties>(CachedString exchange, CachedString routingKey, in TProperties basicProperties, ReadOnlyMemory<byte> body, bool mandatory)
318318
where TProperties : IReadOnlyBasicProperties, IAmqpHeader
319319
=> InnerChannel.BasicPublish(exchange, routingKey, in basicProperties, body, mandatory);
320-
320+
321321
public ValueTask BasicPublishAsync<TProperties>(string exchange, string routingKey, in TProperties basicProperties, ReadOnlyMemory<byte> body, bool mandatory)
322322
where TProperties : IReadOnlyBasicProperties, IAmqpHeader
323323
=> InnerChannel.BasicPublishAsync(exchange, routingKey, in basicProperties, body, mandatory);

projects/RabbitMQ.Client/client/impl/ChannelBase.cs

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -241,29 +241,9 @@ private async Task CloseAsync(ShutdownEventArgs reason, bool abort)
241241
}
242242
}
243243

244-
internal void ConnectionOpen(string virtualHost)
244+
internal async ValueTask ConnectionOpenAsync(string virtualHost)
245245
{
246-
var k = new SimpleBlockingRpcContinuation();
247-
lock (_rpcLock)
248-
{
249-
Enqueue(k);
250-
try
251-
{
252-
_Private_ConnectionOpen(virtualHost);
253-
}
254-
catch (AlreadyClosedException)
255-
{
256-
// let continuation throw OperationInterruptedException,
257-
// which is a much more suitable exception before connection
258-
// negotiation finishes
259-
}
260-
k.GetReply(HandshakeContinuationTimeout);
261-
}
262-
}
263-
264-
internal ValueTask ConnectionOpenAsync(string virtualHost)
265-
{
266-
return _Private_ConnectionOpenAsync(virtualHost);
246+
await _Private_ConnectionOpenAsync(virtualHost).TimeoutAfter(HandshakeContinuationTimeout);
267247
}
268248

269249
internal async ValueTask<ConnectionSecureOrTune> ConnectionSecureOkAsync(byte[] response)
@@ -401,7 +381,7 @@ protected void ChannelSend<T>(in T method) where T : struct, IOutgoingAmqpMethod
401381
{
402382
Session.Transmit(in method);
403383
}
404-
384+
405385
[MethodImpl(MethodImplOptions.AggressiveInlining)]
406386
protected ValueTask ModelSendAsync<T>(in T method) where T : struct, IOutgoingAmqpMethod
407387
{
@@ -419,7 +399,7 @@ protected void ChannelSend<TMethod, THeader>(in TMethod method, in THeader heade
419399
}
420400
Session.Transmit(in method, in header, body);
421401
}
422-
402+
423403
[MethodImpl(MethodImplOptions.AggressiveInlining)]
424404
protected ValueTask ModelSendAsync<TMethod, THeader>(in TMethod method, in THeader header, ReadOnlyMemory<byte> body)
425405
where TMethod : struct, IOutgoingAmqpMethod
@@ -429,7 +409,7 @@ protected ValueTask ModelSendAsync<TMethod, THeader>(in TMethod method, in THead
429409
{
430410
_flowControlBlock.Wait();
431411
}
432-
412+
433413
return Session.TransmitAsync(in method, in header, body);
434414
}
435415

@@ -950,7 +930,7 @@ public void BasicPublish<TProperties>(CachedString exchange, CachedString routin
950930
var cmd = new BasicPublishMemory(exchange.Bytes, routingKey.Bytes, mandatory, default);
951931
ChannelSend(in cmd, in basicProperties, body);
952932
}
953-
933+
954934
public ValueTask BasicPublishAsync<TProperties>(string exchange, string routingKey, in TProperties basicProperties, ReadOnlyMemory<byte> body, bool mandatory)
955935
where TProperties : IReadOnlyBasicProperties, IAmqpHeader
956936
{
@@ -965,7 +945,7 @@ public ValueTask BasicPublishAsync<TProperties>(string exchange, string routingK
965945
var cmd = new BasicPublish(exchange, routingKey, mandatory, default);
966946
return ModelSendAsync(in cmd, in basicProperties, body);
967947
}
968-
948+
969949
public ValueTask BasicPublishAsync<TProperties>(CachedString exchange, CachedString routingKey, in TProperties basicProperties, ReadOnlyMemory<byte> body, bool mandatory)
970950
where TProperties : IReadOnlyBasicProperties, IAmqpHeader
971951
{

projects/RabbitMQ.Client/client/impl/Connection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ internal void Write(ReadOnlyMemory<byte> memory)
408408
task.AsTask().GetAwaiter().GetResult();
409409
}
410410
}
411-
411+
412412
internal ValueTask WriteAsync(ReadOnlyMemory<byte> memory)
413413
{
414414
return _frameHandler.WriteAsync(memory);

projects/RabbitMQ.Client/client/impl/ISession.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ internal interface ISession
7878
void Transmit<TMethod, THeader>(in TMethod cmd, in THeader header, ReadOnlyMemory<byte> body)
7979
where TMethod : struct, IOutgoingAmqpMethod
8080
where THeader : IAmqpHeader;
81-
81+
8282
ValueTask TransmitAsync<TMethod, THeader>(in TMethod cmd, in THeader header, ReadOnlyMemory<byte> body)
8383
where TMethod : struct, IOutgoingAmqpMethod
8484
where THeader : IAmqpHeader;

projects/RabbitMQ.Client/client/impl/SessionBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ public void Transmit<TMethod, THeader>(in TMethod cmd, in THeader header, ReadOn
162162

163163
Connection.Write(Framing.SerializeToFrames(ref Unsafe.AsRef(cmd), ref Unsafe.AsRef(header), body, ChannelNumber, Connection.MaxPayloadSize));
164164
}
165-
165+
166166
public ValueTask TransmitAsync<TMethod, THeader>(in TMethod cmd, in THeader header, ReadOnlyMemory<byte> body)
167167
where TMethod : struct, IOutgoingAmqpMethod
168168
where THeader : IAmqpHeader

projects/RabbitMQ.Client/client/impl/SocketFrameHandler.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,28 @@ public static async Task TimeoutAfter(this Task task, TimeSpan timeout)
6262
}
6363
#endif
6464
}
65+
66+
public static async ValueTask TimeoutAfter(this ValueTask task, TimeSpan timeout)
67+
{
68+
if (!task.IsCompletedSuccessfully)
69+
{
70+
var actualTask = task.AsTask();
71+
#if NET6_0_OR_GREATER
72+
await actualTask.WaitAsync(timeout).ConfigureAwait(false);
73+
#else
74+
if (actualTask == await Task.WhenAny(actualTask, Task.Delay(timeout)).ConfigureAwait(false))
75+
{
76+
await actualTask.ConfigureAwait(false);
77+
}
78+
else
79+
{
80+
Task supressErrorTask =
81+
actualTask.ContinueWith((t, s) => t.Exception.Handle(e => true), null, CancellationToken.None, TaskContinuationOptions.OnlyOnFaulted | TaskContinuationOptions.ExecuteSynchronously, TaskScheduler.Default);
82+
throw new TimeoutException();
83+
}
84+
#endif
85+
}
86+
}
6587
}
6688

6789
internal sealed class SocketFrameHandler : IFrameHandler

projects/TestApplications/CreateChannel/CreateChannel.csproj

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

3+
<PropertyGroup Condition="$([MSBuild]::IsOSPlatform('Windows'))">
4+
<TargetFrameworks>net6.0;net472</TargetFrameworks>
5+
</PropertyGroup>
6+
7+
<PropertyGroup Condition="!$([MSBuild]::IsOSPlatform('Windows'))">
8+
<TargetFramework>net6.0</TargetFramework>
9+
</PropertyGroup>
10+
311
<PropertyGroup>
412
<OutputType>Exe</OutputType>
5-
<TargetFrameworks>net6.0;net472</TargetFrameworks>
613
</PropertyGroup>
714

815
<ItemGroup>

projects/TestApplications/MassPublish/MassPublish.csproj

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

3+
<PropertyGroup Condition="$([MSBuild]::IsOSPlatform('Windows'))">
4+
<TargetFrameworks>net6.0;net472</TargetFrameworks>
5+
</PropertyGroup>
6+
7+
<PropertyGroup Condition="!$([MSBuild]::IsOSPlatform('Windows'))">
8+
<TargetFramework>net6.0</TargetFramework>
9+
</PropertyGroup>
10+
311
<PropertyGroup>
412
<OutputType>Exe</OutputType>
5-
<TargetFrameworks>net6.0;net472</TargetFrameworks>
613
</PropertyGroup>
714

815
<ItemGroup>

projects/Unit/TestConcurrentAccessWithSharedConnection.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public void TestConcurrentChannelOpenAndPublishingSize1024()
8686
{
8787
TestConcurrentChannelOpenAndPublishingWithBodyOfSize(1024);
8888
}
89-
89+
9090
[Fact]
9191
public Task TestConcurrentChannelOpenAndPublishingWithBlankMessagesAsync()
9292
{
@@ -125,7 +125,7 @@ internal void TestConcurrentChannelOpenAndPublishingWithBodyOfSize(int length, i
125125
{
126126
TestConcurrentChannelOpenAndPublishingWithBody(new byte[length], iterations);
127127
}
128-
128+
129129
internal Task TestConcurrentChannelOpenAndPublishingWithBodyOfSizeAsync(int length, int iterations = 30)
130130
{
131131
return TestConcurrentChannelOpenAndPublishingWithBodyAsync(new byte[length], iterations);
@@ -147,7 +147,7 @@ internal void TestConcurrentChannelOpenAndPublishingWithBody(byte[] body, int it
147147
ch.WaitForConfirmsAsync(cts.Token).GetAwaiter().GetResult();
148148
}, iterations);
149149
}
150-
150+
151151
internal Task TestConcurrentChannelOpenAndPublishingWithBodyAsync(byte[] body, int iterations)
152152
{
153153
return TestConcurrentChannelOperationsAsync(async (conn) =>
@@ -170,7 +170,7 @@ internal void TestConcurrentChannelOperations(Action<IConnection> actions,
170170
{
171171
TestConcurrentChannelOperations(actions, iterations, _completionTimeout);
172172
}
173-
173+
174174
internal Task TestConcurrentChannelOperationsAsync(Func<IConnection, Task> actions, int iterations)
175175
{
176176
return TestConcurrentChannelOperationsAsync(actions, iterations, _completionTimeout);
@@ -198,7 +198,7 @@ internal void TestConcurrentChannelOperations(Action<IConnection> actions,
198198
// closing the connection
199199
Assert.True(_conn.IsOpen);
200200
}
201-
201+
202202
internal async Task TestConcurrentChannelOperationsAsync(Func<IConnection, Task> actions,
203203
int iterations, TimeSpan timeout)
204204
{

projects/Unit/Unit.csproj

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

3-
<PropertyGroup>
3+
<PropertyGroup Condition="$([MSBuild]::IsOSPlatform('Windows'))">
44
<TargetFrameworks>net6.0;net472</TargetFrameworks>
5+
</PropertyGroup>
6+
7+
<PropertyGroup Condition="!$([MSBuild]::IsOSPlatform('Windows'))">
8+
<TargetFramework>net6.0</TargetFramework>
9+
</PropertyGroup>
10+
11+
<PropertyGroup>
512
<AssemblyOriginatorKeyFile>../rabbit.snk</AssemblyOriginatorKeyFile>
613
<SignAssembly>true</SignAssembly>
714
<LangVersion>latest</LangVersion>

0 commit comments

Comments
 (0)