From 7db1eb8f256dc2ce1d579dddccc758aa2a310c9f Mon Sep 17 00:00:00 2001 From: David Fowler Date: Wed, 2 Nov 2016 22:02:29 -0700 Subject: [PATCH] Add Async suffix to everything --- samples/ChatSample/Hubs/Chat.cs | 2 +- .../SocketsSample/EndPoints/ChatEndPoint.cs | 2 +- samples/SocketsSample/Hubs/Chat.cs | 6 ++--- .../SocketsSample/LineInvocationAdapter.cs | 6 ++--- .../Protobuf/ProtobufInvocationAdapter.cs | 6 ++--- .../RedisHubLifetimeManager.cs | 14 +++++----- .../DefaultHubLifetimeManager.cs | 16 ++++++------ .../HubEndPoint.cs | 10 ++----- .../HubLifetimeManager.cs | 12 ++++----- .../IClientProxy.cs | 2 +- .../IInvocationAdapter.cs | 6 ++--- .../JsonNetInvocationAdapter.cs | 6 ++--- src/Microsoft.AspNetCore.SignalR/Proxies.cs | 20 +++++++------- .../RpcEndpoint.cs | 6 ++--- .../SignalRAppBuilderExtensions.cs | 1 - src/Microsoft.AspNetCore.Sockets/EndPoint.cs | 2 +- .../HttpConnectionDispatcher.cs | 10 +++---- .../HttpDispatcherAppBuilderExtensions.cs | 26 +++++++++---------- .../IHttpTransport.cs | 2 +- .../LongPolling.cs | 2 +- .../ServerSentEvents.cs | 2 +- .../WebSockets.cs | 2 +- .../HttpConnectionDispatcherTests.cs | 10 +++---- .../LongPollingTests.cs | 4 +-- .../ServerSentEventsTests.cs | 4 +-- 25 files changed, 86 insertions(+), 93 deletions(-) diff --git a/samples/ChatSample/Hubs/Chat.cs b/samples/ChatSample/Hubs/Chat.cs index f54cc2cc28..7864953f6d 100644 --- a/samples/ChatSample/Hubs/Chat.cs +++ b/samples/ChatSample/Hubs/Chat.cs @@ -28,7 +28,7 @@ namespace ChatSample.Hubs public async Task Send(string message) { - await Clients.All.Invoke("Send", $"{Context.User.Identity.Name}: {message}"); + await Clients.All.InvokeAsync("Send", $"{Context.User.Identity.Name}: {message}"); } } } diff --git a/samples/SocketsSample/EndPoints/ChatEndPoint.cs b/samples/SocketsSample/EndPoints/ChatEndPoint.cs index f78f7a33ba..a51d69688f 100644 --- a/samples/SocketsSample/EndPoints/ChatEndPoint.cs +++ b/samples/SocketsSample/EndPoints/ChatEndPoint.cs @@ -10,7 +10,7 @@ namespace SocketsSample { public ConnectionList Connections { get; } = new ConnectionList(); - public override async Task OnConnected(Connection connection) + public override async Task OnConnectedAsync(Connection connection) { Connections.Add(connection); diff --git a/samples/SocketsSample/Hubs/Chat.cs b/samples/SocketsSample/Hubs/Chat.cs index e9735b7c15..253d661596 100644 --- a/samples/SocketsSample/Hubs/Chat.cs +++ b/samples/SocketsSample/Hubs/Chat.cs @@ -8,17 +8,17 @@ namespace SocketsSample.Hubs { public override async Task OnConnectedAsync() { - await Clients.All.Invoke("Send", Context.Connection.ConnectionId + " joined"); + await Clients.All.InvokeAsync("Send", Context.Connection.ConnectionId + " joined"); } public override async Task OnDisconnectedAsync() { - await Clients.All.Invoke("Send", Context.Connection.ConnectionId + " left"); + await Clients.All.InvokeAsync("Send", Context.Connection.ConnectionId + " left"); } public Task Send(string message) { - return Clients.All.Invoke("Send", Context.ConnectionId + ": " + message); + return Clients.All.InvokeAsync("Send", Context.ConnectionId + ": " + message); } } } diff --git a/samples/SocketsSample/LineInvocationAdapter.cs b/samples/SocketsSample/LineInvocationAdapter.cs index 15ede4b2c2..8c6cbb7411 100644 --- a/samples/SocketsSample/LineInvocationAdapter.cs +++ b/samples/SocketsSample/LineInvocationAdapter.cs @@ -9,7 +9,7 @@ namespace SocketsSample { public class LineInvocationAdapter : IInvocationAdapter { - public async Task ReadInvocationDescriptor(Stream stream, Func getParams) + public async Task ReadInvocationDescriptorAsync(Stream stream, Func getParams) { var streamReader = new StreamReader(stream); var line = await streamReader.ReadLineAsync(); @@ -30,13 +30,13 @@ namespace SocketsSample }; } - public async Task WriteInvocationDescriptor(InvocationDescriptor invocationDescriptor, Stream stream) + public async Task WriteInvocationDescriptorAsync(InvocationDescriptor invocationDescriptor, Stream stream) { var msg = $"CI{invocationDescriptor.Id},M{invocationDescriptor.Method},{string.Join(",", invocationDescriptor.Arguments.Select(a => a.ToString()))}\n"; await WriteAsync(msg, stream); } - public async Task WriteInvocationResult(InvocationResultDescriptor resultDescriptor, Stream stream) + public async Task WriteInvocationResultAsync(InvocationResultDescriptor resultDescriptor, Stream stream) { if (string.IsNullOrEmpty(resultDescriptor.Error)) { diff --git a/samples/SocketsSample/Protobuf/ProtobufInvocationAdapter.cs b/samples/SocketsSample/Protobuf/ProtobufInvocationAdapter.cs index e6740d615d..020a0ee2cc 100644 --- a/samples/SocketsSample/Protobuf/ProtobufInvocationAdapter.cs +++ b/samples/SocketsSample/Protobuf/ProtobufInvocationAdapter.cs @@ -16,7 +16,7 @@ namespace SocketsSample.Protobuf _serviceProvider = serviceProvider; } - public async Task ReadInvocationDescriptor(Stream stream, Func getParams) + public async Task ReadInvocationDescriptorAsync(Stream stream, Func getParams) { return await Task.Run(() => CreateInvocationDescriptorInt(stream, getParams)); } @@ -59,7 +59,7 @@ namespace SocketsSample.Protobuf return Task.FromResult(invocationDescriptor); } - public async Task WriteInvocationResult(InvocationResultDescriptor resultDescriptor, Stream stream) + public async Task WriteInvocationResultAsync(InvocationResultDescriptor resultDescriptor, Stream stream) { var outputStream = new CodedOutputStream(stream, leaveOpen: true); outputStream.WriteMessage(new RpcMessageKind() { MessageKind = RpcMessageKind.Types.Kind.Result }); @@ -101,7 +101,7 @@ namespace SocketsSample.Protobuf await stream.FlushAsync(); } - public async Task WriteInvocationDescriptor(InvocationDescriptor invocationDescriptor, Stream stream) + public async Task WriteInvocationDescriptorAsync(InvocationDescriptor invocationDescriptor, Stream stream) { var outputStream = new CodedOutputStream(stream, leaveOpen: true); outputStream.WriteMessage(new RpcMessageKind() { MessageKind = RpcMessageKind.Types.Kind.Invocation }); diff --git a/src/Microsoft.AspNetCore.SignalR.Redis/RedisHubLifetimeManager.cs b/src/Microsoft.AspNetCore.SignalR.Redis/RedisHubLifetimeManager.cs index ae03a41537..3f3059c5fa 100644 --- a/src/Microsoft.AspNetCore.SignalR.Redis/RedisHubLifetimeManager.cs +++ b/src/Microsoft.AspNetCore.SignalR.Redis/RedisHubLifetimeManager.cs @@ -31,7 +31,7 @@ namespace Microsoft.AspNetCore.SignalR.Redis _bus = _redisServerConnection.GetSubscriber(); } - public override Task InvokeAll(string methodName, params object[] args) + public override Task InvokeAllAsync(string methodName, params object[] args) { var message = new InvocationDescriptor { @@ -42,7 +42,7 @@ namespace Microsoft.AspNetCore.SignalR.Redis return PublishAsync(typeof(THub).Name, message); } - public override Task InvokeConnection(string connectionId, string methodName, params object[] args) + public override Task InvokeConnectionAsync(string connectionId, string methodName, params object[] args) { var message = new InvocationDescriptor { @@ -53,7 +53,7 @@ namespace Microsoft.AspNetCore.SignalR.Redis return PublishAsync(typeof(THub) + "." + connectionId, message); } - public override Task InvokeGroup(string groupName, string methodName, params object[] args) + public override Task InvokeGroupAsync(string groupName, string methodName, params object[] args) { var message = new InvocationDescriptor { @@ -64,7 +64,7 @@ namespace Microsoft.AspNetCore.SignalR.Redis return PublishAsync(typeof(THub) + "." + groupName, message); } - public override Task InvokeUser(string userId, string methodName, params object[] args) + public override Task InvokeUserAsync(string userId, string methodName, params object[] args) { var message = new InvocationDescriptor { @@ -83,7 +83,7 @@ namespace Microsoft.AspNetCore.SignalR.Redis // BAD using (var ms = new MemoryStream()) { - invocationAdapter.WriteInvocationDescriptor(message, ms); + invocationAdapter.WriteInvocationDescriptorAsync(message, ms); return _bus.PublishAsync(channel, ms.ToArray()); } @@ -113,13 +113,13 @@ namespace Microsoft.AspNetCore.SignalR.Redis return Task.CompletedTask; } - public override Task AddGroup(Connection connection, string groupName) + public override Task AddGroupAsync(Connection connection, string groupName) { var key = typeof(THub).Name + "." + groupName; return SubscribeAsync(key, connection); } - public override Task RemoveGroup(Connection connection, string groupName) + public override Task RemoveGroupAsync(Connection connection, string groupName) { var key = typeof(THub) + "." + groupName; return UnsubscribeAsync(key, connection); diff --git a/src/Microsoft.AspNetCore.SignalR/DefaultHubLifetimeManager.cs b/src/Microsoft.AspNetCore.SignalR/DefaultHubLifetimeManager.cs index 1d5a8185e9..2aca17d8c7 100644 --- a/src/Microsoft.AspNetCore.SignalR/DefaultHubLifetimeManager.cs +++ b/src/Microsoft.AspNetCore.SignalR/DefaultHubLifetimeManager.cs @@ -17,7 +17,7 @@ namespace Microsoft.AspNetCore.SignalR _registry = registry; } - public override Task AddGroup(Connection connection, string groupName) + public override Task AddGroupAsync(Connection connection, string groupName) { var groups = connection.Metadata.GetOrAdd("groups", k => new HashSet()); @@ -29,7 +29,7 @@ namespace Microsoft.AspNetCore.SignalR return Task.CompletedTask; } - public override Task RemoveGroup(Connection connection, string groupName) + public override Task RemoveGroupAsync(Connection connection, string groupName) { var groups = connection.Metadata.Get>("groups"); @@ -41,7 +41,7 @@ namespace Microsoft.AspNetCore.SignalR return Task.CompletedTask; } - public override Task InvokeAll(string methodName, params object[] args) + public override Task InvokeAllAsync(string methodName, params object[] args) { return InvokeAllWhere(methodName, args, c => true); } @@ -65,13 +65,13 @@ namespace Microsoft.AspNetCore.SignalR var invocationAdapter = _registry.GetInvocationAdapter((string)connection.Metadata["formatType"]); - tasks.Add(invocationAdapter.WriteInvocationDescriptor(message, connection.Channel.GetStream())); + tasks.Add(invocationAdapter.WriteInvocationDescriptorAsync(message, connection.Channel.GetStream())); } return Task.WhenAll(tasks); } - public override Task InvokeConnection(string connectionId, string methodName, params object[] args) + public override Task InvokeConnectionAsync(string connectionId, string methodName, params object[] args) { var connection = _connections[connectionId]; @@ -83,10 +83,10 @@ namespace Microsoft.AspNetCore.SignalR Arguments = args }; - return invocationAdapter.WriteInvocationDescriptor(message, connection.Channel.GetStream()); + return invocationAdapter.WriteInvocationDescriptorAsync(message, connection.Channel.GetStream()); } - public override Task InvokeGroup(string groupName, string methodName, params object[] args) + public override Task InvokeGroupAsync(string groupName, string methodName, params object[] args) { return InvokeAllWhere(methodName, args, connection => { @@ -95,7 +95,7 @@ namespace Microsoft.AspNetCore.SignalR }); } - public override Task InvokeUser(string userId, string methodName, params object[] args) + public override Task InvokeUserAsync(string userId, string methodName, params object[] args) { return InvokeAllWhere(methodName, args, connection => { diff --git a/src/Microsoft.AspNetCore.SignalR/HubEndPoint.cs b/src/Microsoft.AspNetCore.SignalR/HubEndPoint.cs index 62da466e2d..c29620c014 100644 --- a/src/Microsoft.AspNetCore.SignalR/HubEndPoint.cs +++ b/src/Microsoft.AspNetCore.SignalR/HubEndPoint.cs @@ -8,7 +8,6 @@ namespace Microsoft.AspNetCore.SignalR { public class HubEndPoint : RpcEndpoint where THub : Hub { - private readonly AllClientProxy _all; private readonly HubLifetimeManager _lifetimeManager; private readonly IHubContext _hubContext; @@ -23,7 +22,7 @@ namespace Microsoft.AspNetCore.SignalR _hubContext = hubContext; } - public override async Task OnConnected(Connection connection) + public override async Task OnConnectedAsync(Connection connection) { try { @@ -36,7 +35,7 @@ namespace Microsoft.AspNetCore.SignalR await hub.OnConnectedAsync(); } - await base.OnConnected(connection); + await base.OnConnectedAsync(connection); } finally { @@ -62,10 +61,5 @@ namespace Microsoft.AspNetCore.SignalR hub.Context = new HubCallerContext(connection); hub.Groups = new GroupManager(connection, _lifetimeManager); } - - protected override void AfterInvoke(Connection connection, THub endpoint) - { - // Poison the hub make sure it can't be used after invocation - } } } diff --git a/src/Microsoft.AspNetCore.SignalR/HubLifetimeManager.cs b/src/Microsoft.AspNetCore.SignalR/HubLifetimeManager.cs index 2ee18cf6d5..ad7b1ed3c5 100644 --- a/src/Microsoft.AspNetCore.SignalR/HubLifetimeManager.cs +++ b/src/Microsoft.AspNetCore.SignalR/HubLifetimeManager.cs @@ -9,17 +9,17 @@ namespace Microsoft.AspNetCore.SignalR public abstract Task OnDisconnectedAsync(Connection connection); - public abstract Task InvokeAll(string methodName, params object[] args); + public abstract Task InvokeAllAsync(string methodName, params object[] args); - public abstract Task InvokeConnection(string connectionId, string methodName, params object[] args); + public abstract Task InvokeConnectionAsync(string connectionId, string methodName, params object[] args); - public abstract Task InvokeGroup(string groupName, string methodName, params object[] args); + public abstract Task InvokeGroupAsync(string groupName, string methodName, params object[] args); - public abstract Task InvokeUser(string userId, string methodName, params object[] args); + public abstract Task InvokeUserAsync(string userId, string methodName, params object[] args); - public abstract Task AddGroup(Connection connection, string groupName); + public abstract Task AddGroupAsync(Connection connection, string groupName); - public abstract Task RemoveGroup(Connection connection, string groupName); + public abstract Task RemoveGroupAsync(Connection connection, string groupName); } } diff --git a/src/Microsoft.AspNetCore.SignalR/IClientProxy.cs b/src/Microsoft.AspNetCore.SignalR/IClientProxy.cs index 12749c84fe..5204a36638 100644 --- a/src/Microsoft.AspNetCore.SignalR/IClientProxy.cs +++ b/src/Microsoft.AspNetCore.SignalR/IClientProxy.cs @@ -10,6 +10,6 @@ namespace Microsoft.AspNetCore.SignalR /// name of the method to invoke /// argumetns to pass to the client /// A task that represents when the data has been sent to the client. - Task Invoke(string method, params object[] args); + Task InvokeAsync(string method, params object[] args); } } diff --git a/src/Microsoft.AspNetCore.SignalR/IInvocationAdapter.cs b/src/Microsoft.AspNetCore.SignalR/IInvocationAdapter.cs index 727c839684..3481c19d00 100644 --- a/src/Microsoft.AspNetCore.SignalR/IInvocationAdapter.cs +++ b/src/Microsoft.AspNetCore.SignalR/IInvocationAdapter.cs @@ -6,10 +6,10 @@ namespace Microsoft.AspNetCore.SignalR { public interface IInvocationAdapter { - Task ReadInvocationDescriptor(Stream stream, Func getParams); + Task ReadInvocationDescriptorAsync(Stream stream, Func getParams); - Task WriteInvocationResult(InvocationResultDescriptor resultDescriptor, Stream stream); + Task WriteInvocationResultAsync(InvocationResultDescriptor resultDescriptor, Stream stream); - Task WriteInvocationDescriptor(InvocationDescriptor invocationDescriptor, Stream stream); + Task WriteInvocationDescriptorAsync(InvocationDescriptor invocationDescriptor, Stream stream); } } diff --git a/src/Microsoft.AspNetCore.SignalR/JsonNetInvocationAdapter.cs b/src/Microsoft.AspNetCore.SignalR/JsonNetInvocationAdapter.cs index 187fdaf731..50cf9346cb 100644 --- a/src/Microsoft.AspNetCore.SignalR/JsonNetInvocationAdapter.cs +++ b/src/Microsoft.AspNetCore.SignalR/JsonNetInvocationAdapter.cs @@ -13,20 +13,20 @@ namespace Microsoft.AspNetCore.SignalR { } - public async Task ReadInvocationDescriptor(Stream stream, Func getParams) + public async Task ReadInvocationDescriptorAsync(Stream stream, Func getParams) { var reader = new JsonTextReader(new StreamReader(stream)); // REVIEW: Task.Run() return await Task.Run(() => _serializer.Deserialize(reader)); } - public Task WriteInvocationResult(InvocationResultDescriptor resultDescriptor, Stream stream) + public Task WriteInvocationResultAsync(InvocationResultDescriptor resultDescriptor, Stream stream) { Write(resultDescriptor, stream); return Task.FromResult(0); } - public Task WriteInvocationDescriptor(InvocationDescriptor invocationDescriptor, Stream stream) + public Task WriteInvocationDescriptorAsync(InvocationDescriptor invocationDescriptor, Stream stream) { Write(invocationDescriptor, stream); return Task.FromResult(0); diff --git a/src/Microsoft.AspNetCore.SignalR/Proxies.cs b/src/Microsoft.AspNetCore.SignalR/Proxies.cs index c8c9c3180f..7c7d48cf09 100644 --- a/src/Microsoft.AspNetCore.SignalR/Proxies.cs +++ b/src/Microsoft.AspNetCore.SignalR/Proxies.cs @@ -16,9 +16,9 @@ namespace Microsoft.AspNetCore.SignalR _userId = userId; } - public Task Invoke(string method, params object[] args) + public Task InvokeAsync(string method, params object[] args) { - return _lifetimeManager.InvokeUser(_userId, method, args); + return _lifetimeManager.InvokeUserAsync(_userId, method, args); } } @@ -33,9 +33,9 @@ namespace Microsoft.AspNetCore.SignalR _groupName = groupName; } - public Task Invoke(string method, params object[] args) + public Task InvokeAsync(string method, params object[] args) { - return _lifetimeManager.InvokeGroup(_groupName, method, args); + return _lifetimeManager.InvokeGroupAsync(_groupName, method, args); } } @@ -48,9 +48,9 @@ namespace Microsoft.AspNetCore.SignalR _lifetimeManager = lifetimeManager; } - public Task Invoke(string method, params object[] args) + public Task InvokeAsync(string method, params object[] args) { - return _lifetimeManager.InvokeAll(method, args); + return _lifetimeManager.InvokeAllAsync(method, args); } } @@ -66,9 +66,9 @@ namespace Microsoft.AspNetCore.SignalR _connectionId = connectionId; } - public Task Invoke(string method, params object[] args) + public Task InvokeAsync(string method, params object[] args) { - return _lifetimeManager.InvokeConnection(_connectionId, method, args); + return _lifetimeManager.InvokeConnectionAsync(_connectionId, method, args); } } @@ -85,12 +85,12 @@ namespace Microsoft.AspNetCore.SignalR public Task Add(string groupName) { - return _lifetimeManager.AddGroup(_connection, groupName); + return _lifetimeManager.AddGroupAsync(_connection, groupName); } public Task Remove(string groupName) { - return _lifetimeManager.RemoveGroup(_connection, groupName); + return _lifetimeManager.RemoveGroupAsync(_connection, groupName); } } } diff --git a/src/Microsoft.AspNetCore.SignalR/RpcEndpoint.cs b/src/Microsoft.AspNetCore.SignalR/RpcEndpoint.cs index c2d16922d4..c4ae7a8eca 100644 --- a/src/Microsoft.AspNetCore.SignalR/RpcEndpoint.cs +++ b/src/Microsoft.AspNetCore.SignalR/RpcEndpoint.cs @@ -30,7 +30,7 @@ namespace Microsoft.AspNetCore.SignalR RegisterRPCEndPoint(); } - public override async Task OnConnected(Connection connection) + public override async Task OnConnectedAsync(Connection connection) { // TODO: Dispatch from the caller await Task.Yield(); @@ -41,7 +41,7 @@ namespace Microsoft.AspNetCore.SignalR while (true) { var invocationDescriptor = - await invocationAdapter.ReadInvocationDescriptor( + await invocationAdapter.ReadInvocationDescriptorAsync( stream, methodName => { Type[] types; @@ -76,7 +76,7 @@ namespace Microsoft.AspNetCore.SignalR }; } - await invocationAdapter.WriteInvocationResult(result, stream); + await invocationAdapter.WriteInvocationResultAsync(result, stream); } } diff --git a/src/Microsoft.AspNetCore.SignalR/SignalRAppBuilderExtensions.cs b/src/Microsoft.AspNetCore.SignalR/SignalRAppBuilderExtensions.cs index 7f09d5c8d0..fc7a407e50 100644 --- a/src/Microsoft.AspNetCore.SignalR/SignalRAppBuilderExtensions.cs +++ b/src/Microsoft.AspNetCore.SignalR/SignalRAppBuilderExtensions.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.SignalR; -using static Microsoft.AspNetCore.Builder.HttpDispatcherAppBuilderExtensions; namespace Microsoft.AspNetCore.Builder { diff --git a/src/Microsoft.AspNetCore.Sockets/EndPoint.cs b/src/Microsoft.AspNetCore.Sockets/EndPoint.cs index 5deae9424a..9317eaecb2 100644 --- a/src/Microsoft.AspNetCore.Sockets/EndPoint.cs +++ b/src/Microsoft.AspNetCore.Sockets/EndPoint.cs @@ -12,6 +12,6 @@ namespace Microsoft.AspNetCore.Sockets /// /// The new /// A that represents the connection lifetime. When the task completes, the connection is complete. - public abstract Task OnConnected(Connection connection); + public abstract Task OnConnectedAsync(Connection connection); } } diff --git a/src/Microsoft.AspNetCore.Sockets/HttpConnectionDispatcher.cs b/src/Microsoft.AspNetCore.Sockets/HttpConnectionDispatcher.cs index 3866a2fa42..9086b61d70 100644 --- a/src/Microsoft.AspNetCore.Sockets/HttpConnectionDispatcher.cs +++ b/src/Microsoft.AspNetCore.Sockets/HttpConnectionDispatcher.cs @@ -19,7 +19,7 @@ namespace Microsoft.AspNetCore.Sockets _channelFactory = factory; } - public async Task Execute(string path, HttpContext context) where TEndPoint : EndPoint + public async Task ExecuteAsync(string path, HttpContext context) where TEndPoint : EndPoint { if (context.Request.Path.StartsWithSegments(path + "/getid")) { @@ -91,7 +91,7 @@ namespace Microsoft.AspNetCore.Sockets var longPolling = new LongPolling(state.Connection); // Start the transport - var transportTask = longPolling.ProcessRequest(context); + var transportTask = longPolling.ProcessRequestAsync(context); Task endpointTask = null; @@ -110,7 +110,7 @@ namespace Microsoft.AspNetCore.Sockets await endpointTask; }; - endpointTask = endpoint.OnConnected(state.Connection); + endpointTask = endpoint.OnConnectedAsync(state.Connection); state.Connection.Metadata["endpoint"] = endpointTask; } else @@ -145,10 +145,10 @@ namespace Microsoft.AspNetCore.Sockets RegisterDisconnect(context, connection); // Start the transport - var transportTask = transport.ProcessRequest(context); + var transportTask = transport.ProcessRequestAsync(context); // Call into the end point passing the connection - var endpointTask = endpoint.OnConnected(connection); + var endpointTask = endpoint.OnConnectedAsync(connection); // Wait for any of them to end await Task.WhenAny(endpointTask, transportTask); diff --git a/src/Microsoft.AspNetCore.Sockets/HttpDispatcherAppBuilderExtensions.cs b/src/Microsoft.AspNetCore.Sockets/HttpDispatcherAppBuilderExtensions.cs index 97a87f5cc4..b15d74a9b4 100644 --- a/src/Microsoft.AspNetCore.Sockets/HttpDispatcherAppBuilderExtensions.cs +++ b/src/Microsoft.AspNetCore.Sockets/HttpDispatcherAppBuilderExtensions.cs @@ -22,22 +22,22 @@ namespace Microsoft.AspNetCore.Builder app.UseRouter(routes.Build()); return app; } + } - public class SocketRouteBuilder + public class SocketRouteBuilder + { + private readonly HttpConnectionDispatcher _dispatcher; + private readonly RouteBuilder _routes; + + public SocketRouteBuilder(RouteBuilder routes, HttpConnectionDispatcher dispatcher) { - private readonly HttpConnectionDispatcher _dispatcher; - private readonly RouteBuilder _routes; + _routes = routes; + _dispatcher = dispatcher; + } - public SocketRouteBuilder(RouteBuilder routes, HttpConnectionDispatcher dispatcher) - { - _routes = routes; - _dispatcher = dispatcher; - } - - public void MapSocketEndpoint(string path) where TEndPoint : EndPoint - { - _routes.AddPrefixRoute(path, new RouteHandler(c => _dispatcher.Execute(path, c))); - } + public void MapSocketEndpoint(string path) where TEndPoint : EndPoint + { + _routes.AddPrefixRoute(path, new RouteHandler(c => _dispatcher.ExecuteAsync(path, c))); } } } diff --git a/src/Microsoft.AspNetCore.Sockets/IHttpTransport.cs b/src/Microsoft.AspNetCore.Sockets/IHttpTransport.cs index ffe8fa2da7..e0b437927f 100644 --- a/src/Microsoft.AspNetCore.Sockets/IHttpTransport.cs +++ b/src/Microsoft.AspNetCore.Sockets/IHttpTransport.cs @@ -13,6 +13,6 @@ namespace Microsoft.AspNetCore.Sockets /// /// /// A that completes when the transport has finished processing - Task ProcessRequest(HttpContext context); + Task ProcessRequestAsync(HttpContext context); } } diff --git a/src/Microsoft.AspNetCore.Sockets/LongPolling.cs b/src/Microsoft.AspNetCore.Sockets/LongPolling.cs index eed89f4330..a740a30b31 100644 --- a/src/Microsoft.AspNetCore.Sockets/LongPolling.cs +++ b/src/Microsoft.AspNetCore.Sockets/LongPolling.cs @@ -16,7 +16,7 @@ namespace Microsoft.AspNetCore.Sockets _channel = (HttpChannel)connection.Channel; } - public async Task ProcessRequest(HttpContext context) + public async Task ProcessRequestAsync(HttpContext context) { var result = await _channel.Output.ReadAsync(); var buffer = result.Buffer; diff --git a/src/Microsoft.AspNetCore.Sockets/ServerSentEvents.cs b/src/Microsoft.AspNetCore.Sockets/ServerSentEvents.cs index a625a70542..173416bb4c 100644 --- a/src/Microsoft.AspNetCore.Sockets/ServerSentEvents.cs +++ b/src/Microsoft.AspNetCore.Sockets/ServerSentEvents.cs @@ -16,7 +16,7 @@ namespace Microsoft.AspNetCore.Sockets _channel = (HttpChannel)connection.Channel; } - public async Task ProcessRequest(HttpContext context) + public async Task ProcessRequestAsync(HttpContext context) { context.Response.ContentType = "text/event-stream"; context.Response.Headers["Cache-Control"] = "no-cache"; diff --git a/src/Microsoft.AspNetCore.Sockets/WebSockets.cs b/src/Microsoft.AspNetCore.Sockets/WebSockets.cs index fdec59ed28..ad500a2b05 100644 --- a/src/Microsoft.AspNetCore.Sockets/WebSockets.cs +++ b/src/Microsoft.AspNetCore.Sockets/WebSockets.cs @@ -20,7 +20,7 @@ namespace Microsoft.AspNetCore.Sockets _messageType = format == Format.Binary ? WebSocketMessageType.Binary : WebSocketMessageType.Text; } - public async Task ProcessRequest(HttpContext context) + public async Task ProcessRequestAsync(HttpContext context) { if (!context.WebSockets.IsWebSocketRequest) { diff --git a/test/Microsoft.AspNetCore.Sockets.Tests/HttpConnectionDispatcherTests.cs b/test/Microsoft.AspNetCore.Sockets.Tests/HttpConnectionDispatcherTests.cs index 7048970d5d..0b17aaab36 100644 --- a/test/Microsoft.AspNetCore.Sockets.Tests/HttpConnectionDispatcherTests.cs +++ b/test/Microsoft.AspNetCore.Sockets.Tests/HttpConnectionDispatcherTests.cs @@ -25,7 +25,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests var ms = new MemoryStream(); context.Request.Path = "/getid"; context.Response.Body = ms; - await dispatcher.Execute("", context); + await dispatcher.ExecuteAsync("", context); var id = Encoding.UTF8.GetString(ms.ToArray()); @@ -52,7 +52,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests context.Request.Query = qs; await Assert.ThrowsAsync(async () => { - await dispatcher.Execute("", context); + await dispatcher.ExecuteAsync("", context); }); } } @@ -72,7 +72,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests context.Request.Query = qs; await Assert.ThrowsAsync(async () => { - await dispatcher.Execute("", context); + await dispatcher.ExecuteAsync("", context); }); } } @@ -88,7 +88,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests context.Request.Path = "/send"; await Assert.ThrowsAsync(async () => { - await dispatcher.Execute("", context); + await dispatcher.ExecuteAsync("", context); }); } } @@ -96,7 +96,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests public class TestEndPoint : EndPoint { - public override Task OnConnected(Connection connection) + public override Task OnConnectedAsync(Connection connection) { throw new NotImplementedException(); } diff --git a/test/Microsoft.AspNetCore.Sockets.Tests/LongPollingTests.cs b/test/Microsoft.AspNetCore.Sockets.Tests/LongPollingTests.cs index d9442b3f9e..466b939628 100644 --- a/test/Microsoft.AspNetCore.Sockets.Tests/LongPollingTests.cs +++ b/test/Microsoft.AspNetCore.Sockets.Tests/LongPollingTests.cs @@ -26,7 +26,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests channel.Output.CompleteWriter(); - await poll.ProcessRequest(context); + await poll.ProcessRequestAsync(context); Assert.Equal(204, context.Response.StatusCode); } @@ -50,7 +50,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests channel.Output.CompleteWriter(); - await poll.ProcessRequest(context); + await poll.ProcessRequestAsync(context); Assert.Equal("Hello World", Encoding.UTF8.GetString(ms.ToArray())); } diff --git a/test/Microsoft.AspNetCore.Sockets.Tests/ServerSentEventsTests.cs b/test/Microsoft.AspNetCore.Sockets.Tests/ServerSentEventsTests.cs index 3d1d9868fc..c3e8cfce83 100644 --- a/test/Microsoft.AspNetCore.Sockets.Tests/ServerSentEventsTests.cs +++ b/test/Microsoft.AspNetCore.Sockets.Tests/ServerSentEventsTests.cs @@ -26,7 +26,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests channel.Output.CompleteWriter(); - await sse.ProcessRequest(context); + await sse.ProcessRequestAsync(context); Assert.Equal("text/event-stream", context.Response.ContentType); Assert.Equal("no-cache", context.Response.Headers["Cache-Control"]); @@ -51,7 +51,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests channel.Output.CompleteWriter(); - await sse.ProcessRequest(context); + await sse.ProcessRequestAsync(context); var expected = "data: Hello World\n\n"; Assert.Equal(expected, Encoding.UTF8.GetString(ms.ToArray()));