Decouple connection objects from the server (#2535)
- Making progress towards being able to use the connection objects on the client side.
This commit is contained in:
parent
c7027784b6
commit
b23d9b7679
|
|
@ -14,7 +14,7 @@ using Microsoft.Extensions.Logging;
|
|||
|
||||
namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal
|
||||
{
|
||||
public partial class LibuvConnection : LibuvConnectionContext
|
||||
public partial class LibuvConnection : TransportConnection
|
||||
{
|
||||
private static readonly int MinAllocBufferSize = KestrelMemoryPool.MinimumSegmentSize / 2;
|
||||
|
||||
|
|
@ -28,7 +28,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal
|
|||
|
||||
private MemoryHandle _bufferHandle;
|
||||
|
||||
public LibuvConnection(ListenerContext context, UvStreamHandle socket) : base(context)
|
||||
public LibuvConnection(UvStreamHandle socket, ILibuvTrace log, LibuvThread thread)
|
||||
{
|
||||
_socket = socket;
|
||||
|
||||
|
|
@ -43,20 +43,22 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal
|
|||
LocalAddress = localEndPoint.Address;
|
||||
LocalPort = localEndPoint.Port;
|
||||
}
|
||||
|
||||
Log = log;
|
||||
Thread = thread;
|
||||
}
|
||||
|
||||
public LibuvOutputConsumer OutputConsumer { get; set; }
|
||||
|
||||
private ILibuvTrace Log => ListenerContext.TransportContext.Log;
|
||||
private IConnectionDispatcher ConnectionDispatcher => ListenerContext.TransportContext.ConnectionDispatcher;
|
||||
private LibuvThread Thread => ListenerContext.Thread;
|
||||
private ILibuvTrace Log { get; }
|
||||
private LibuvThread Thread { get; }
|
||||
public override MemoryPool<byte> MemoryPool => Thread.MemoryPool;
|
||||
public override PipeScheduler InputWriterScheduler => Thread;
|
||||
public override PipeScheduler OutputReaderScheduler => Thread;
|
||||
|
||||
public async Task Start()
|
||||
{
|
||||
try
|
||||
{
|
||||
ConnectionDispatcher.OnConnection(this);
|
||||
|
||||
OutputConsumer = new LibuvOutputConsumer(Output, Thread, _socket, ConnectionId, Log);
|
||||
|
||||
StartReading();
|
||||
|
|
|
|||
|
|
@ -1,24 +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.Buffers;
|
||||
using System.IO.Pipelines;
|
||||
using System.Threading;
|
||||
using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal;
|
||||
|
||||
namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal
|
||||
{
|
||||
public class LibuvConnectionContext : TransportConnection
|
||||
{
|
||||
public LibuvConnectionContext(ListenerContext context)
|
||||
{
|
||||
ListenerContext = context;
|
||||
}
|
||||
|
||||
public ListenerContext ListenerContext { get; set; }
|
||||
|
||||
public override MemoryPool<byte> MemoryPool => ListenerContext.Thread.MemoryPool;
|
||||
public override PipeScheduler InputWriterScheduler => ListenerContext.Thread;
|
||||
public override PipeScheduler OutputReaderScheduler => ListenerContext.Thread;
|
||||
}
|
||||
}
|
||||
|
|
@ -93,7 +93,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal
|
|||
try
|
||||
{
|
||||
pipe.Init(Thread.Loop, Thread.QueueCloseHandle, false);
|
||||
|
||||
|
||||
if (!useFileHandle)
|
||||
{
|
||||
pipe.Bind(EndPointInformation.SocketPath);
|
||||
|
|
@ -181,7 +181,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal
|
|||
|
||||
protected virtual void DispatchConnection(UvStreamHandle socket)
|
||||
{
|
||||
var connection = new LibuvConnection(this, socket);
|
||||
var connection = new LibuvConnection(socket, Log, Thread);
|
||||
|
||||
TransportContext.ConnectionDispatcher.OnConnection(connection);
|
||||
|
||||
_ = connection.Start();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -161,7 +161,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Internal
|
|||
|
||||
try
|
||||
{
|
||||
var connection = new LibuvConnection(this, acceptSocket);
|
||||
var connection = new LibuvConnection(acceptSocket, Log, Thread);
|
||||
|
||||
TransportContext.ConnectionDispatcher.OnConnection(connection);
|
||||
|
||||
_ = connection.Start();
|
||||
}
|
||||
catch (UvException ex)
|
||||
|
|
|
|||
|
|
@ -60,13 +60,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal
|
|||
public override PipeScheduler InputWriterScheduler => _scheduler;
|
||||
public override PipeScheduler OutputReaderScheduler => _scheduler;
|
||||
|
||||
public async Task StartAsync(IConnectionDispatcher connectionDispatcher)
|
||||
public async Task StartAsync()
|
||||
{
|
||||
Exception sendError = null;
|
||||
try
|
||||
{
|
||||
connectionDispatcher.OnConnection(this);
|
||||
|
||||
// Spawn send and receive logic
|
||||
Task receiveTask = DoReceive();
|
||||
Task<Exception> sendTask = DoSend();
|
||||
|
|
|
|||
|
|
@ -157,7 +157,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets
|
|||
acceptSocket.NoDelay = _endPointInformation.NoDelay;
|
||||
|
||||
var connection = new SocketConnection(acceptSocket, _memoryPool, _schedulers[schedulerIndex], _trace);
|
||||
_ = connection.StartAsync(_dispatcher);
|
||||
|
||||
_dispatcher.OnConnection(connection);
|
||||
|
||||
_ = connection.StartAsync();
|
||||
}
|
||||
catch (SocketException ex) when (ex.SocketErrorCode == SocketError.ConnectionReset)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -35,7 +35,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests
|
|||
Thread = thread
|
||||
};
|
||||
var socket = new MockSocket(mockLibuv, Thread.CurrentThread.ManagedThreadId, transportContext.Log);
|
||||
var connection = new LibuvConnection(listenerContext, socket);
|
||||
var connection = new LibuvConnection(socket, listenerContext.TransportContext.Log, thread);
|
||||
listenerContext.TransportContext.ConnectionDispatcher.OnConnection(connection);
|
||||
connectionTask = connection.Start();
|
||||
|
||||
mockLibuv.AllocCallback(socket.InternalGetHandle(), 2048, out var ignored);
|
||||
|
|
@ -89,7 +90,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests
|
|||
Thread = thread
|
||||
};
|
||||
var socket = new MockSocket(mockLibuv, Thread.CurrentThread.ManagedThreadId, transportContext.Log);
|
||||
var connection = new LibuvConnection(listenerContext, socket);
|
||||
var connection = new LibuvConnection(socket, listenerContext.TransportContext.Log, thread);
|
||||
listenerContext.TransportContext.ConnectionDispatcher.OnConnection(connection);
|
||||
connectionTask = connection.Start();
|
||||
|
||||
mockLibuv.AllocCallback(socket.InternalGetHandle(), 2048, out var ignored);
|
||||
|
|
@ -157,7 +159,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests
|
|||
Thread = thread
|
||||
};
|
||||
var socket = new MockSocket(mockLibuv, Thread.CurrentThread.ManagedThreadId, transportContext.Log);
|
||||
var connection = new LibuvConnection(listenerContext, socket);
|
||||
var connection = new LibuvConnection(socket, listenerContext.TransportContext.Log, thread);
|
||||
listenerContext.TransportContext.ConnectionDispatcher.OnConnection(connection);
|
||||
connectionTask = connection.Start();
|
||||
|
||||
mockLibuv.AllocCallback(socket.InternalGetHandle(), 2048, out var ignored);
|
||||
|
|
@ -223,7 +226,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests
|
|||
Thread = thread
|
||||
};
|
||||
var socket = new MockSocket(mockLibuv, Thread.CurrentThread.ManagedThreadId, transportContext.Log);
|
||||
var connection = new LibuvConnection(listenerContext, socket);
|
||||
var connection = new LibuvConnection(socket, listenerContext.TransportContext.Log, thread);
|
||||
listenerContext.TransportContext.ConnectionDispatcher.OnConnection(connection);
|
||||
connectionTask = connection.Start();
|
||||
|
||||
var ignored = new LibuvFunctions.uv_buf_t();
|
||||
|
|
|
|||
Loading…
Reference in New Issue