Remove unnecessary use of generics in listeners
This commit is contained in:
parent
803ec38073
commit
a9b8cfa582
|
|
@ -11,10 +11,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Base class for listeners in Kestrel. Listens for incoming connections
|
/// Base class for listeners in Kestrel. Listens for incoming connections
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <typeparam name="T">Type of socket used by this listener</typeparam>
|
public abstract class Listener : ListenerContext, IListener
|
||||||
public abstract class Listener<T> : ListenerContext, IListener where T : UvStreamHandle
|
|
||||||
{
|
{
|
||||||
protected T ListenSocket { get; private set; }
|
protected UvStreamHandle ListenSocket { get; private set; }
|
||||||
|
|
||||||
protected static void ConnectionCallback(UvStreamHandle stream, int status, Exception error, object state)
|
protected static void ConnectionCallback(UvStreamHandle stream, int status, Exception error, object state)
|
||||||
{
|
{
|
||||||
|
|
@ -24,7 +23,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
((Listener<T>)state).OnConnection((T)stream, status);
|
((Listener)state).OnConnection(stream, status);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -62,16 +61,16 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates the socket used to listen for incoming connections
|
/// Creates the socket used to listen for incoming connections
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected abstract T CreateListenSocket(string host, int port);
|
protected abstract UvStreamHandle CreateListenSocket(string host, int port);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Handles an incoming connection
|
/// Handles an incoming connection
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="listenSocket">Socket being used to listen on</param>
|
/// <param name="listenSocket">Socket being used to listen on</param>
|
||||||
/// <param name="status">Connection status</param>
|
/// <param name="status">Connection status</param>
|
||||||
protected abstract void OnConnection(T listenSocket, int status);
|
protected abstract void OnConnection(UvStreamHandle listenSocket, int status);
|
||||||
|
|
||||||
protected virtual void DispatchConnection(T socket)
|
protected virtual void DispatchConnection(UvStreamHandle socket)
|
||||||
{
|
{
|
||||||
var connection = new Connection(this, socket);
|
var connection = new Connection(this, socket);
|
||||||
connection.Start();
|
connection.Start();
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
|
||||||
/// A primary listener waits for incoming connections on a specified socket. Incoming
|
/// A primary listener waits for incoming connections on a specified socket. Incoming
|
||||||
/// connections may be passed to a secondary listener to handle.
|
/// connections may be passed to a secondary listener to handle.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
abstract public class ListenerPrimary<T> : Listener<T>, IListenerPrimary where T : UvStreamHandle
|
abstract public class ListenerPrimary : Listener, IListenerPrimary
|
||||||
{
|
{
|
||||||
UvPipeHandle ListenPipe { get; set; }
|
UvPipeHandle ListenPipe { get; set; }
|
||||||
|
|
||||||
|
|
@ -65,7 +65,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
|
||||||
_dispatchPipes.Add(dispatchPipe);
|
_dispatchPipes.Add(dispatchPipe);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void DispatchConnection(T socket)
|
protected override void DispatchConnection(UvStreamHandle socket)
|
||||||
{
|
{
|
||||||
var index = _dispatchIndex++ % (_dispatchPipes.Count + 1);
|
var index = _dispatchIndex++ % (_dispatchPipes.Count + 1);
|
||||||
if (index == _dispatchPipes.Count)
|
if (index == _dispatchPipes.Count)
|
||||||
|
|
@ -84,7 +84,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
|
||||||
(write2, status, error, state) =>
|
(write2, status, error, state) =>
|
||||||
{
|
{
|
||||||
write2.Dispose();
|
write2.Dispose();
|
||||||
((T)state).Dispose();
|
((UvStreamHandle)state).Dispose();
|
||||||
},
|
},
|
||||||
socket);
|
socket);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
|
||||||
/// A secondary listener is delegated requests from a primary listener via a named pipe or
|
/// A secondary listener is delegated requests from a primary listener via a named pipe or
|
||||||
/// UNIX domain socket.
|
/// UNIX domain socket.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract class ListenerSecondary<T> : ListenerContext, IListenerSecondary where T : UvStreamHandle
|
public abstract class ListenerSecondary : ListenerContext, IListenerSecondary
|
||||||
{
|
{
|
||||||
UvPipeHandle DispatchPipe { get; set; }
|
UvPipeHandle DispatchPipe { get; set; }
|
||||||
|
|
||||||
|
|
@ -108,7 +108,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a socket which can be used to accept an incoming connection
|
/// Creates a socket which can be used to accept an incoming connection
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected abstract T CreateAcceptSocket();
|
protected abstract UvStreamHandle CreateAcceptSocket();
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -7,9 +7,9 @@ using Microsoft.AspNet.Server.Kestrel.Networking;
|
||||||
namespace Microsoft.AspNet.Server.Kestrel.Http
|
namespace Microsoft.AspNet.Server.Kestrel.Http
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Implementation of <see cref="Listener{T}"/> that uses UNIX domain sockets as its transport.
|
/// Implementation of <see cref="Listener"/> that uses UNIX domain sockets as its transport.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class PipeListener : Listener<UvPipeHandle>
|
public class PipeListener : Listener
|
||||||
{
|
{
|
||||||
public PipeListener(IMemoryPool memory) : base(memory)
|
public PipeListener(IMemoryPool memory) : base(memory)
|
||||||
{
|
{
|
||||||
|
|
@ -18,7 +18,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates the socket used to listen for incoming connections
|
/// Creates the socket used to listen for incoming connections
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected override UvPipeHandle CreateListenSocket(string host, int port)
|
protected override UvStreamHandle CreateListenSocket(string host, int port)
|
||||||
{
|
{
|
||||||
var socket = new UvPipeHandle();
|
var socket = new UvPipeHandle();
|
||||||
socket.Init(Thread.Loop, false);
|
socket.Init(Thread.Loop, false);
|
||||||
|
|
@ -32,7 +32,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="listenSocket">Socket being used to listen on</param>
|
/// <param name="listenSocket">Socket being used to listen on</param>
|
||||||
/// <param name="status">Connection status</param>
|
/// <param name="status">Connection status</param>
|
||||||
protected override void OnConnection(UvPipeHandle listenSocket, int status)
|
protected override void OnConnection(UvStreamHandle listenSocket, int status)
|
||||||
{
|
{
|
||||||
var acceptSocket = new UvPipeHandle();
|
var acceptSocket = new UvPipeHandle();
|
||||||
acceptSocket.Init(Thread.Loop, false);
|
acceptSocket.Init(Thread.Loop, false);
|
||||||
|
|
|
||||||
|
|
@ -7,9 +7,9 @@ using Microsoft.AspNet.Server.Kestrel.Networking;
|
||||||
namespace Microsoft.AspNet.Server.Kestrel.Http
|
namespace Microsoft.AspNet.Server.Kestrel.Http
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// An implementation of <see cref="ListenerPrimary{T}"/> using UNIX sockets.
|
/// An implementation of <see cref="ListenerPrimary"/> using UNIX sockets.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class PipeListenerPrimary : ListenerPrimary<UvPipeHandle>
|
public class PipeListenerPrimary : ListenerPrimary
|
||||||
{
|
{
|
||||||
public PipeListenerPrimary(IMemoryPool memory) : base(memory)
|
public PipeListenerPrimary(IMemoryPool memory) : base(memory)
|
||||||
{
|
{
|
||||||
|
|
@ -18,7 +18,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates the socket used to listen for incoming connections
|
/// Creates the socket used to listen for incoming connections
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected override UvPipeHandle CreateListenSocket(string host, int port)
|
protected override UvStreamHandle CreateListenSocket(string host, int port)
|
||||||
{
|
{
|
||||||
var socket = new UvPipeHandle();
|
var socket = new UvPipeHandle();
|
||||||
socket.Init(Thread.Loop, false);
|
socket.Init(Thread.Loop, false);
|
||||||
|
|
@ -32,7 +32,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="listenSocket">Socket being used to listen on</param>
|
/// <param name="listenSocket">Socket being used to listen on</param>
|
||||||
/// <param name="status">Connection status</param>
|
/// <param name="status">Connection status</param>
|
||||||
protected override void OnConnection(UvPipeHandle listenSocket, int status)
|
protected override void OnConnection(UvStreamHandle listenSocket, int status)
|
||||||
{
|
{
|
||||||
var acceptSocket = new UvPipeHandle();
|
var acceptSocket = new UvPipeHandle();
|
||||||
acceptSocket.Init(Thread.Loop, false);
|
acceptSocket.Init(Thread.Loop, false);
|
||||||
|
|
|
||||||
|
|
@ -6,9 +6,9 @@ using Microsoft.AspNet.Server.Kestrel.Networking;
|
||||||
namespace Microsoft.AspNet.Server.Kestrel.Http
|
namespace Microsoft.AspNet.Server.Kestrel.Http
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// An implementation of <see cref="ListenerSecondary{T}"/> using UNIX sockets.
|
/// An implementation of <see cref="ListenerSecondary"/> using UNIX sockets.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class PipeListenerSecondary : ListenerSecondary<UvPipeHandle>
|
public class PipeListenerSecondary : ListenerSecondary
|
||||||
{
|
{
|
||||||
public PipeListenerSecondary(IMemoryPool memory) : base(memory)
|
public PipeListenerSecondary(IMemoryPool memory) : base(memory)
|
||||||
{
|
{
|
||||||
|
|
@ -17,7 +17,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a socket which can be used to accept an incoming connection
|
/// Creates a socket which can be used to accept an incoming connection
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected override UvPipeHandle CreateAcceptSocket()
|
protected override UvStreamHandle CreateAcceptSocket()
|
||||||
{
|
{
|
||||||
var acceptSocket = new UvPipeHandle();
|
var acceptSocket = new UvPipeHandle();
|
||||||
acceptSocket.Init(Thread.Loop, false);
|
acceptSocket.Init(Thread.Loop, false);
|
||||||
|
|
|
||||||
|
|
@ -8,9 +8,9 @@ using Microsoft.AspNet.Server.Kestrel.Networking;
|
||||||
namespace Microsoft.AspNet.Server.Kestrel.Http
|
namespace Microsoft.AspNet.Server.Kestrel.Http
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Implementation of <see cref="Listener{T}"/> that uses TCP sockets as its transport.
|
/// Implementation of <see cref="Listener"/> that uses TCP sockets as its transport.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class TcpListener : Listener<UvTcpHandle>
|
public class TcpListener : Listener
|
||||||
{
|
{
|
||||||
public TcpListener(IMemoryPool memory) : base(memory)
|
public TcpListener(IMemoryPool memory) : base(memory)
|
||||||
{
|
{
|
||||||
|
|
@ -19,7 +19,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates the socket used to listen for incoming connections
|
/// Creates the socket used to listen for incoming connections
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected override UvTcpHandle CreateListenSocket(string host, int port)
|
protected override UvStreamHandle CreateListenSocket(string host, int port)
|
||||||
{
|
{
|
||||||
var socket = new UvTcpHandle();
|
var socket = new UvTcpHandle();
|
||||||
socket.Init(Thread.Loop, Thread.QueueCloseHandle);
|
socket.Init(Thread.Loop, Thread.QueueCloseHandle);
|
||||||
|
|
@ -33,7 +33,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="listenSocket">Socket being used to listen on</param>
|
/// <param name="listenSocket">Socket being used to listen on</param>
|
||||||
/// <param name="status">Connection status</param>
|
/// <param name="status">Connection status</param>
|
||||||
protected override void OnConnection(UvTcpHandle listenSocket, int status)
|
protected override void OnConnection(UvStreamHandle listenSocket, int status)
|
||||||
{
|
{
|
||||||
var acceptSocket = new UvTcpHandle();
|
var acceptSocket = new UvTcpHandle();
|
||||||
acceptSocket.Init(Thread.Loop, Thread.QueueCloseHandle);
|
acceptSocket.Init(Thread.Loop, Thread.QueueCloseHandle);
|
||||||
|
|
|
||||||
|
|
@ -8,9 +8,9 @@ using Microsoft.AspNet.Server.Kestrel.Networking;
|
||||||
namespace Microsoft.AspNet.Server.Kestrel.Http
|
namespace Microsoft.AspNet.Server.Kestrel.Http
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// An implementation of <see cref="ListenerPrimary{T}"/> using TCP sockets.
|
/// An implementation of <see cref="ListenerPrimary"/> using TCP sockets.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class TcpListenerPrimary : ListenerPrimary<UvTcpHandle>
|
public class TcpListenerPrimary : ListenerPrimary
|
||||||
{
|
{
|
||||||
public TcpListenerPrimary(IMemoryPool memory) : base(memory)
|
public TcpListenerPrimary(IMemoryPool memory) : base(memory)
|
||||||
{
|
{
|
||||||
|
|
@ -19,7 +19,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates the socket used to listen for incoming connections
|
/// Creates the socket used to listen for incoming connections
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected override UvTcpHandle CreateListenSocket(string host, int port)
|
protected override UvStreamHandle CreateListenSocket(string host, int port)
|
||||||
{
|
{
|
||||||
var socket = new UvTcpHandle();
|
var socket = new UvTcpHandle();
|
||||||
socket.Init(Thread.Loop, Thread.QueueCloseHandle);
|
socket.Init(Thread.Loop, Thread.QueueCloseHandle);
|
||||||
|
|
@ -33,7 +33,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="listenSocket">Socket being used to listen on</param>
|
/// <param name="listenSocket">Socket being used to listen on</param>
|
||||||
/// <param name="status">Connection status</param>
|
/// <param name="status">Connection status</param>
|
||||||
protected override void OnConnection(UvTcpHandle listenSocket, int status)
|
protected override void OnConnection(UvStreamHandle listenSocket, int status)
|
||||||
{
|
{
|
||||||
var acceptSocket = new UvTcpHandle();
|
var acceptSocket = new UvTcpHandle();
|
||||||
acceptSocket.Init(Thread.Loop, Thread.QueueCloseHandle);
|
acceptSocket.Init(Thread.Loop, Thread.QueueCloseHandle);
|
||||||
|
|
|
||||||
|
|
@ -6,9 +6,9 @@ using Microsoft.AspNet.Server.Kestrel.Networking;
|
||||||
namespace Microsoft.AspNet.Server.Kestrel.Http
|
namespace Microsoft.AspNet.Server.Kestrel.Http
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// An implementation of <see cref="ListenerSecondary{T}"/> using TCP sockets.
|
/// An implementation of <see cref="ListenerSecondary"/> using TCP sockets.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class TcpListenerSecondary : ListenerSecondary<UvTcpHandle>
|
public class TcpListenerSecondary : ListenerSecondary
|
||||||
{
|
{
|
||||||
public TcpListenerSecondary(IMemoryPool memory) : base(memory)
|
public TcpListenerSecondary(IMemoryPool memory) : base(memory)
|
||||||
{
|
{
|
||||||
|
|
@ -17,7 +17,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a socket which can be used to accept an incoming connection
|
/// Creates a socket which can be used to accept an incoming connection
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected override UvTcpHandle CreateAcceptSocket()
|
protected override UvStreamHandle CreateAcceptSocket()
|
||||||
{
|
{
|
||||||
var acceptSocket = new UvTcpHandle();
|
var acceptSocket = new UvTcpHandle();
|
||||||
acceptSocket.Init(Thread.Loop, Thread.QueueCloseHandle);
|
acceptSocket.Init(Thread.Loop, Thread.QueueCloseHandle);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue