diff --git a/build/dependencies.props b/build/dependencies.props index a204e88755..7588689c0b 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -22,16 +22,16 @@ 2.1.0-preview2-30220 2.1.0-preview2-30220 2.1.0-preview2-30220 - 2.1.0-preview2-30220 + 2.1.0-a-preview2-pk-corefx0-17561 2.1.0-preview2-30220 2.1.0-preview2-30220 0.5.0-preview2-30220 - 2.1.0-preview2-30220 + 2.1.0-a-preview2-pk-corefx0-17561 2.1.0-preview2-30220 2.1.0-preview2-30220 2.1.0-preview2-30220 - 2.1.0-preview2-30220 - 4.5.0-preview2-26224-02 + 2.1.0-a-preview2-pk-corefx0-16561 + 4.5.0-preview2-26308-02 2.1.0-preview2-30220 2.1.0-preview2-30220 2.1.0-preview2-30220 @@ -53,21 +53,21 @@ 2.1.0-preview2-30220 2.1.0-preview2-30220 2.0.0 - 2.1.0-preview2-26225-03 + 2.1.0-preview2-26308-01 15.6.0 4.7.49 1.0.0-rc 10.0.1 1.2.4 - 4.5.0-preview2-26224-02 - 4.5.0-preview2-26224-02 - 4.5.0-preview2-26224-02 - 4.5.0-preview2-26224-02 + 4.5.0-preview2-26308-02 + 4.5.0-preview2-26308-02 + 4.5.0-preview2-26308-02 + 4.5.0-preview2-26308-02 3.1.1 4.3.0 - 4.5.0-preview2-26224-02 - 4.5.0-preview2-26224-02 - 4.5.0-preview2-26224-02 + 4.5.0-preview2-26308-02 + 4.5.0-preview2-26308-02 + 4.5.0-preview2-26308-02 2.3.1 2.4.0-beta.1.build3945 diff --git a/samples/SocketsSample/EndPoints/MessagesEndPoint.cs b/samples/SocketsSample/EndPoints/MessagesEndPoint.cs index 285c3a8212..411f6541ad 100644 --- a/samples/SocketsSample/EndPoints/MessagesEndPoint.cs +++ b/samples/SocketsSample/EndPoints/MessagesEndPoint.cs @@ -65,11 +65,9 @@ private Task Broadcast(string text) private Task Broadcast(byte[] payload) { var tasks = new List(Connections.Count); - async Task ToTask(PipeAwaiter awaiter) => await awaiter; - foreach (var c in Connections) { - tasks.Add(ToTask(c.Transport.Output.WriteAsync(payload))); + tasks.Add(c.Transport.Output.WriteAsync(payload).AsTask()); } return Task.WhenAll(tasks); diff --git a/src/Common/PipeWriterStream.cs b/src/Common/PipeWriterStream.cs index f43f3d68dd..56472af59e 100644 --- a/src/Common/PipeWriterStream.cs +++ b/src/Common/PipeWriterStream.cs @@ -63,11 +63,11 @@ public override Task WriteAsync(byte[] buffer, int offset, int count, Cancellati } #if NETCOREAPP2_1 - public override Task WriteAsync(ReadOnlyMemory source, CancellationToken cancellationToken = default) + public override ValueTask WriteAsync(ReadOnlyMemory source, CancellationToken cancellationToken = default) { _pipeWriter.Write(source.Span); _length += source.Length; - return Task.CompletedTask; + return new ValueTask(Task.CompletedTask); } #endif } diff --git a/src/Common/WebSocketExtensions.cs b/src/Common/WebSocketExtensions.cs index dbbe798c21..06094a8df8 100644 --- a/src/Common/WebSocketExtensions.cs +++ b/src/Common/WebSocketExtensions.cs @@ -20,7 +20,7 @@ public static Task SendAsync(this WebSocket webSocket, ReadOnlySequence bu #if NETCOREAPP2_1 if (buffer.IsSingleSegment) { - return webSocket.SendAsync(buffer.First, webSocketMessageType, endOfMessage: true, cancellationToken); + return webSocket.SendAsync(buffer.First, webSocketMessageType, endOfMessage: true, cancellationToken).AsTask(); } else { diff --git a/src/Microsoft.AspNetCore.SignalR.Common/Internal/Protocol/NegotiationProtocol.cs b/src/Microsoft.AspNetCore.SignalR.Common/Internal/Protocol/NegotiationProtocol.cs index 95e3d44acf..948c06bd91 100644 --- a/src/Microsoft.AspNetCore.SignalR.Common/Internal/Protocol/NegotiationProtocol.cs +++ b/src/Microsoft.AspNetCore.SignalR.Common/Internal/Protocol/NegotiationProtocol.cs @@ -69,7 +69,7 @@ public static bool TryParseMessage(ReadOnlySequence buffer, out Negotiatio } else { - consumed = buffer.GetPosition(separator.Value, 1); + consumed = buffer.GetPosition(1, separator.Value); examined = consumed; } diff --git a/src/Microsoft.AspNetCore.Sockets.Client.Http/HttpConnection.cs b/src/Microsoft.AspNetCore.Sockets.Client.Http/HttpConnection.cs index d4f2f16b63..ddb47474d9 100644 --- a/src/Microsoft.AspNetCore.Sockets.Client.Http/HttpConnection.cs +++ b/src/Microsoft.AspNetCore.Sockets.Client.Http/HttpConnection.cs @@ -206,7 +206,7 @@ private async Task StartAsyncInternal() } } } - + if (_transport == null) { throw new InvalidOperationException("Unable to connect to the server with any of the available transports."); @@ -367,7 +367,7 @@ private static Uri CreateConnectUrl(Uri url, string connectionId) private async Task StartTransport(Uri connectUrl, TransportType transportType) { - var options = new PipeOptions(readerScheduler: PipeScheduler.ThreadPool); + var options = new PipeOptions(writerScheduler: PipeScheduler.Inline, readerScheduler: PipeScheduler.ThreadPool, useSynchronizationContext: false); var pair = DuplexPipe.CreateConnectionPair(options, options); _transportChannel = pair.Transport; _transport = _transportFactory.CreateTransport(transportType); diff --git a/src/Microsoft.AspNetCore.Sockets.Client.Http/Internal/StreamExtensions.cs b/src/Microsoft.AspNetCore.Sockets.Client.Http/Internal/StreamExtensions.cs index 7c746010dc..3da3700313 100644 --- a/src/Microsoft.AspNetCore.Sockets.Client.Http/Internal/StreamExtensions.cs +++ b/src/Microsoft.AspNetCore.Sockets.Client.Http/Internal/StreamExtensions.cs @@ -64,7 +64,7 @@ private static async Task CopyMultipleToStreamAsync(this ReadOnlySequence private static async Task WriteToStream(Stream stream, ReadOnlyMemory readOnlyMemory) { var memory = MemoryMarshal.AsMemory(readOnlyMemory); - if (memory.TryGetArray(out ArraySegment data)) + if (MemoryMarshal.TryGetArray(memory, out ArraySegment data)) { await stream.WriteAsync(data.Array, data.Offset, data.Count) .ConfigureAwait(continueOnCapturedContext: false); diff --git a/src/Microsoft.AspNetCore.Sockets.Client.Http/ServerSentEventsMessageParser.cs b/src/Microsoft.AspNetCore.Sockets.Client.Http/ServerSentEventsMessageParser.cs index fa9b957284..4346696f48 100644 --- a/src/Microsoft.AspNetCore.Sockets.Client.Http/ServerSentEventsMessageParser.cs +++ b/src/Microsoft.AspNetCore.Sockets.Client.Http/ServerSentEventsMessageParser.cs @@ -48,7 +48,7 @@ public ParseResult ParseMessage(ReadOnlySequence buffer, out SequencePosit return ParseResult.Incomplete; } - lineEnd = buffer.GetPosition(lineEnd, 1); + lineEnd = buffer.GetPosition(1, lineEnd); var line = ConvertBufferToSpan(buffer.Slice(start, lineEnd)); buffer = buffer.Slice(line.Length); diff --git a/src/Microsoft.AspNetCore.Sockets.Client.Http/WebSocketsTransport.cs b/src/Microsoft.AspNetCore.Sockets.Client.Http/WebSocketsTransport.cs index 0837e138b9..f43d7f0b4e 100644 --- a/src/Microsoft.AspNetCore.Sockets.Client.Http/WebSocketsTransport.cs +++ b/src/Microsoft.AspNetCore.Sockets.Client.Http/WebSocketsTransport.cs @@ -5,6 +5,7 @@ using System.Diagnostics; using System.IO.Pipelines; using System.Net.WebSockets; +using System.Runtime.InteropServices; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Sockets.Client.Http; @@ -151,7 +152,7 @@ private async Task StartReceiving(WebSocket socket) #if NETCOREAPP2_1 var receiveResult = await socket.ReceiveAsync(memory, CancellationToken.None); #else - var isArray = memory.TryGetArray(out var arraySegment); + var isArray = MemoryMarshal.TryGetArray(memory, out var arraySegment); Debug.Assert(isArray); // Exceptions are handled above where the send and receive tasks are being run. diff --git a/src/Microsoft.AspNetCore.Sockets.Http/HttpConnectionDispatcher.cs b/src/Microsoft.AspNetCore.Sockets.Http/HttpConnectionDispatcher.cs index c6e1a7a3cc..f3f6eaa047 100644 --- a/src/Microsoft.AspNetCore.Sockets.Http/HttpConnectionDispatcher.cs +++ b/src/Microsoft.AspNetCore.Sockets.Http/HttpConnectionDispatcher.cs @@ -514,8 +514,8 @@ private async Task GetConnectionAsync(HttpContext cont private DefaultConnectionContext CreateConnectionInternal(HttpSocketOptions options) { - var transportPipeOptions = new PipeOptions(pauseWriterThreshold: options.TransportMaxBufferSize, resumeWriterThreshold: options.TransportMaxBufferSize / 2, readerScheduler: PipeScheduler.ThreadPool); - var appPipeOptions = new PipeOptions(pauseWriterThreshold: options.ApplicationMaxBufferSize, resumeWriterThreshold: options.ApplicationMaxBufferSize / 2, readerScheduler: PipeScheduler.ThreadPool); + var transportPipeOptions = new PipeOptions(pauseWriterThreshold: options.TransportMaxBufferSize, resumeWriterThreshold: options.TransportMaxBufferSize / 2, readerScheduler: PipeScheduler.ThreadPool, useSynchronizationContext: false); + var appPipeOptions = new PipeOptions(pauseWriterThreshold: options.ApplicationMaxBufferSize, resumeWriterThreshold: options.ApplicationMaxBufferSize / 2, readerScheduler: PipeScheduler.ThreadPool, useSynchronizationContext: false); return _manager.CreateConnection(transportPipeOptions, appPipeOptions); } diff --git a/src/Microsoft.AspNetCore.Sockets.Http/Internal/Transports/WebSocketsTransport.cs b/src/Microsoft.AspNetCore.Sockets.Http/Internal/Transports/WebSocketsTransport.cs index 01e7eb8fd2..b054fb6c49 100644 --- a/src/Microsoft.AspNetCore.Sockets.Http/Internal/Transports/WebSocketsTransport.cs +++ b/src/Microsoft.AspNetCore.Sockets.Http/Internal/Transports/WebSocketsTransport.cs @@ -5,6 +5,7 @@ using System.Diagnostics; using System.IO.Pipelines; using System.Net.WebSockets; +using System.Runtime.InteropServices; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; @@ -143,7 +144,7 @@ private async Task StartReceiving(WebSocket socket) #if NETCOREAPP2_1 var receiveResult = await socket.ReceiveAsync(memory, CancellationToken.None); #else - var isArray = memory.TryGetArray(out var arraySegment); + var isArray = MemoryMarshal.TryGetArray(memory, out var arraySegment); Debug.Assert(isArray); // Exceptions are handled above where the send and receive tasks are being run. diff --git a/test/Microsoft.AspNetCore.SignalR.Client.FunctionalTests/HubConnectionTests.cs b/test/Microsoft.AspNetCore.SignalR.Client.FunctionalTests/HubConnectionTests.cs index 24d82ad1d9..1e8d72cbe4 100644 --- a/test/Microsoft.AspNetCore.SignalR.Client.FunctionalTests/HubConnectionTests.cs +++ b/test/Microsoft.AspNetCore.SignalR.Client.FunctionalTests/HubConnectionTests.cs @@ -333,7 +333,7 @@ public async Task CanCloseStreamMethodEarly(IHubProtocol protocol, TransportType var channel = await connection.StreamAsync("Stream", 1000, cts.Token).OrTimeout(); - await channel.WaitToReadAsync().OrTimeout(); + await channel.WaitToReadAsync().AsTask().OrTimeout(); cts.Cancel(); var results = await channel.ReadAllAsync().OrTimeout(); @@ -369,7 +369,7 @@ public async Task StreamDoesNotStartIfTokenAlreadyCanceled(IHubProtocol protocol var channel = await connection.StreamAsync("Stream", 5, cts.Token).OrTimeout(); - await Assert.ThrowsAnyAsync(() => channel.WaitToReadAsync().OrTimeout()); + await Assert.ThrowsAnyAsync(() => channel.WaitToReadAsync().AsTask().OrTimeout()); } catch (Exception ex) { diff --git a/test/Microsoft.AspNetCore.SignalR.Client.Tests/ServerSentEventsParserTests.cs b/test/Microsoft.AspNetCore.SignalR.Client.Tests/ServerSentEventsParserTests.cs index 8b192f1d64..6c950800f6 100644 --- a/test/Microsoft.AspNetCore.SignalR.Client.Tests/ServerSentEventsParserTests.cs +++ b/test/Microsoft.AspNetCore.SignalR.Client.Tests/ServerSentEventsParserTests.cs @@ -186,7 +186,7 @@ public async Task ParseMultipleMessagesText(string message1, string message2) var parseResult = parser.ParseMessage(result.Buffer, out var consumed, out var examined, out var message); Assert.Equal(ServerSentEventsMessageParser.ParseResult.Completed, parseResult); Assert.Equal("foo", Encoding.UTF8.GetString(message)); - Assert.Equal(consumed, result.Buffer.GetPosition(result.Buffer.Start, message1.Length)); + Assert.Equal(consumed, result.Buffer.GetPosition(message1.Length)); pipe.Reader.AdvanceTo(consumed, examined); Assert.Equal(consumed, examined); diff --git a/test/Microsoft.AspNetCore.SignalR.Client.Tests/TestConnection.cs b/test/Microsoft.AspNetCore.SignalR.Client.Tests/TestConnection.cs index a5651837e3..dcd71f92d2 100644 --- a/test/Microsoft.AspNetCore.SignalR.Client.Tests/TestConnection.cs +++ b/test/Microsoft.AspNetCore.SignalR.Client.Tests/TestConnection.cs @@ -109,7 +109,7 @@ public Task ReceiveJsonMessage(object jsonObject) var json = JsonConvert.SerializeObject(jsonObject, Formatting.None); var bytes = FormatMessageToArray(Encoding.UTF8.GetBytes(json)); - return _receivedMessages.Writer.WriteAsync(bytes); + return _receivedMessages.Writer.WriteAsync(bytes).AsTask(); } private byte[] FormatMessageToArray(byte[] message) diff --git a/test/Microsoft.AspNetCore.SignalR.Common.Tests/Internal/Protocol/MessagePackHubProtocolTests.cs b/test/Microsoft.AspNetCore.SignalR.Common.Tests/Internal/Protocol/MessagePackHubProtocolTests.cs index 6f0a46311c..4d77154c8f 100644 --- a/test/Microsoft.AspNetCore.SignalR.Common.Tests/Internal/Protocol/MessagePackHubProtocolTests.cs +++ b/test/Microsoft.AspNetCore.SignalR.Common.Tests/Internal/Protocol/MessagePackHubProtocolTests.cs @@ -303,7 +303,7 @@ public void WriteMessages(string testDataName) AssertMessages(testData.Encoded, bytes); // Unframe the message to check the binary encoding - var byteSpan = bytes.AsReadOnlySpan(); + ReadOnlySpan byteSpan = bytes.AsSpan(); Assert.True(BinaryMessageParser.TryParseMessage(ref byteSpan, out var unframed)); // Check the baseline binary encoding, use Assert.True in order to configure the error message diff --git a/test/Microsoft.AspNetCore.SignalR.Tests.Utils/PipeReaderExtensions.cs b/test/Microsoft.AspNetCore.SignalR.Tests.Utils/PipeReaderExtensions.cs index 87575a3252..11b0da30b4 100644 --- a/test/Microsoft.AspNetCore.SignalR.Tests.Utils/PipeReaderExtensions.cs +++ b/test/Microsoft.AspNetCore.SignalR.Tests.Utils/PipeReaderExtensions.cs @@ -61,7 +61,7 @@ public static async Task ConsumeAsync(this PipeReader pipeReader, int numBytes) pipeReader.AdvanceTo(result.Buffer.Start, result.Buffer.End); continue; } - pipeReader.AdvanceTo(result.Buffer.GetPosition(result.Buffer.Start, numBytes)); + pipeReader.AdvanceTo(result.Buffer.GetPosition(numBytes)); break; } } diff --git a/test/Microsoft.AspNetCore.SignalR.Tests.Utils/TaskExtensions.cs b/test/Microsoft.AspNetCore.SignalR.Tests.Utils/TaskExtensions.cs index 501df86866..65f252f56a 100644 --- a/test/Microsoft.AspNetCore.SignalR.Tests.Utils/TaskExtensions.cs +++ b/test/Microsoft.AspNetCore.SignalR.Tests.Utils/TaskExtensions.cs @@ -93,10 +93,5 @@ private static string GetMessage(string memberName, string filePath, int? lineNu return "Operation timed out"; } } - - public static async Task AsTask(this PipeAwaiter awaiter) - { - return await awaiter; - } } } diff --git a/test/Microsoft.AspNetCore.Sockets.Tests/HttpConnectionDispatcherTests.cs b/test/Microsoft.AspNetCore.Sockets.Tests/HttpConnectionDispatcherTests.cs index 99d49bcd4a..04b43d08df 100644 --- a/test/Microsoft.AspNetCore.Sockets.Tests/HttpConnectionDispatcherTests.cs +++ b/test/Microsoft.AspNetCore.Sockets.Tests/HttpConnectionDispatcherTests.cs @@ -1362,14 +1362,8 @@ public class BlockingEndPoint : EndPoint { public override Task OnConnectedAsync(ConnectionContext connection) { - var waitHandle = new ManualResetEventSlim(); - var awaiter = connection.Transport.Input.ReadAsync(); - awaiter.OnCompleted(waitHandle.Set); - waitHandle.Wait(); - - var result = awaiter.GetResult(); + var result = connection.Transport.Input.ReadAsync().AsTask().Result; connection.Transport.Input.AdvanceTo(result.Buffer.End); - return Task.CompletedTask; } } diff --git a/test/Microsoft.AspNetCore.Sockets.Tests/ServerSentEventsTests.cs b/test/Microsoft.AspNetCore.Sockets.Tests/ServerSentEventsTests.cs index 426d354c09..0ecb997412 100644 --- a/test/Microsoft.AspNetCore.Sockets.Tests/ServerSentEventsTests.cs +++ b/test/Microsoft.AspNetCore.Sockets.Tests/ServerSentEventsTests.cs @@ -58,7 +58,7 @@ public async Task SSEWritesMessages() var connection = new DefaultConnectionContext("foo", pair.Transport, pair.Application); var context = new DefaultHttpContext(); - + var ms = new MemoryStream(); context.Response.Body = ms; var sse = new ServerSentEventsTransport(connection.Application.Input, connectionId: string.Empty, loggerFactory: new LoggerFactory()); @@ -66,12 +66,9 @@ public async Task SSEWritesMessages() var task = sse.ProcessRequestAsync(context, context.RequestAborted); await connection.Transport.Output.WriteAsync(Encoding.ASCII.GetBytes("Hello")); - - Assert.Equal(":\r\ndata: Hello\r\n\r\n", Encoding.ASCII.GetString(ms.ToArray())); - connection.Transport.Output.Complete(); - await task.OrTimeout(); + Assert.Equal(":\r\ndata: Hello\r\n\r\n", Encoding.ASCII.GetString(ms.ToArray())); } [Theory]