Skip to content
This repository has been archived by the owner on Dec 18, 2018. It is now read-only.

Update to new corefx #1561

Merged
merged 1 commit into from
Mar 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions build/dependencies.props
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@
<MicrosoftAspNetCoreHttpPackageVersion>2.1.0-preview2-30220</MicrosoftAspNetCoreHttpPackageVersion>
<MicrosoftAspNetCoreIdentityEntityFrameworkCorePackageVersion>2.1.0-preview2-30220</MicrosoftAspNetCoreIdentityEntityFrameworkCorePackageVersion>
<MicrosoftAspNetCoreMvcPackageVersion>2.1.0-preview2-30220</MicrosoftAspNetCoreMvcPackageVersion>
<MicrosoftAspNetCoreProtocolsAbstractionsPackageVersion>2.1.0-preview2-30220</MicrosoftAspNetCoreProtocolsAbstractionsPackageVersion>
<MicrosoftAspNetCoreProtocolsAbstractionsPackageVersion>2.1.0-a-preview2-pk-corefx0-17561</MicrosoftAspNetCoreProtocolsAbstractionsPackageVersion>
<MicrosoftAspNetCoreRoutingPackageVersion>2.1.0-preview2-30220</MicrosoftAspNetCoreRoutingPackageVersion>
<MicrosoftAspNetCoreServerIISIntegrationPackageVersion>2.1.0-preview2-30220</MicrosoftAspNetCoreServerIISIntegrationPackageVersion>
<MicrosoftAspNetCoreServerIntegrationTestingPackageVersion>0.5.0-preview2-30220</MicrosoftAspNetCoreServerIntegrationTestingPackageVersion>
<MicrosoftAspNetCoreServerKestrelPackageVersion>2.1.0-preview2-30220</MicrosoftAspNetCoreServerKestrelPackageVersion>
<MicrosoftAspNetCoreServerKestrelPackageVersion>2.1.0-a-preview2-pk-corefx0-17561</MicrosoftAspNetCoreServerKestrelPackageVersion>
<MicrosoftAspNetCoreStaticFilesPackageVersion>2.1.0-preview2-30220</MicrosoftAspNetCoreStaticFilesPackageVersion>
<MicrosoftAspNetCoreTestHostPackageVersion>2.1.0-preview2-30220</MicrosoftAspNetCoreTestHostPackageVersion>
<MicrosoftAspNetCoreTestingPackageVersion>2.1.0-preview2-30220</MicrosoftAspNetCoreTestingPackageVersion>
<MicrosoftAspNetCoreWebSocketsPackageVersion>2.1.0-preview2-30220</MicrosoftAspNetCoreWebSocketsPackageVersion>
<MicrosoftCSharpPackageVersion>4.5.0-preview2-26224-02</MicrosoftCSharpPackageVersion>
<MicrosoftAspNetCoreWebSocketsPackageVersion>2.1.0-a-preview2-pk-corefx0-16561</MicrosoftAspNetCoreWebSocketsPackageVersion>
<MicrosoftCSharpPackageVersion>4.5.0-preview2-26308-02</MicrosoftCSharpPackageVersion>
<MicrosoftEntityFrameworkCoreDesignPackageVersion>2.1.0-preview2-30220</MicrosoftEntityFrameworkCoreDesignPackageVersion>
<MicrosoftEntityFrameworkCoreSqlServerPackageVersion>2.1.0-preview2-30220</MicrosoftEntityFrameworkCoreSqlServerPackageVersion>
<MicrosoftEntityFrameworkCoreToolsPackageVersion>2.1.0-preview2-30220</MicrosoftEntityFrameworkCoreToolsPackageVersion>
Expand All @@ -53,21 +53,21 @@
<MicrosoftExtensionsSecurityHelperSourcesPackageVersion>2.1.0-preview2-30220</MicrosoftExtensionsSecurityHelperSourcesPackageVersion>
<MicrosoftExtensionsValueStopwatchSourcesPackageVersion>2.1.0-preview2-30220</MicrosoftExtensionsValueStopwatchSourcesPackageVersion>
<MicrosoftNETCoreApp20PackageVersion>2.0.0</MicrosoftNETCoreApp20PackageVersion>
<MicrosoftNETCoreApp21PackageVersion>2.1.0-preview2-26225-03</MicrosoftNETCoreApp21PackageVersion>
<MicrosoftNETCoreApp21PackageVersion>2.1.0-preview2-26308-01</MicrosoftNETCoreApp21PackageVersion>
<MicrosoftNETTestSdkPackageVersion>15.6.0</MicrosoftNETTestSdkPackageVersion>
<MoqPackageVersion>4.7.49</MoqPackageVersion>
<MsgPackCliPackageVersion>1.0.0-rc</MsgPackCliPackageVersion>
<NewtonsoftJsonPackageVersion>10.0.1</NewtonsoftJsonPackageVersion>
<StackExchangeRedisStrongNamePackageVersion>1.2.4</StackExchangeRedisStrongNamePackageVersion>
<SystemBuffersPackageVersion>4.5.0-preview2-26224-02</SystemBuffersPackageVersion>
<SystemIOPipelinesPackageVersion>4.5.0-preview2-26224-02</SystemIOPipelinesPackageVersion>
<SystemMemoryPackageVersion>4.5.0-preview2-26224-02</SystemMemoryPackageVersion>
<SystemNumericsVectorsPackageVersion>4.5.0-preview2-26224-02</SystemNumericsVectorsPackageVersion>
<SystemBuffersPackageVersion>4.5.0-preview2-26308-02</SystemBuffersPackageVersion>
<SystemIOPipelinesPackageVersion>4.5.0-preview2-26308-02</SystemIOPipelinesPackageVersion>
<SystemMemoryPackageVersion>4.5.0-preview2-26308-02</SystemMemoryPackageVersion>
<SystemNumericsVectorsPackageVersion>4.5.0-preview2-26308-02</SystemNumericsVectorsPackageVersion>
<SystemReactiveLinqPackageVersion>3.1.1</SystemReactiveLinqPackageVersion>
<SystemReflectionEmitPackageVersion>4.3.0</SystemReflectionEmitPackageVersion>
<SystemRuntimeCompilerServicesUnsafePackageVersion>4.5.0-preview2-26224-02</SystemRuntimeCompilerServicesUnsafePackageVersion>
<SystemThreadingChannelsPackageVersion>4.5.0-preview2-26224-02</SystemThreadingChannelsPackageVersion>
<SystemThreadingTasksExtensionsPackageVersion>4.5.0-preview2-26224-02</SystemThreadingTasksExtensionsPackageVersion>
<SystemRuntimeCompilerServicesUnsafePackageVersion>4.5.0-preview2-26308-02</SystemRuntimeCompilerServicesUnsafePackageVersion>
<SystemThreadingChannelsPackageVersion>4.5.0-preview2-26308-02</SystemThreadingChannelsPackageVersion>
<SystemThreadingTasksExtensionsPackageVersion>4.5.0-preview2-26308-02</SystemThreadingTasksExtensionsPackageVersion>
<XunitPackageVersion>2.3.1</XunitPackageVersion>
<XunitRunnerVisualStudioPackageVersion>2.4.0-beta.1.build3945</XunitRunnerVisualStudioPackageVersion>
</PropertyGroup>
Expand Down
4 changes: 1 addition & 3 deletions samples/SocketsSample/EndPoints/MessagesEndPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,9 @@ private Task Broadcast(string text)
private Task Broadcast(byte[] payload)
{
var tasks = new List<Task>(Connections.Count);
async Task<FlushResult> ToTask(PipeAwaiter<FlushResult> 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);
Expand Down
4 changes: 2 additions & 2 deletions src/Common/PipeWriterStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ public override Task WriteAsync(byte[] buffer, int offset, int count, Cancellati
}

#if NETCOREAPP2_1
public override Task WriteAsync(ReadOnlyMemory<byte> source, CancellationToken cancellationToken = default)
public override ValueTask WriteAsync(ReadOnlyMemory<byte> source, CancellationToken cancellationToken = default)
{
_pipeWriter.Write(source.Span);
_length += source.Length;
return Task.CompletedTask;
return new ValueTask(Task.CompletedTask);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return default;

}
#endif
}
Expand Down
2 changes: 1 addition & 1 deletion src/Common/WebSocketExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static Task SendAsync(this WebSocket webSocket, ReadOnlySequence<byte> 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();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make this method return ValueTask.

}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public static bool TryParseMessage(ReadOnlySequence<byte> buffer, out Negotiatio
}
else
{
consumed = buffer.GetPosition(separator.Value, 1);
consumed = buffer.GetPosition(1, separator.Value);
examined = consumed;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ private static async Task CopyMultipleToStreamAsync(this ReadOnlySequence<byte>
private static async Task WriteToStream(Stream stream, ReadOnlyMemory<byte> readOnlyMemory)
{
var memory = MemoryMarshal.AsMemory(readOnlyMemory);
if (memory.TryGetArray(out ArraySegment<byte> data))
if (MemoryMarshal.TryGetArray(memory, out ArraySegment<byte> data))
{
await stream.WriteAsync(data.Array, data.Offset, data.Count)
.ConfigureAwait(continueOnCapturedContext: false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public ParseResult ParseMessage(ReadOnlySequence<byte> 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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<byte>(memory, out var arraySegment);
Debug.Assert(isArray);

// Exceptions are handled above where the send and receive tasks are being run.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -514,8 +514,8 @@ private async Task<DefaultConnectionContext> 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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<byte>(memory, out var arraySegment);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the <byte> not inferrable?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first parameter type is ReadOnlyMemory, it's either inference or implicit conversion, unfortunately.

Debug.Assert(isArray);

// Exceptions are handled above where the send and receive tasks are being run.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ public async Task CanCloseStreamMethodEarly(IHubProtocol protocol, TransportType

var channel = await connection.StreamAsync<int>("Stream", 1000, cts.Token).OrTimeout();

await channel.WaitToReadAsync().OrTimeout();
await channel.WaitToReadAsync().AsTask().OrTimeout();
cts.Cancel();

var results = await channel.ReadAllAsync().OrTimeout();
Expand Down Expand Up @@ -369,7 +369,7 @@ public async Task StreamDoesNotStartIfTokenAlreadyCanceled(IHubProtocol protocol

var channel = await connection.StreamAsync<int>("Stream", 5, cts.Token).OrTimeout();

await Assert.ThrowsAnyAsync<OperationCanceledException>(() => channel.WaitToReadAsync().OrTimeout());
await Assert.ThrowsAnyAsync<OperationCanceledException>(() => channel.WaitToReadAsync().AsTask().OrTimeout());
}
catch (Exception ex)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<byte> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,5 @@ private static string GetMessage(string memberName, string filePath, int? lineNu
return "Operation timed out";
}
}

public static async Task<T> AsTask<T>(this PipeAwaiter<T> awaiter)
{
return await awaiter;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,20 +58,17 @@ 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());

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]
Expand Down