From 3934ffd5af9b581f18300d43dd3c8de869b1617f Mon Sep 17 00:00:00 2001 From: David Fowler Date: Sat, 10 Feb 2018 22:16:30 -0800 Subject: [PATCH] Cleanup some dead code (#1434) - Rename SocketBuilder to ConnectionBuilder - Removed ChannelReaderExtensions --- .../ChannelReaderExtensions.cs | 47 ------------------- ...ions.cs => ConnectionBuilderExtensions.cs} | 10 ++-- .../SocketRouteBuilder.cs | 8 ++-- ...ions.cs => ConnectionBuilderExtensions.cs} | 8 ++-- 4 files changed, 13 insertions(+), 60 deletions(-) delete mode 100644 src/Microsoft.AspNetCore.Sockets.Abstractions/ChannelReaderExtensions.cs rename src/Microsoft.AspNetCore.Sockets.Abstractions/{SocketBuilderExtensions.cs => ConnectionBuilderExtensions.cs} (74%) rename src/Microsoft.AspNetCore.Sockets/{SocketBuilderExtensions.cs => ConnectionBuilderExtensions.cs} (60%) diff --git a/src/Microsoft.AspNetCore.Sockets.Abstractions/ChannelReaderExtensions.cs b/src/Microsoft.AspNetCore.Sockets.Abstractions/ChannelReaderExtensions.cs deleted file mode 100644 index e437a1a594..0000000000 --- a/src/Microsoft.AspNetCore.Sockets.Abstractions/ChannelReaderExtensions.cs +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Threading; -using System.Threading.Channels; -using System.Threading.Tasks; - -namespace Microsoft.AspNetCore.SignalR.Internal -{ - public static class ChannelReaderExtensions - { - /// Asynchronously reads an item from the channel. - /// The channel - /// A used to cancel the read operation. - /// A that represents the asynchronous read operation. - public static ValueTask ReadAsync(this ChannelReader channel, CancellationToken cancellationToken = default) - { - try - { - return - cancellationToken.IsCancellationRequested - ? new ValueTask(Task.FromCanceled(cancellationToken)) - : channel.TryRead(out T item) - ? new ValueTask(item) - : ReadAsyncCore(cancellationToken); - } - catch (Exception e) - { - return new ValueTask(Task.FromException(e)); - } - - async ValueTask ReadAsyncCore(CancellationToken ct) - { - while (await channel.WaitToReadAsync(ct).ConfigureAwait(false)) - { - if (channel.TryRead(out T item)) - { - return item; - } - } - - throw new ChannelClosedException(); - } - } - } -} diff --git a/src/Microsoft.AspNetCore.Sockets.Abstractions/SocketBuilderExtensions.cs b/src/Microsoft.AspNetCore.Sockets.Abstractions/ConnectionBuilderExtensions.cs similarity index 74% rename from src/Microsoft.AspNetCore.Sockets.Abstractions/SocketBuilderExtensions.cs rename to src/Microsoft.AspNetCore.Sockets.Abstractions/ConnectionBuilderExtensions.cs index 69dc9712d4..c952c7829a 100644 --- a/src/Microsoft.AspNetCore.Sockets.Abstractions/SocketBuilderExtensions.cs +++ b/src/Microsoft.AspNetCore.Sockets.Abstractions/ConnectionBuilderExtensions.cs @@ -7,11 +7,11 @@ using Microsoft.AspNetCore.Protocols; namespace Microsoft.AspNetCore.Sockets { - public static class SocketBuilderExtensions + public static class ConnectionBuilderExtensions { - public static IConnectionBuilder Use(this IConnectionBuilder socketBuilder, Func, Task> middleware) + public static IConnectionBuilder Use(this IConnectionBuilder connectionBuilder, Func, Task> middleware) { - return socketBuilder.Use(next => + return connectionBuilder.Use(next => { return context => { @@ -21,9 +21,9 @@ namespace Microsoft.AspNetCore.Sockets }); } - public static IConnectionBuilder Run(this IConnectionBuilder socketBuilder, Func middleware) + public static IConnectionBuilder Run(this IConnectionBuilder connectionBuilder, Func middleware) { - return socketBuilder.Use(next => + return connectionBuilder.Use(next => { return context => { diff --git a/src/Microsoft.AspNetCore.Sockets.Http/SocketRouteBuilder.cs b/src/Microsoft.AspNetCore.Sockets.Http/SocketRouteBuilder.cs index 96df652cc5..1afac841a2 100644 --- a/src/Microsoft.AspNetCore.Sockets.Http/SocketRouteBuilder.cs +++ b/src/Microsoft.AspNetCore.Sockets.Http/SocketRouteBuilder.cs @@ -27,11 +27,11 @@ namespace Microsoft.AspNetCore.Sockets public void MapSocket(PathString path, Action socketConfig) => MapSocket(path, new HttpSocketOptions(), socketConfig); - public void MapSocket(PathString path, HttpSocketOptions options, Action socketConfig) + public void MapSocket(PathString path, HttpSocketOptions options, Action connectionConfig) { - var socketBuilder = new ConnectionBuilder(_routes.ServiceProvider); - socketConfig(socketBuilder); - var socket = socketBuilder.Build(); + var connectionBuilder = new ConnectionBuilder(_routes.ServiceProvider); + connectionConfig(connectionBuilder); + var socket = connectionBuilder.Build(); _routes.MapRoute(path, c => _dispatcher.ExecuteAsync(c, options, socket)); _routes.MapRoute(path + "/negotiate", c => _dispatcher.ExecuteNegotiateAsync(c, options)); } diff --git a/src/Microsoft.AspNetCore.Sockets/SocketBuilderExtensions.cs b/src/Microsoft.AspNetCore.Sockets/ConnectionBuilderExtensions.cs similarity index 60% rename from src/Microsoft.AspNetCore.Sockets/SocketBuilderExtensions.cs rename to src/Microsoft.AspNetCore.Sockets/ConnectionBuilderExtensions.cs index 1e4d5cd688..c2659108aa 100644 --- a/src/Microsoft.AspNetCore.Sockets/SocketBuilderExtensions.cs +++ b/src/Microsoft.AspNetCore.Sockets/ConnectionBuilderExtensions.cs @@ -6,13 +6,13 @@ using Microsoft.Extensions.DependencyInjection; namespace Microsoft.AspNetCore.Sockets { - public static class SocketBuilderExtensions + public static class ConnectionBuilderExtensions { - public static IConnectionBuilder UseEndPoint(this IConnectionBuilder socketBuilder) where TEndPoint : EndPoint + public static IConnectionBuilder UseEndPoint(this IConnectionBuilder connectionBuilder) where TEndPoint : EndPoint { - var endpoint = socketBuilder.ApplicationServices.GetRequiredService(); + var endpoint = connectionBuilder.ApplicationServices.GetRequiredService(); // This is a terminal middleware, so there's no need to use the 'next' parameter - return socketBuilder.Run(connection => endpoint.OnConnectedAsync(connection)); + return connectionBuilder.Run(connection => endpoint.OnConnectedAsync(connection)); } } }