Updated to new System.IO.Pipelines package instead of Channels
This commit is contained in:
parent
f3ebe03a0b
commit
4aa65cf0bf
|
|
@ -2,7 +2,6 @@
|
||||||
<configuration>
|
<configuration>
|
||||||
<packageSources>
|
<packageSources>
|
||||||
<add key="NuGet" value="https://api.nuget.org/v3/index.json" />
|
<add key="NuGet" value="https://api.nuget.org/v3/index.json" />
|
||||||
<add key="Channels" value="https://www.myget.org/F/channels/api/v3/index.json" />
|
|
||||||
<add key="dotnet-corefxlab" value="https://dotnet.myget.org/F/dotnet-corefxlab/api/v3/index.json" />
|
<add key="dotnet-corefxlab" value="https://dotnet.myget.org/F/dotnet-corefxlab/api/v3/index.json" />
|
||||||
<add key="AspNetCore" value="https://dotnet.myget.org/F/aspnetcore-ci-dev/api/v3/index.json" />
|
<add key="AspNetCore" value="https://dotnet.myget.org/F/aspnetcore-ci-dev/api/v3/index.json" />
|
||||||
</packageSources>
|
</packageSources>
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.IO.Pipelines;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Channels;
|
|
||||||
using Microsoft.AspNetCore.Sockets;
|
using Microsoft.AspNetCore.Sockets;
|
||||||
|
|
||||||
namespace SocialWeather
|
namespace SocialWeather
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
using System.Threading.Tasks;
|
using System.IO.Pipelines;
|
||||||
using Channels;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Sockets;
|
using Microsoft.AspNetCore.Sockets;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,9 @@
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.IO.Pipelines;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Channels;
|
|
||||||
using Microsoft.AspNetCore.Sockets;
|
using Microsoft.AspNetCore.Sockets;
|
||||||
|
|
||||||
namespace SocketsSample
|
namespace SocketsSample
|
||||||
|
|
|
||||||
|
|
@ -5,11 +5,11 @@ using System;
|
||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.IO.Pipelines;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Channels;
|
|
||||||
using Microsoft.AspNetCore.Sockets;
|
using Microsoft.AspNetCore.Sockets;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
|
|
|
||||||
|
|
@ -3,9 +3,9 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.IO.Pipelines;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Channels;
|
|
||||||
using Microsoft.AspNetCore.Sockets;
|
using Microsoft.AspNetCore.Sockets;
|
||||||
using Microsoft.Extensions.Internal;
|
using Microsoft.Extensions.Internal;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,10 +3,10 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.IO.Pipelines;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Channels;
|
|
||||||
using Microsoft.AspNetCore.Sockets;
|
using Microsoft.AspNetCore.Sockets;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
// Copyright (c) .NET Foundation. All rights reserved.
|
// 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.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
|
using System.IO.Pipelines;
|
||||||
using System.Security.Claims;
|
using System.Security.Claims;
|
||||||
using Channels;
|
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Sockets
|
namespace Microsoft.AspNetCore.Sockets
|
||||||
{
|
{
|
||||||
|
|
@ -10,7 +10,7 @@ namespace Microsoft.AspNetCore.Sockets
|
||||||
{
|
{
|
||||||
public string ConnectionId { get; set; }
|
public string ConnectionId { get; set; }
|
||||||
public ClaimsPrincipal User { get; set; }
|
public ClaimsPrincipal User { get; set; }
|
||||||
public IChannel Channel { get; set; }
|
public IPipelineConnection Channel { get; set; }
|
||||||
public ConnectionMetadata Metadata { get; } = new ConnectionMetadata();
|
public ConnectionMetadata Metadata { get; } = new ConnectionMetadata();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,8 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
|
using System.IO.Pipelines;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using Channels;
|
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Sockets
|
namespace Microsoft.AspNetCore.Sockets
|
||||||
{
|
{
|
||||||
|
|
@ -38,7 +38,7 @@ namespace Microsoft.AspNetCore.Sockets
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConnectionState AddNewConnection(IChannel channel)
|
public ConnectionState AddNewConnection(IPipelineConnection connection)
|
||||||
{
|
{
|
||||||
string id = MakeNewConnectionId();
|
string id = MakeNewConnectionId();
|
||||||
|
|
||||||
|
|
@ -46,7 +46,7 @@ namespace Microsoft.AspNetCore.Sockets
|
||||||
{
|
{
|
||||||
Connection = new Connection
|
Connection = new Connection
|
||||||
{
|
{
|
||||||
Channel = channel,
|
Channel = connection,
|
||||||
ConnectionId = id
|
ConnectionId = id
|
||||||
},
|
},
|
||||||
LastSeen = DateTimeOffset.UtcNow,
|
LastSeen = DateTimeOffset.UtcNow,
|
||||||
|
|
|
||||||
|
|
@ -2,25 +2,25 @@
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using Channels;
|
using System.IO.Pipelines;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Sockets
|
namespace Microsoft.AspNetCore.Sockets
|
||||||
{
|
{
|
||||||
public class HttpChannel : IChannel
|
public class HttpConnection : IPipelineConnection
|
||||||
{
|
{
|
||||||
public HttpChannel(ChannelFactory factory)
|
public HttpConnection(PipelineFactory factory)
|
||||||
{
|
{
|
||||||
Input = factory.CreateChannel();
|
Input = factory.Create();
|
||||||
Output = factory.CreateChannel();
|
Output = factory.Create();
|
||||||
}
|
}
|
||||||
|
|
||||||
IReadableChannel IChannel.Input => Input;
|
IPipelineReader IPipelineConnection.Input => Input;
|
||||||
|
|
||||||
IWritableChannel IChannel.Output => Output;
|
IPipelineWriter IPipelineConnection.Output => Output;
|
||||||
|
|
||||||
public Channel Input { get; }
|
public PipelineReaderWriter Input { get; }
|
||||||
|
|
||||||
public Channel Output { get; }
|
public PipelineReaderWriter Output { get; }
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
|
|
@ -2,9 +2,9 @@
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.IO.Pipelines;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Channels;
|
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
@ -15,13 +15,13 @@ namespace Microsoft.AspNetCore.Sockets
|
||||||
public class HttpConnectionDispatcher
|
public class HttpConnectionDispatcher
|
||||||
{
|
{
|
||||||
private readonly ConnectionManager _manager;
|
private readonly ConnectionManager _manager;
|
||||||
private readonly ChannelFactory _channelFactory;
|
private readonly PipelineFactory _pipelineFactory;
|
||||||
private readonly ILoggerFactory _loggerFactory;
|
private readonly ILoggerFactory _loggerFactory;
|
||||||
|
|
||||||
public HttpConnectionDispatcher(ConnectionManager manager, ChannelFactory factory, ILoggerFactory loggerFactory)
|
public HttpConnectionDispatcher(ConnectionManager manager, PipelineFactory factory, ILoggerFactory loggerFactory)
|
||||||
{
|
{
|
||||||
_manager = manager;
|
_manager = manager;
|
||||||
_channelFactory = factory;
|
_pipelineFactory = factory;
|
||||||
_loggerFactory = loggerFactory;
|
_loggerFactory = loggerFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -169,13 +169,13 @@ namespace Microsoft.AspNetCore.Sockets
|
||||||
private static void RegisterLongPollingDisconnect(HttpContext context, Connection connection)
|
private static void RegisterLongPollingDisconnect(HttpContext context, Connection connection)
|
||||||
{
|
{
|
||||||
// For long polling, we need to end the transport but not the overall connection so we write 0 bytes
|
// For long polling, we need to end the transport but not the overall connection so we write 0 bytes
|
||||||
context.RequestAborted.Register(state => ((HttpChannel)state).Output.WriteAsync(Span<byte>.Empty), connection.Channel);
|
context.RequestAborted.Register(state => ((HttpConnection)state).Output.WriteAsync(Span<byte>.Empty), connection.Channel);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void RegisterDisconnect(HttpContext context, Connection connection)
|
private static void RegisterDisconnect(HttpContext context, Connection connection)
|
||||||
{
|
{
|
||||||
// We just kill the output writing as a signal to the transport that it is done
|
// We just kill the output writing as a signal to the transport that it is done
|
||||||
context.RequestAborted.Register(state => ((HttpChannel)state).Output.CompleteWriter(), connection.Channel);
|
context.RequestAborted.Register(state => ((HttpConnection)state).Output.CompleteWriter(), connection.Channel);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Task ProcessGetId(HttpContext context)
|
private Task ProcessGetId(HttpContext context)
|
||||||
|
|
@ -204,7 +204,7 @@ namespace Microsoft.AspNetCore.Sockets
|
||||||
{
|
{
|
||||||
// If we received an HTTP POST for the connection id and it's not an HttpChannel then fail.
|
// If we received an HTTP POST for the connection id and it's not an HttpChannel then fail.
|
||||||
// You can't write to a TCP channel directly from here.
|
// You can't write to a TCP channel directly from here.
|
||||||
var httpChannel = state.Connection.Channel as HttpChannel;
|
var httpChannel = state.Connection.Channel as HttpConnection;
|
||||||
|
|
||||||
if (httpChannel == null)
|
if (httpChannel == null)
|
||||||
{
|
{
|
||||||
|
|
@ -233,7 +233,7 @@ namespace Microsoft.AspNetCore.Sockets
|
||||||
if (StringValues.IsNullOrEmpty(connectionId))
|
if (StringValues.IsNullOrEmpty(connectionId))
|
||||||
{
|
{
|
||||||
isNewConnection = true;
|
isNewConnection = true;
|
||||||
var channel = new HttpChannel(_channelFactory);
|
var channel = new HttpConnection(_pipelineFactory);
|
||||||
connectionState = _manager.AddNewConnection(channel);
|
connectionState = _manager.AddNewConnection(channel);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
@ -250,7 +250,7 @@ namespace Microsoft.AspNetCore.Sockets
|
||||||
if (connectionState.Connection.Channel == null)
|
if (connectionState.Connection.Channel == null)
|
||||||
{
|
{
|
||||||
isNewConnection = true;
|
isNewConnection = true;
|
||||||
connectionState.Connection.Channel = new HttpChannel(_channelFactory);
|
connectionState.Connection.Channel = new HttpConnection(_pipelineFactory);
|
||||||
connectionState.Active = true;
|
connectionState.Active = true;
|
||||||
connectionState.LastSeen = DateTimeOffset.UtcNow;
|
connectionState.LastSeen = DateTimeOffset.UtcNow;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using Channels;
|
using System.IO.Pipelines;
|
||||||
using Microsoft.AspNetCore.Hosting;
|
using Microsoft.AspNetCore.Hosting;
|
||||||
using Microsoft.AspNetCore.Routing;
|
using Microsoft.AspNetCore.Routing;
|
||||||
using Microsoft.AspNetCore.Sockets;
|
using Microsoft.AspNetCore.Sockets;
|
||||||
|
|
@ -17,7 +17,7 @@ namespace Microsoft.AspNetCore.Builder
|
||||||
public static IApplicationBuilder UseSockets(this IApplicationBuilder app, Action<SocketRouteBuilder> callback)
|
public static IApplicationBuilder UseSockets(this IApplicationBuilder app, Action<SocketRouteBuilder> callback)
|
||||||
{
|
{
|
||||||
var manager = new ConnectionManager();
|
var manager = new ConnectionManager();
|
||||||
var factory = new ChannelFactory();
|
var factory = new PipelineFactory();
|
||||||
|
|
||||||
var loggerFactory = app.ApplicationServices.GetService<ILoggerFactory>();
|
var loggerFactory = app.ApplicationServices.GetService<ILoggerFactory>();
|
||||||
var dispatcher = new HttpConnectionDispatcher(manager, factory, loggerFactory);
|
var dispatcher = new HttpConnectionDispatcher(manager, factory, loggerFactory);
|
||||||
|
|
|
||||||
|
|
@ -2,21 +2,21 @@
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.IO.Pipelines;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Channels;
|
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Sockets
|
namespace Microsoft.AspNetCore.Sockets
|
||||||
{
|
{
|
||||||
public class LongPolling : IHttpTransport
|
public class LongPolling : IHttpTransport
|
||||||
{
|
{
|
||||||
private readonly HttpChannel _channel;
|
private readonly HttpConnection _channel;
|
||||||
private readonly Connection _connection;
|
private readonly Connection _connection;
|
||||||
|
|
||||||
public LongPolling(Connection connection)
|
public LongPolling(Connection connection)
|
||||||
{
|
{
|
||||||
_connection = connection;
|
_connection = connection;
|
||||||
_channel = (HttpChannel)connection.Channel;
|
_channel = (HttpConnection)connection.Channel;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task ProcessRequestAsync(HttpContext context)
|
public async Task ProcessRequestAsync(HttpContext context)
|
||||||
|
|
|
||||||
|
|
@ -2,21 +2,21 @@
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.IO.Pipelines;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Channels;
|
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Sockets
|
namespace Microsoft.AspNetCore.Sockets
|
||||||
{
|
{
|
||||||
public class ServerSentEvents : IHttpTransport
|
public class ServerSentEvents : IHttpTransport
|
||||||
{
|
{
|
||||||
private readonly HttpChannel _channel;
|
private readonly HttpConnection _channel;
|
||||||
private readonly Connection _connection;
|
private readonly Connection _connection;
|
||||||
|
|
||||||
public ServerSentEvents(Connection connection)
|
public ServerSentEvents(Connection connection)
|
||||||
{
|
{
|
||||||
_connection = connection;
|
_connection = connection;
|
||||||
_channel = (HttpChannel)connection.Channel;
|
_channel = (HttpConnection)connection.Channel;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task ProcessRequestAsync(HttpContext context)
|
public async Task ProcessRequestAsync(HttpContext context)
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,8 @@
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.IO.Pipelines;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Channels;
|
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.WebSockets.Internal;
|
using Microsoft.AspNetCore.WebSockets.Internal;
|
||||||
using Microsoft.Extensions.Internal;
|
using Microsoft.Extensions.Internal;
|
||||||
|
|
@ -18,13 +18,13 @@ namespace Microsoft.AspNetCore.Sockets
|
||||||
private static readonly TimeSpan _closeTimeout = TimeSpan.FromSeconds(5);
|
private static readonly TimeSpan _closeTimeout = TimeSpan.FromSeconds(5);
|
||||||
private static readonly WebSocketAcceptContext EmptyContext = new WebSocketAcceptContext();
|
private static readonly WebSocketAcceptContext EmptyContext = new WebSocketAcceptContext();
|
||||||
|
|
||||||
private readonly HttpChannel _channel;
|
private readonly HttpConnection _channel;
|
||||||
private readonly WebSocketOpcode _opcode;
|
private readonly WebSocketOpcode _opcode;
|
||||||
private readonly ILogger _logger;
|
private readonly ILogger _logger;
|
||||||
|
|
||||||
public WebSockets(Connection connection, Format format, ILoggerFactory loggerFactory)
|
public WebSockets(Connection connection, Format format, ILoggerFactory loggerFactory)
|
||||||
{
|
{
|
||||||
_channel = (HttpChannel)connection.Channel;
|
_channel = (HttpConnection)connection.Channel;
|
||||||
_opcode = format == Format.Binary ? WebSocketOpcode.Binary : WebSocketOpcode.Text;
|
_opcode = format == Format.Binary ? WebSocketOpcode.Binary : WebSocketOpcode.Text;
|
||||||
|
|
||||||
_logger = (ILogger)loggerFactory?.CreateLogger<WebSockets>() ?? NullLogger.Instance;
|
_logger = (ILogger)loggerFactory?.CreateLogger<WebSockets>() ?? NullLogger.Instance;
|
||||||
|
|
@ -44,7 +44,7 @@ namespace Microsoft.AspNetCore.Sockets
|
||||||
_logger.LogInformation("Socket opened.");
|
_logger.LogInformation("Socket opened.");
|
||||||
|
|
||||||
// Begin sending and receiving. Receiving must be started first because ExecuteAsync enables SendAsync.
|
// Begin sending and receiving. Receiving must be started first because ExecuteAsync enables SendAsync.
|
||||||
var receiving = ws.ExecuteAsync((frame, self) => ((WebSockets)self).HandleFrame(frame), this);
|
var receiving = ws.ExecuteAsync((frame, state) => ((WebSockets)state).HandleFrame(frame), this);
|
||||||
var sending = StartSending(ws);
|
var sending = StartSending(ws);
|
||||||
|
|
||||||
// Wait for something to shut down.
|
// Wait for something to shut down.
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@
|
||||||
},
|
},
|
||||||
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"Channels": "0.2.0-beta-*",
|
"System.IO.Pipelines": "0.1.0-*",
|
||||||
"Microsoft.AspNetCore.Hosting.Abstractions": "1.2.0-*",
|
"Microsoft.AspNetCore.Hosting.Abstractions": "1.2.0-*",
|
||||||
"Microsoft.AspNetCore.Routing": "1.2.0-*",
|
"Microsoft.AspNetCore.Routing": "1.2.0-*",
|
||||||
"Microsoft.AspNetCore.WebSockets.Internal": "0.1.0-*",
|
"Microsoft.AspNetCore.WebSockets.Internal": "0.1.0-*",
|
||||||
|
|
|
||||||
|
|
@ -2,39 +2,39 @@
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using Channels;
|
using System.IO.Pipelines;
|
||||||
using Microsoft.AspNetCore.WebSockets.Internal;
|
using Microsoft.AspNetCore.WebSockets.Internal;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Builder
|
namespace Microsoft.AspNetCore.Builder
|
||||||
{
|
{
|
||||||
public static class WebSocketAppBuilderExtensions
|
public static class WebSocketAppBuilderExtensions
|
||||||
{
|
{
|
||||||
public static void UseWebSocketConnections(this IApplicationBuilder self)
|
public static void UseWebSocketConnections(this IApplicationBuilder app)
|
||||||
{
|
{
|
||||||
// Only the GC can clean up this channel factory :(
|
// Only the GC can clean up this channel factory :(
|
||||||
self.UseWebSocketConnections(new ChannelFactory(), new WebSocketConnectionOptions());
|
app.UseWebSocketConnections(new PipelineFactory(), new WebSocketConnectionOptions());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void UseWebSocketConnections(this IApplicationBuilder self, ChannelFactory channelFactory)
|
public static void UseWebSocketConnections(this IApplicationBuilder app, PipelineFactory factory)
|
||||||
{
|
{
|
||||||
if (channelFactory == null)
|
if (factory == null)
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException(nameof(channelFactory));
|
throw new ArgumentNullException(nameof(factory));
|
||||||
}
|
}
|
||||||
self.UseWebSocketConnections(channelFactory, new WebSocketConnectionOptions());
|
app.UseWebSocketConnections(factory, new WebSocketConnectionOptions());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void UseWebSocketConnections(this IApplicationBuilder self, ChannelFactory channelFactory, WebSocketConnectionOptions options)
|
public static void UseWebSocketConnections(this IApplicationBuilder app, PipelineFactory factory, WebSocketConnectionOptions options)
|
||||||
{
|
{
|
||||||
if (channelFactory == null)
|
if (factory == null)
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException(nameof(channelFactory));
|
throw new ArgumentNullException(nameof(factory));
|
||||||
}
|
}
|
||||||
if (options == null)
|
if (options == null)
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException(nameof(options));
|
throw new ArgumentNullException(nameof(options));
|
||||||
}
|
}
|
||||||
self.UseMiddleware<WebSocketConnectionMiddleware>(channelFactory, options);
|
app.UseMiddleware<WebSocketConnectionMiddleware>(factory, options);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,8 @@
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.IO.Pipelines;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Channels;
|
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Http.Features;
|
using Microsoft.AspNetCore.Http.Features;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
@ -16,7 +16,7 @@ namespace Microsoft.AspNetCore.WebSockets.Internal
|
||||||
private HttpContext _context;
|
private HttpContext _context;
|
||||||
private IHttpUpgradeFeature _upgradeFeature;
|
private IHttpUpgradeFeature _upgradeFeature;
|
||||||
private ILogger _logger;
|
private ILogger _logger;
|
||||||
private readonly ChannelFactory _channelFactory;
|
private readonly PipelineFactory _factory;
|
||||||
|
|
||||||
public bool IsWebSocketRequest
|
public bool IsWebSocketRequest
|
||||||
{
|
{
|
||||||
|
|
@ -30,9 +30,9 @@ namespace Microsoft.AspNetCore.WebSockets.Internal
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public WebSocketConnectionFeature(HttpContext context, ChannelFactory channelFactory, IHttpUpgradeFeature upgradeFeature, ILoggerFactory loggerFactory)
|
public WebSocketConnectionFeature(HttpContext context, PipelineFactory factory, IHttpUpgradeFeature upgradeFeature, ILoggerFactory loggerFactory)
|
||||||
{
|
{
|
||||||
_channelFactory = channelFactory;
|
_factory = factory;
|
||||||
_context = context;
|
_context = context;
|
||||||
_upgradeFeature = upgradeFeature;
|
_upgradeFeature = upgradeFeature;
|
||||||
_logger = loggerFactory.CreateLogger<WebSocketConnectionFeature>();
|
_logger = loggerFactory.CreateLogger<WebSocketConnectionFeature>();
|
||||||
|
|
@ -70,8 +70,8 @@ namespace Microsoft.AspNetCore.WebSockets.Internal
|
||||||
_logger.LogDebug("Upgrading connection to WebSockets");
|
_logger.LogDebug("Upgrading connection to WebSockets");
|
||||||
var opaqueTransport = await _upgradeFeature.UpgradeAsync();
|
var opaqueTransport = await _upgradeFeature.UpgradeAsync();
|
||||||
var connection = new WebSocketConnection(
|
var connection = new WebSocketConnection(
|
||||||
opaqueTransport.AsReadableChannel(),
|
opaqueTransport.AsPipelineReader(),
|
||||||
_channelFactory.MakeWriteableChannel(opaqueTransport),
|
_factory.CreateWriter(opaqueTransport),
|
||||||
subProtocol: subProtocol);
|
subProtocol: subProtocol);
|
||||||
return connection;
|
return connection;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,8 @@
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.IO.Pipelines;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Channels;
|
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Http.Features;
|
using Microsoft.AspNetCore.Http.Features;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
@ -12,20 +12,20 @@ namespace Microsoft.AspNetCore.WebSockets.Internal
|
||||||
{
|
{
|
||||||
public class WebSocketConnectionMiddleware
|
public class WebSocketConnectionMiddleware
|
||||||
{
|
{
|
||||||
private readonly ChannelFactory _channelFactory;
|
private readonly PipelineFactory _factory;
|
||||||
private readonly ILoggerFactory _loggerFactory;
|
private readonly ILoggerFactory _loggerFactory;
|
||||||
private readonly RequestDelegate _next;
|
private readonly RequestDelegate _next;
|
||||||
private readonly WebSocketConnectionOptions _options;
|
private readonly WebSocketConnectionOptions _options;
|
||||||
|
|
||||||
public WebSocketConnectionMiddleware(RequestDelegate next, ChannelFactory channelFactory, WebSocketConnectionOptions options, ILoggerFactory loggerFactory)
|
public WebSocketConnectionMiddleware(RequestDelegate next, PipelineFactory factory, WebSocketConnectionOptions options, ILoggerFactory loggerFactory)
|
||||||
{
|
{
|
||||||
if (next == null)
|
if (next == null)
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException(nameof(next));
|
throw new ArgumentNullException(nameof(next));
|
||||||
}
|
}
|
||||||
if (channelFactory == null)
|
if (factory == null)
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException(nameof(channelFactory));
|
throw new ArgumentNullException(nameof(factory));
|
||||||
}
|
}
|
||||||
if (options == null)
|
if (options == null)
|
||||||
{
|
{
|
||||||
|
|
@ -38,7 +38,7 @@ namespace Microsoft.AspNetCore.WebSockets.Internal
|
||||||
|
|
||||||
_next = next;
|
_next = next;
|
||||||
_loggerFactory = loggerFactory;
|
_loggerFactory = loggerFactory;
|
||||||
_channelFactory = channelFactory;
|
_factory = factory;
|
||||||
_options = options;
|
_options = options;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -49,7 +49,7 @@ namespace Microsoft.AspNetCore.WebSockets.Internal
|
||||||
{
|
{
|
||||||
if (_options.ReplaceFeature || context.Features.Get<IHttpWebSocketConnectionFeature>() == null)
|
if (_options.ReplaceFeature || context.Features.Get<IHttpWebSocketConnectionFeature>() == null)
|
||||||
{
|
{
|
||||||
context.Features.Set<IHttpWebSocketConnectionFeature>(new WebSocketConnectionFeature(context, _channelFactory, upgradeFeature, _loggerFactory));
|
context.Features.Set<IHttpWebSocketConnectionFeature>(new WebSocketConnectionFeature(context, _factory, upgradeFeature, _loggerFactory));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Binary;
|
using System.Binary;
|
||||||
using Channels;
|
using System.IO.Pipelines;
|
||||||
|
|
||||||
namespace Microsoft.Extensions.WebSockets.Internal
|
namespace Microsoft.Extensions.WebSockets.Internal
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -3,17 +3,17 @@
|
||||||
|
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Channels;
|
using System.IO.Pipelines;
|
||||||
|
|
||||||
namespace Microsoft.Extensions.WebSockets.Internal
|
namespace Microsoft.Extensions.WebSockets.Internal
|
||||||
{
|
{
|
||||||
public static class ChannelExtensions
|
public static class PipelineReaderExtensions
|
||||||
{
|
{
|
||||||
public static ValueTask<ChannelReadResult> ReadAtLeastAsync(this IReadableChannel input, int minimumRequiredBytes) => ReadAtLeastAsync(input, minimumRequiredBytes, CancellationToken.None);
|
public static ValueTask<ReadResult> ReadAtLeastAsync(this IPipelineReader input, int minimumRequiredBytes) => ReadAtLeastAsync(input, minimumRequiredBytes, CancellationToken.None);
|
||||||
|
|
||||||
// TODO: Pull this up to Channels. We should be able to do it there without allocating a Task<T> in any case (rather than here where we can avoid allocation
|
// TODO: Pull this up to Channels. We should be able to do it there without allocating a Task<T> in any case (rather than here where we can avoid allocation
|
||||||
// only if the buffer is already ready and has enough data)
|
// only if the buffer is already ready and has enough data)
|
||||||
public static ValueTask<ChannelReadResult> ReadAtLeastAsync(this IReadableChannel input, int minimumRequiredBytes, CancellationToken cancellationToken)
|
public static ValueTask<ReadResult> ReadAtLeastAsync(this IPipelineReader input, int minimumRequiredBytes, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
var awaiter = input.ReadAsync(/* cancellationToken */);
|
var awaiter = input.ReadAsync(/* cancellationToken */);
|
||||||
|
|
||||||
|
|
@ -25,7 +25,7 @@ namespace Microsoft.Extensions.WebSockets.Internal
|
||||||
|
|
||||||
if (result.IsCompleted || result.Buffer.Length >= minimumRequiredBytes)
|
if (result.IsCompleted || result.Buffer.Length >= minimumRequiredBytes)
|
||||||
{
|
{
|
||||||
return new ValueTask<ChannelReadResult>(result);
|
return new ValueTask<ReadResult>(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Buffer wasn't big enough, mark it as examined and continue to the "slow" path below
|
// Buffer wasn't big enough, mark it as examined and continue to the "slow" path below
|
||||||
|
|
@ -33,10 +33,10 @@ namespace Microsoft.Extensions.WebSockets.Internal
|
||||||
consumed: result.Buffer.Start,
|
consumed: result.Buffer.Start,
|
||||||
examined: result.Buffer.End);
|
examined: result.Buffer.End);
|
||||||
}
|
}
|
||||||
return new ValueTask<ChannelReadResult>(ReadAtLeastSlowAsync(awaiter, input, minimumRequiredBytes, cancellationToken));
|
return new ValueTask<ReadResult>(ReadAtLeastSlowAsync(awaiter, input, minimumRequiredBytes, cancellationToken));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static async Task<ChannelReadResult> ReadAtLeastSlowAsync(ReadableChannelAwaitable awaitable, IReadableChannel input, int minimumRequiredBytes, CancellationToken cancellationToken)
|
private static async Task<ReadResult> ReadAtLeastSlowAsync(ReadableBufferAwaitable awaitable, IPipelineReader input, int minimumRequiredBytes, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
var result = await awaitable;
|
var result = await awaitable;
|
||||||
while (!result.IsCompleted && result.Buffer.Length < minimumRequiredBytes)
|
while (!result.IsCompleted && result.Buffer.Length < minimumRequiredBytes)
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using Channels;
|
using System.IO.Pipelines;
|
||||||
|
|
||||||
namespace Microsoft.Extensions.WebSockets.Internal
|
namespace Microsoft.Extensions.WebSockets.Internal
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,10 @@
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
using System.Binary;
|
using System.Binary;
|
||||||
|
using System.IO.Pipelines;
|
||||||
|
using System.IO.Pipelines.Text.Primitives;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using Channels;
|
using System.Text.Formatting;
|
||||||
using Channels.Text.Primitives;
|
|
||||||
|
|
||||||
namespace Microsoft.Extensions.WebSockets.Internal
|
namespace Microsoft.Extensions.WebSockets.Internal
|
||||||
{
|
{
|
||||||
|
|
@ -70,7 +71,7 @@ namespace Microsoft.Extensions.WebSockets.Internal
|
||||||
buffer.WriteBigEndian((ushort)Status);
|
buffer.WriteBigEndian((ushort)Status);
|
||||||
if (!string.IsNullOrEmpty(Description))
|
if (!string.IsNullOrEmpty(Description))
|
||||||
{
|
{
|
||||||
buffer.WriteUtf8String(Description);
|
buffer.Append(Description, EncodingData.TextEncoding.Utf8);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,10 +5,10 @@ using System;
|
||||||
using System.Binary;
|
using System.Binary;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
|
using System.IO.Pipelines;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Channels;
|
|
||||||
|
|
||||||
namespace Microsoft.Extensions.WebSockets.Internal
|
namespace Microsoft.Extensions.WebSockets.Internal
|
||||||
{
|
{
|
||||||
|
|
@ -29,8 +29,8 @@ namespace Microsoft.Extensions.WebSockets.Internal
|
||||||
{
|
{
|
||||||
private WebSocketOptions _options;
|
private WebSocketOptions _options;
|
||||||
private readonly byte[] _maskingKeyBuffer;
|
private readonly byte[] _maskingKeyBuffer;
|
||||||
private readonly IReadableChannel _inbound;
|
private readonly IPipelineReader _inbound;
|
||||||
private readonly IWritableChannel _outbound;
|
private readonly IPipelineWriter _outbound;
|
||||||
private readonly CancellationTokenSource _terminateReceiveCts = new CancellationTokenSource();
|
private readonly CancellationTokenSource _terminateReceiveCts = new CancellationTokenSource();
|
||||||
private readonly Timer _pinger;
|
private readonly Timer _pinger;
|
||||||
private readonly CancellationTokenSource _timerCts = new CancellationTokenSource();
|
private readonly CancellationTokenSource _timerCts = new CancellationTokenSource();
|
||||||
|
|
@ -45,36 +45,36 @@ namespace Microsoft.Extensions.WebSockets.Internal
|
||||||
public WebSocketConnectionState State { get; private set; } = WebSocketConnectionState.Created;
|
public WebSocketConnectionState State { get; private set; } = WebSocketConnectionState.Created;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Constructs a new, unmasked, <see cref="WebSocketConnection"/> from an <see cref="IReadableChannel"/> and an <see cref="IWritableChannel"/> that represents an established WebSocket connection (i.e. after handshaking)
|
/// Constructs a new, unmasked, <see cref="WebSocketConnection"/> from an <see cref="IPipelineReader"/> and an <see cref="IPipelineWriter"/> that represents an established WebSocket connection (i.e. after handshaking)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="inbound">A <see cref="IReadableChannel"/> from which frames will be read when receiving.</param>
|
/// <param name="inbound">A <see cref="IPipelineReader"/> from which frames will be read when receiving.</param>
|
||||||
/// <param name="outbound">A <see cref="IWritableChannel"/> to which frame will be written when sending.</param>
|
/// <param name="outbound">A <see cref="IPipelineWriter"/> to which frame will be written when sending.</param>
|
||||||
public WebSocketConnection(IReadableChannel inbound, IWritableChannel outbound) : this(inbound, outbound, options: WebSocketOptions.DefaultUnmasked) { }
|
public WebSocketConnection(IPipelineReader inbound, IPipelineWriter outbound) : this(inbound, outbound, options: WebSocketOptions.DefaultUnmasked) { }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Constructs a new, unmasked, <see cref="WebSocketConnection"/> from an <see cref="IReadableChannel"/> and an <see cref="IWritableChannel"/> that represents an established WebSocket connection (i.e. after handshaking)
|
/// Constructs a new, unmasked, <see cref="WebSocketConnection"/> from an <see cref="IPipelineReader"/> and an <see cref="IPipelineWriter"/> that represents an established WebSocket connection (i.e. after handshaking)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="inbound">A <see cref="IReadableChannel"/> from which frames will be read when receiving.</param>
|
/// <param name="inbound">A <see cref="IPipelineReader"/> from which frames will be read when receiving.</param>
|
||||||
/// <param name="outbound">A <see cref="IWritableChannel"/> to which frame will be written when sending.</param>
|
/// <param name="outbound">A <see cref="IPipelineWriter"/> to which frame will be written when sending.</param>
|
||||||
/// <param name="subProtocol">The sub-protocol provided during handshaking</param>
|
/// <param name="subProtocol">The sub-protocol provided during handshaking</param>
|
||||||
public WebSocketConnection(IReadableChannel inbound, IWritableChannel outbound, string subProtocol) : this(inbound, outbound, subProtocol, options: WebSocketOptions.DefaultUnmasked) { }
|
public WebSocketConnection(IPipelineReader inbound, IPipelineWriter outbound, string subProtocol) : this(inbound, outbound, subProtocol, options: WebSocketOptions.DefaultUnmasked) { }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Constructs a new, <see cref="WebSocketConnection"/> from an <see cref="IReadableChannel"/> and an <see cref="IWritableChannel"/> that represents an established WebSocket connection (i.e. after handshaking)
|
/// Constructs a new, <see cref="WebSocketConnection"/> from an <see cref="IPipelineReader"/> and an <see cref="IPipelineWriter"/> that represents an established WebSocket connection (i.e. after handshaking)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="inbound">A <see cref="IReadableChannel"/> from which frames will be read when receiving.</param>
|
/// <param name="inbound">A <see cref="IPipelineReader"/> from which frames will be read when receiving.</param>
|
||||||
/// <param name="outbound">A <see cref="IWritableChannel"/> to which frame will be written when sending.</param>
|
/// <param name="outbound">A <see cref="IPipelineWriter"/> to which frame will be written when sending.</param>
|
||||||
/// <param name="options">A <see cref="WebSocketOptions"/> which provides the configuration options for the socket.</param>
|
/// <param name="options">A <see cref="WebSocketOptions"/> which provides the configuration options for the socket.</param>
|
||||||
public WebSocketConnection(IReadableChannel inbound, IWritableChannel outbound, WebSocketOptions options) : this(inbound, outbound, subProtocol: string.Empty, options: options) { }
|
public WebSocketConnection(IPipelineReader inbound, IPipelineWriter outbound, WebSocketOptions options) : this(inbound, outbound, subProtocol: string.Empty, options: options) { }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Constructs a new <see cref="WebSocketConnection"/> from an <see cref="IReadableChannel"/> and an <see cref="IWritableChannel"/> that represents an established WebSocket connection (i.e. after handshaking)
|
/// Constructs a new <see cref="WebSocketConnection"/> from an <see cref="IPipelineReader"/> and an <see cref="IPipelineWriter"/> that represents an established WebSocket connection (i.e. after handshaking)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="inbound">A <see cref="IReadableChannel"/> from which frames will be read when receiving.</param>
|
/// <param name="inbound">A <see cref="IPipelineReader"/> from which frames will be read when receiving.</param>
|
||||||
/// <param name="outbound">A <see cref="IWritableChannel"/> to which frame will be written when sending.</param>
|
/// <param name="outbound">A <see cref="IPipelineWriter"/> to which frame will be written when sending.</param>
|
||||||
/// <param name="subProtocol">The sub-protocol provided during handshaking</param>
|
/// <param name="subProtocol">The sub-protocol provided during handshaking</param>
|
||||||
/// <param name="options">A <see cref="WebSocketOptions"/> which provides the configuration options for the socket.</param>
|
/// <param name="options">A <see cref="WebSocketOptions"/> which provides the configuration options for the socket.</param>
|
||||||
public WebSocketConnection(IReadableChannel inbound, IWritableChannel outbound, string subProtocol, WebSocketOptions options)
|
public WebSocketConnection(IPipelineReader inbound, IPipelineWriter outbound, string subProtocol, WebSocketOptions options)
|
||||||
{
|
{
|
||||||
_inbound = inbound;
|
_inbound = inbound;
|
||||||
_outbound = outbound;
|
_outbound = outbound;
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
// Copyright (c) .NET Foundation. All rights reserved.
|
// 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.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
using Channels;
|
using System.IO.Pipelines;
|
||||||
|
|
||||||
namespace Microsoft.Extensions.WebSockets.Internal
|
namespace Microsoft.Extensions.WebSockets.Internal
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -48,15 +48,15 @@ namespace Microsoft.Extensions.WebSockets.Internal
|
||||||
public static class WebSocketOpcodeExtensions
|
public static class WebSocketOpcodeExtensions
|
||||||
{
|
{
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static bool IsControl(this WebSocketOpcode self)
|
public static bool IsControl(this WebSocketOpcode opcode)
|
||||||
{
|
{
|
||||||
return self >= WebSocketOpcode.Close;
|
return opcode >= WebSocketOpcode.Close;
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static bool IsMessage(this WebSocketOpcode self)
|
public static bool IsMessage(this WebSocketOpcode opcode)
|
||||||
{
|
{
|
||||||
return self < WebSocketOpcode.Close;
|
return opcode < WebSocketOpcode.Close;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -23,8 +23,8 @@
|
||||||
},
|
},
|
||||||
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"Channels": "0.2.0-beta-*",
|
"System.IO.Pipelines": "0.1.0-*",
|
||||||
"Channels.Text.Primitives": "0.2.0-beta-*",
|
"System.IO.Pipelines.Text.Primitives": "0.1.0-*",
|
||||||
"Microsoft.Extensions.TaskCache.Sources": {
|
"Microsoft.Extensions.TaskCache.Sources": {
|
||||||
"version": "1.2.0-*",
|
"version": "1.2.0-*",
|
||||||
"type": "build"
|
"type": "build"
|
||||||
|
|
|
||||||
|
|
@ -3,9 +3,9 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.IO.Pipelines;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Channels;
|
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Sockets.Tests
|
namespace Microsoft.AspNetCore.Sockets.Tests
|
||||||
|
|
@ -42,8 +42,8 @@ namespace Microsoft.AspNetCore.Sockets.Tests
|
||||||
[Fact]
|
[Fact]
|
||||||
public void AddNewConnection()
|
public void AddNewConnection()
|
||||||
{
|
{
|
||||||
using (var factory = new ChannelFactory())
|
using (var factory = new PipelineFactory())
|
||||||
using (var channel = new HttpChannel(factory))
|
using (var channel = new HttpConnection(factory))
|
||||||
{
|
{
|
||||||
var connectionManager = new ConnectionManager();
|
var connectionManager = new ConnectionManager();
|
||||||
var state = connectionManager.AddNewConnection(channel);
|
var state = connectionManager.AddNewConnection(channel);
|
||||||
|
|
@ -62,8 +62,8 @@ namespace Microsoft.AspNetCore.Sockets.Tests
|
||||||
[Fact]
|
[Fact]
|
||||||
public void RemoveConnection()
|
public void RemoveConnection()
|
||||||
{
|
{
|
||||||
using (var factory = new ChannelFactory())
|
using (var factory = new PipelineFactory())
|
||||||
using (var channel = new HttpChannel(factory))
|
using (var channel = new HttpConnection(factory))
|
||||||
{
|
{
|
||||||
var connectionManager = new ConnectionManager();
|
var connectionManager = new ConnectionManager();
|
||||||
var state = connectionManager.AddNewConnection(channel);
|
var state = connectionManager.AddNewConnection(channel);
|
||||||
|
|
|
||||||
|
|
@ -4,10 +4,10 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.IO.Pipelines;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Channels;
|
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Http.Internal;
|
using Microsoft.AspNetCore.Http.Internal;
|
||||||
using Microsoft.Extensions.Primitives;
|
using Microsoft.Extensions.Primitives;
|
||||||
|
|
@ -21,7 +21,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests
|
||||||
public async Task GetIdReservesConnectionIdAndReturnsIt()
|
public async Task GetIdReservesConnectionIdAndReturnsIt()
|
||||||
{
|
{
|
||||||
var manager = new ConnectionManager();
|
var manager = new ConnectionManager();
|
||||||
using (var factory = new ChannelFactory())
|
using (var factory = new PipelineFactory())
|
||||||
{
|
{
|
||||||
var dispatcher = new HttpConnectionDispatcher(manager, factory, loggerFactory: null);
|
var dispatcher = new HttpConnectionDispatcher(manager, factory, loggerFactory: null);
|
||||||
var context = new DefaultHttpContext();
|
var context = new DefaultHttpContext();
|
||||||
|
|
@ -44,7 +44,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests
|
||||||
var manager = new ConnectionManager();
|
var manager = new ConnectionManager();
|
||||||
var state = manager.ReserveConnection();
|
var state = manager.ReserveConnection();
|
||||||
|
|
||||||
using (var factory = new ChannelFactory())
|
using (var factory = new PipelineFactory())
|
||||||
{
|
{
|
||||||
var dispatcher = new HttpConnectionDispatcher(manager, factory, loggerFactory: null);
|
var dispatcher = new HttpConnectionDispatcher(manager, factory, loggerFactory: null);
|
||||||
var context = new DefaultHttpContext();
|
var context = new DefaultHttpContext();
|
||||||
|
|
@ -64,7 +64,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests
|
||||||
public async Task SendingToUnknownConnectionIdThrows()
|
public async Task SendingToUnknownConnectionIdThrows()
|
||||||
{
|
{
|
||||||
var manager = new ConnectionManager();
|
var manager = new ConnectionManager();
|
||||||
using (var factory = new ChannelFactory())
|
using (var factory = new PipelineFactory())
|
||||||
{
|
{
|
||||||
var dispatcher = new HttpConnectionDispatcher(manager, factory, loggerFactory: null);
|
var dispatcher = new HttpConnectionDispatcher(manager, factory, loggerFactory: null);
|
||||||
var context = new DefaultHttpContext();
|
var context = new DefaultHttpContext();
|
||||||
|
|
@ -84,7 +84,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests
|
||||||
public async Task SendingWithoutConnectionIdThrows()
|
public async Task SendingWithoutConnectionIdThrows()
|
||||||
{
|
{
|
||||||
var manager = new ConnectionManager();
|
var manager = new ConnectionManager();
|
||||||
using (var factory = new ChannelFactory())
|
using (var factory = new PipelineFactory())
|
||||||
{
|
{
|
||||||
var dispatcher = new HttpConnectionDispatcher(manager, factory, loggerFactory: null);
|
var dispatcher = new HttpConnectionDispatcher(manager, factory, loggerFactory: null);
|
||||||
var context = new DefaultHttpContext();
|
var context = new DefaultHttpContext();
|
||||||
|
|
|
||||||
|
|
@ -4,10 +4,10 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.IO.Pipelines;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Channels;
|
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
|
|
@ -18,11 +18,11 @@ namespace Microsoft.AspNetCore.Sockets.Tests
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task Set204StatusCodeWhenChannelComplete()
|
public async Task Set204StatusCodeWhenChannelComplete()
|
||||||
{
|
{
|
||||||
using (var factory = new ChannelFactory())
|
using (var factory = new PipelineFactory())
|
||||||
{
|
{
|
||||||
var connection = new Connection();
|
var connection = new Connection();
|
||||||
connection.ConnectionId = Guid.NewGuid().ToString();
|
connection.ConnectionId = Guid.NewGuid().ToString();
|
||||||
var channel = new HttpChannel(factory);
|
var channel = new HttpConnection(factory);
|
||||||
connection.Channel = channel;
|
connection.Channel = channel;
|
||||||
var context = new DefaultHttpContext();
|
var context = new DefaultHttpContext();
|
||||||
var poll = new LongPolling(connection);
|
var poll = new LongPolling(connection);
|
||||||
|
|
@ -38,11 +38,11 @@ namespace Microsoft.AspNetCore.Sockets.Tests
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task NoFramingAddedWhenDataSent()
|
public async Task NoFramingAddedWhenDataSent()
|
||||||
{
|
{
|
||||||
using (var factory = new ChannelFactory())
|
using (var factory = new PipelineFactory())
|
||||||
{
|
{
|
||||||
var connection = new Connection();
|
var connection = new Connection();
|
||||||
connection.ConnectionId = Guid.NewGuid().ToString();
|
connection.ConnectionId = Guid.NewGuid().ToString();
|
||||||
var channel = new HttpChannel(factory);
|
var channel = new HttpConnection(factory);
|
||||||
connection.Channel = channel;
|
connection.Channel = channel;
|
||||||
var context = new DefaultHttpContext();
|
var context = new DefaultHttpContext();
|
||||||
var ms = new MemoryStream();
|
var ms = new MemoryStream();
|
||||||
|
|
|
||||||
|
|
@ -4,10 +4,10 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.IO.Pipelines;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Channels;
|
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
|
|
@ -18,16 +18,16 @@ namespace Microsoft.AspNetCore.Sockets.Tests
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task SSESetsContentType()
|
public async Task SSESetsContentType()
|
||||||
{
|
{
|
||||||
using (var factory = new ChannelFactory())
|
using (var factory = new PipelineFactory())
|
||||||
{
|
{
|
||||||
var connection = new Connection();
|
var connection = new Connection();
|
||||||
connection.ConnectionId = Guid.NewGuid().ToString();
|
connection.ConnectionId = Guid.NewGuid().ToString();
|
||||||
var channel = new HttpChannel(factory);
|
var httpConnection = new HttpConnection(factory);
|
||||||
connection.Channel = channel;
|
connection.Channel = httpConnection;
|
||||||
var sse = new ServerSentEvents(connection);
|
var sse = new ServerSentEvents(connection);
|
||||||
var context = new DefaultHttpContext();
|
var context = new DefaultHttpContext();
|
||||||
|
|
||||||
channel.Output.CompleteWriter();
|
httpConnection.Output.CompleteWriter();
|
||||||
|
|
||||||
await sse.ProcessRequestAsync(context);
|
await sse.ProcessRequestAsync(context);
|
||||||
|
|
||||||
|
|
@ -39,20 +39,20 @@ namespace Microsoft.AspNetCore.Sockets.Tests
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task SSEAddsAppropriateFraming()
|
public async Task SSEAddsAppropriateFraming()
|
||||||
{
|
{
|
||||||
using (var factory = new ChannelFactory())
|
using (var factory = new PipelineFactory())
|
||||||
{
|
{
|
||||||
var connection = new Connection();
|
var connection = new Connection();
|
||||||
connection.ConnectionId = Guid.NewGuid().ToString();
|
connection.ConnectionId = Guid.NewGuid().ToString();
|
||||||
var channel = new HttpChannel(factory);
|
var httpConnection = new HttpConnection(factory);
|
||||||
connection.Channel = channel;
|
connection.Channel = httpConnection;
|
||||||
var sse = new ServerSentEvents(connection);
|
var sse = new ServerSentEvents(connection);
|
||||||
var context = new DefaultHttpContext();
|
var context = new DefaultHttpContext();
|
||||||
var ms = new MemoryStream();
|
var ms = new MemoryStream();
|
||||||
context.Response.Body = ms;
|
context.Response.Body = ms;
|
||||||
|
|
||||||
await channel.Output.WriteAsync(Encoding.UTF8.GetBytes("Hello World"));
|
await httpConnection.Output.WriteAsync(Encoding.UTF8.GetBytes("Hello World"));
|
||||||
|
|
||||||
channel.Output.CompleteWriter();
|
httpConnection.Output.CompleteWriter();
|
||||||
|
|
||||||
await sse.ProcessRequestAsync(context);
|
await sse.ProcessRequestAsync(context);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
// Copyright (c) .NET Foundation. All rights reserved.
|
// 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.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
|
using System.IO.Pipelines;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using Channels;
|
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.Extensions.WebSockets.Internal.Tests
|
namespace Microsoft.Extensions.WebSockets.Internal.Tests
|
||||||
|
|
|
||||||
|
|
@ -3,16 +3,15 @@
|
||||||
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Channels;
|
|
||||||
|
|
||||||
namespace Microsoft.Extensions.WebSockets.Internal.Tests
|
namespace Microsoft.Extensions.WebSockets.Internal.Tests
|
||||||
{
|
{
|
||||||
public static class WebSocketConnectionExtensions
|
public static class WebSocketConnectionExtensions
|
||||||
{
|
{
|
||||||
public static async Task<WebSocketConnectionSummary> ExecuteAndCaptureFramesAsync(this IWebSocketConnection self)
|
public static async Task<WebSocketConnectionSummary> ExecuteAndCaptureFramesAsync(this IWebSocketConnection connection)
|
||||||
{
|
{
|
||||||
var frames = new List<WebSocketFrame>();
|
var frames = new List<WebSocketFrame>();
|
||||||
var closeResult = await self.ExecuteAsync(frame => frames.Add(frame.Copy()));
|
var closeResult = await connection.ExecuteAsync(frame => frames.Add(frame.Copy()));
|
||||||
return new WebSocketConnectionSummary(frames, closeResult);
|
return new WebSocketConnectionSummary(frames, closeResult);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,10 +2,10 @@
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.IO.Pipelines;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Channels;
|
|
||||||
using Microsoft.Extensions.Internal;
|
using Microsoft.Extensions.Internal;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,10 +3,10 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
|
using System.IO.Pipelines;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Channels;
|
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.Extensions.WebSockets.Internal.Tests
|
namespace Microsoft.Extensions.WebSockets.Internal.Tests
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,9 @@
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.IO.Pipelines;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Channels;
|
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.Extensions.WebSockets.Internal.Tests
|
namespace Microsoft.Extensions.WebSockets.Internal.Tests
|
||||||
|
|
|
||||||
|
|
@ -2,10 +2,10 @@
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.IO.Pipelines;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Channels;
|
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.Extensions.WebSockets.Internal.Tests
|
namespace Microsoft.Extensions.WebSockets.Internal.Tests
|
||||||
|
|
@ -192,12 +192,12 @@ namespace Microsoft.Extensions.WebSockets.Internal.Tests
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static async Task<WebSocketConnectionSummary> RunReceiveTest(Func<IWritableChannel, CancellationToken, Task> producer)
|
private static async Task<WebSocketConnectionSummary> RunReceiveTest(Func<IPipelineWriter, CancellationToken, Task> producer)
|
||||||
{
|
{
|
||||||
using (var factory = new ChannelFactory())
|
using (var factory = new PipelineFactory())
|
||||||
{
|
{
|
||||||
var outbound = factory.CreateChannel();
|
var outbound = factory.Create();
|
||||||
var inbound = factory.CreateChannel();
|
var inbound = factory.Create();
|
||||||
|
|
||||||
var timeoutToken = TestUtil.CreateTimeoutToken();
|
var timeoutToken = TestUtil.CreateTimeoutToken();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,9 @@
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.IO.Pipelines;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Channels;
|
|
||||||
using Microsoft.Extensions.Internal;
|
using Microsoft.Extensions.Internal;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
|
|
@ -172,10 +172,10 @@ namespace Microsoft.Extensions.WebSockets.Internal.Tests
|
||||||
|
|
||||||
private static async Task<byte[]> RunSendTest(Func<WebSocketConnection, Task> producer, WebSocketOptions options)
|
private static async Task<byte[]> RunSendTest(Func<WebSocketConnection, Task> producer, WebSocketOptions options)
|
||||||
{
|
{
|
||||||
using (var factory = new ChannelFactory())
|
using (var factory = new PipelineFactory())
|
||||||
{
|
{
|
||||||
var outbound = factory.CreateChannel();
|
var outbound = factory.Create();
|
||||||
var inbound = factory.CreateChannel();
|
var inbound = factory.Create();
|
||||||
|
|
||||||
Task executeTask;
|
Task executeTask;
|
||||||
using (var connection = new WebSocketConnection(inbound, outbound, options))
|
using (var connection = new WebSocketConnection(inbound, outbound, options))
|
||||||
|
|
@ -197,12 +197,12 @@ namespace Microsoft.Extensions.WebSockets.Internal.Tests
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void CompleteChannels(params Channel[] channels)
|
private static void CompleteChannels(params PipelineReaderWriter[] readerWriters)
|
||||||
{
|
{
|
||||||
foreach (var channel in channels)
|
foreach (var readerWriter in readerWriters)
|
||||||
{
|
{
|
||||||
channel.CompleteReader();
|
readerWriter.CompleteReader();
|
||||||
channel.CompleteWriter();
|
readerWriter.CompleteWriter();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
// Copyright (c) .NET Foundation. All rights reserved.
|
// 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.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
|
using System.IO.Pipelines;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Channels;
|
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.Extensions.WebSockets.Internal.Tests
|
namespace Microsoft.Extensions.WebSockets.Internal.Tests
|
||||||
|
|
|
||||||
|
|
@ -2,21 +2,21 @@
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using Channels;
|
using System.IO.Pipelines;
|
||||||
|
|
||||||
namespace Microsoft.Extensions.WebSockets.Internal.Tests
|
namespace Microsoft.Extensions.WebSockets.Internal.Tests
|
||||||
{
|
{
|
||||||
internal class WebSocketPair : IDisposable
|
internal class WebSocketPair : IDisposable
|
||||||
{
|
{
|
||||||
private ChannelFactory _factory;
|
private PipelineFactory _factory;
|
||||||
|
|
||||||
public Channel ServerToClient { get; }
|
public PipelineReaderWriter ServerToClient { get; }
|
||||||
public Channel ClientToServer { get; }
|
public PipelineReaderWriter ClientToServer { get; }
|
||||||
|
|
||||||
public IWebSocketConnection ClientSocket { get; }
|
public IWebSocketConnection ClientSocket { get; }
|
||||||
public IWebSocketConnection ServerSocket { get; }
|
public IWebSocketConnection ServerSocket { get; }
|
||||||
|
|
||||||
public WebSocketPair(ChannelFactory factory, Channel serverToClient, Channel clientToServer, IWebSocketConnection clientSocket, IWebSocketConnection serverSocket)
|
public WebSocketPair(PipelineFactory factory, PipelineReaderWriter serverToClient, PipelineReaderWriter clientToServer, IWebSocketConnection clientSocket, IWebSocketConnection serverSocket)
|
||||||
{
|
{
|
||||||
_factory = factory;
|
_factory = factory;
|
||||||
ServerToClient = serverToClient;
|
ServerToClient = serverToClient;
|
||||||
|
|
@ -30,9 +30,9 @@ namespace Microsoft.Extensions.WebSockets.Internal.Tests
|
||||||
public static WebSocketPair Create(WebSocketOptions serverOptions, WebSocketOptions clientOptions)
|
public static WebSocketPair Create(WebSocketOptions serverOptions, WebSocketOptions clientOptions)
|
||||||
{
|
{
|
||||||
// Create channels
|
// Create channels
|
||||||
var factory = new ChannelFactory();
|
var factory = new PipelineFactory();
|
||||||
var serverToClient = factory.CreateChannel();
|
var serverToClient = factory.Create();
|
||||||
var clientToServer = factory.CreateChannel();
|
var clientToServer = factory.Create();
|
||||||
|
|
||||||
var serverSocket = new WebSocketConnection(clientToServer, serverToClient, options: serverOptions);
|
var serverSocket = new WebSocketConnection(clientToServer, serverToClient, options: serverOptions);
|
||||||
var clientSocket = new WebSocketConnection(serverToClient, clientToServer, options: clientOptions);
|
var clientSocket = new WebSocketConnection(serverToClient, clientToServer, options: clientOptions);
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
// Copyright (c) .NET Foundation. All rights reserved.
|
// 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.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
|
using System.IO.Pipelines;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Channels;
|
|
||||||
using Microsoft.AspNetCore.Builder;
|
using Microsoft.AspNetCore.Builder;
|
||||||
using Microsoft.AspNetCore.Hosting;
|
using Microsoft.AspNetCore.Hosting;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
|
|
@ -20,11 +20,11 @@ namespace WebSocketsTestApp
|
||||||
// For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940
|
// For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940
|
||||||
public void ConfigureServices(IServiceCollection services)
|
public void ConfigureServices(IServiceCollection services)
|
||||||
{
|
{
|
||||||
services.AddSingleton<ChannelFactory>();
|
services.AddSingleton<PipelineFactory>();
|
||||||
}
|
}
|
||||||
|
|
||||||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
||||||
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, ChannelFactory channelFactory)
|
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, PipelineFactory pipelineFactory)
|
||||||
{
|
{
|
||||||
loggerFactory.AddConsole(LogLevel.Debug);
|
loggerFactory.AddConsole(LogLevel.Debug);
|
||||||
|
|
||||||
|
|
@ -33,7 +33,7 @@ namespace WebSocketsTestApp
|
||||||
app.UseDeveloperExceptionPage();
|
app.UseDeveloperExceptionPage();
|
||||||
}
|
}
|
||||||
|
|
||||||
app.UseWebSocketConnections(new ChannelFactory());
|
app.UseWebSocketConnections(pipelineFactory);
|
||||||
|
|
||||||
app.Use(async (context, next) =>
|
app.Use(async (context, next) =>
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue