Cleanup: private embedded types and readonly where appropriate (#187).

This commit is contained in:
Cesar Blum Silveira 2015-12-23 17:55:26 -08:00
parent 39a4e098d1
commit 6fbb9a0cfe
15 changed files with 39 additions and 42 deletions

View File

@ -7,12 +7,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
{ {
public FrameContext() public FrameContext()
{ {
} }
public FrameContext(ConnectionContext context) : base(context) public FrameContext(ConnectionContext context) : base(context)
{ {
} }
public IFrameControl FrameControl { get; set; } public IFrameControl FrameControl { get; set; }

View File

@ -21,11 +21,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
public partial struct Enumerator : IEnumerator<KeyValuePair<string, StringValues>> public partial struct Enumerator : IEnumerator<KeyValuePair<string, StringValues>>
{ {
private FrameRequestHeaders _collection; private readonly FrameRequestHeaders _collection;
private long _bits; private readonly long _bits;
private int _state; private int _state;
private KeyValuePair<string, StringValues> _current; private KeyValuePair<string, StringValues> _current;
private bool _hasUnknown; private readonly bool _hasUnknown;
private Dictionary<string, StringValues>.Enumerator _unknownEnumerator; private Dictionary<string, StringValues>.Enumerator _unknownEnumerator;
internal Enumerator(FrameRequestHeaders collection) internal Enumerator(FrameRequestHeaders collection)

View File

@ -10,8 +10,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
{ {
public partial class FrameResponseHeaders : FrameHeaders public partial class FrameResponseHeaders : FrameHeaders
{ {
private static byte[] _CrLf = new[] { (byte)'\r', (byte)'\n' }; private static readonly byte[] _CrLf = new[] { (byte)'\r', (byte)'\n' };
private static byte[] _colonSpace = new[] { (byte)':', (byte)' ' }; private static readonly byte[] _colonSpace = new[] { (byte)':', (byte)' ' };
public bool HasConnection => HeaderConnection.Count != 0; public bool HasConnection => HeaderConnection.Count != 0;
@ -53,11 +53,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
public partial struct Enumerator : IEnumerator<KeyValuePair<string, StringValues>> public partial struct Enumerator : IEnumerator<KeyValuePair<string, StringValues>>
{ {
private FrameResponseHeaders _collection; private readonly FrameResponseHeaders _collection;
private long _bits; private readonly long _bits;
private int _state; private int _state;
private KeyValuePair<string, StringValues> _current; private KeyValuePair<string, StringValues> _current;
private bool _hasUnknown; private readonly bool _hasUnknown;
private Dictionary<string, StringValues>.Enumerator _unknownEnumerator; private Dictionary<string, StringValues>.Enumerator _unknownEnumerator;
internal Enumerator(FrameResponseHeaders collection) internal Enumerator(FrameResponseHeaders collection)

View File

@ -3,7 +3,6 @@
using System; using System;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNet.Http;
using Microsoft.AspNet.Server.Kestrel.Networking; using Microsoft.AspNet.Server.Kestrel.Networking;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;

View File

@ -14,9 +14,9 @@ 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 : Listener public abstract class ListenerPrimary : Listener
{ {
private List<UvPipeHandle> _dispatchPipes = new List<UvPipeHandle>(); private readonly List<UvPipeHandle> _dispatchPipes = new List<UvPipeHandle>();
private int _dispatchIndex; private int _dispatchIndex;
private string _pipeName; private string _pipeName;
@ -28,7 +28,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
{ {
} }
UvPipeHandle ListenPipe { get; set; } private UvPipeHandle ListenPipe { get; set; }
public async Task StartAsync( public async Task StartAsync(
string pipeName, string pipeName,

View File

@ -12,7 +12,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
{ {
public abstract class MessageBody public abstract class MessageBody
{ {
private FrameContext _context; private readonly FrameContext _context;
private int _send100Continue = 1; private int _send100Continue = 1;
protected MessageBody(FrameContext context) protected MessageBody(FrameContext context)
@ -130,7 +130,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
} }
class ForRemainingData : MessageBody private class ForRemainingData : MessageBody
{ {
public ForRemainingData(FrameContext context) public ForRemainingData(FrameContext context)
: base(context) : base(context)
@ -143,7 +143,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
} }
} }
class ForContentLength : MessageBody private class ForContentLength : MessageBody
{ {
private readonly int _contentLength; private readonly int _contentLength;
private int _inputLength; private int _inputLength;
@ -182,7 +182,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
/// <summary> /// <summary>
/// http://tools.ietf.org/html/rfc2616#section-3.6.1 /// http://tools.ietf.org/html/rfc2616#section-3.6.1
/// </summary> /// </summary>
class ForChunkedEncoding : MessageBody private class ForChunkedEncoding : MessageBody
{ {
private int _inputLength; private int _inputLength;

View File

@ -21,7 +21,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
private const int _initialTaskQueues = 64; private const int _initialTaskQueues = 64;
private const int _maxPooledWriteContexts = 32; private const int _maxPooledWriteContexts = 32;
private static WaitCallback _returnBlocks = (state) => ReturnBlocks((MemoryPoolBlock2)state); private static readonly WaitCallback _returnBlocks = (state) => ReturnBlocks((MemoryPoolBlock2)state);
private readonly KestrelThread _thread; private readonly KestrelThread _thread;
private readonly UvStreamHandle _socket; private readonly UvStreamHandle _socket;

View File

@ -30,21 +30,21 @@ namespace Microsoft.AspNet.Server.Kestrel
private static readonly Action<object, object> _listenerPrimaryCallbackAdapter = (callback, state) => ((Action<ListenerPrimary>)callback).Invoke((ListenerPrimary)state); private static readonly Action<object, object> _listenerPrimaryCallbackAdapter = (callback, state) => ((Action<ListenerPrimary>)callback).Invoke((ListenerPrimary)state);
private static readonly Action<object, object> _listenerSecondaryCallbackAdapter = (callback, state) => ((Action<ListenerSecondary>)callback).Invoke((ListenerSecondary)state); private static readonly Action<object, object> _listenerSecondaryCallbackAdapter = (callback, state) => ((Action<ListenerSecondary>)callback).Invoke((ListenerSecondary)state);
private KestrelEngine _engine; private readonly KestrelEngine _engine;
private readonly IApplicationLifetime _appLifetime; private readonly IApplicationLifetime _appLifetime;
private Thread _thread; private readonly Thread _thread;
private UvLoopHandle _loop; private readonly UvLoopHandle _loop;
private UvAsyncHandle _post; private readonly UvAsyncHandle _post;
private Queue<Work> _workAdding = new Queue<Work>(1024); private Queue<Work> _workAdding = new Queue<Work>(1024);
private Queue<Work> _workRunning = new Queue<Work>(1024); private Queue<Work> _workRunning = new Queue<Work>(1024);
private Queue<CloseHandle> _closeHandleAdding = new Queue<CloseHandle>(256); private Queue<CloseHandle> _closeHandleAdding = new Queue<CloseHandle>(256);
private Queue<CloseHandle> _closeHandleRunning = new Queue<CloseHandle>(256); private Queue<CloseHandle> _closeHandleRunning = new Queue<CloseHandle>(256);
private object _workSync = new Object(); private readonly object _workSync = new Object();
private bool _stopImmediate = false; private bool _stopImmediate = false;
private bool _initCompleted = false; private bool _initCompleted = false;
private ExceptionDispatchInfo _closeError; private ExceptionDispatchInfo _closeError;
private IKestrelTrace _log; private readonly IKestrelTrace _log;
private IThreadPool _threadPool; private readonly IThreadPool _threadPool;
public KestrelThread(KestrelEngine engine) public KestrelThread(KestrelEngine engine)
{ {

View File

@ -12,15 +12,15 @@ namespace Microsoft.AspNet.Server.Kestrel
/// </summary> /// </summary>
public class KestrelTrace : IKestrelTrace public class KestrelTrace : IKestrelTrace
{ {
private static Action<ILogger, long, Exception> _connectionStart; private static readonly Action<ILogger, long, Exception> _connectionStart;
private static Action<ILogger, long, Exception> _connectionStop; private static readonly Action<ILogger, long, Exception> _connectionStop;
private static Action<ILogger, long, Exception> _connectionPause; private static readonly Action<ILogger, long, Exception> _connectionPause;
private static Action<ILogger, long, Exception> _connectionResume; private static readonly Action<ILogger, long, Exception> _connectionResume;
private static Action<ILogger, long, Exception> _connectionReadFin; private static readonly Action<ILogger, long, Exception> _connectionReadFin;
private static Action<ILogger, long, Exception> _connectionWriteFin; private static readonly Action<ILogger, long, Exception> _connectionWriteFin;
private static Action<ILogger, long, int, Exception> _connectionWroteFin; private static readonly Action<ILogger, long, int, Exception> _connectionWroteFin;
private static Action<ILogger, long, Exception> _connectionKeepAlive; private static readonly Action<ILogger, long, Exception> _connectionKeepAlive;
private static Action<ILogger, long, Exception> _connectionDisconnect; private static readonly Action<ILogger, long, Exception> _connectionDisconnect;
protected readonly ILogger _logger; protected readonly ILogger _logger;

View File

@ -11,7 +11,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure
{ {
private const int _maxStackAllocBytes = 16384; private const int _maxStackAllocBytes = 16384;
private static Encoding _utf8 = Encoding.UTF8; private static readonly Encoding _utf8 = Encoding.UTF8;
public const string HttpConnectMethod = "CONNECT"; public const string HttpConnectMethod = "CONNECT";
public const string HttpDeleteMethod = "DELETE"; public const string HttpDeleteMethod = "DELETE";
@ -41,7 +41,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Infrastructure
private readonly static long _http11VersionLong = GetAsciiStringAsLong("HTTP/1.1"); private readonly static long _http11VersionLong = GetAsciiStringAsLong("HTTP/1.1");
private const int PerfectHashDivisor = 37; private const int PerfectHashDivisor = 37;
private static Tuple<long, string>[] _knownStrings = new Tuple<long, string>[PerfectHashDivisor]; private static readonly Tuple<long, string>[] _knownStrings = new Tuple<long, string>[PerfectHashDivisor];
static MemoryPoolIterator2Extensions() static MemoryPoolIterator2Extensions()
{ {

View File

@ -103,7 +103,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking
} }
} }
public bool IsWindows; public readonly bool IsWindows;
public int Check(int statusCode) public int Check(int statusCode)
{ {

View File

@ -8,7 +8,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking
{ {
public class UvAsyncHandle : UvHandle public class UvAsyncHandle : UvHandle
{ {
private static Libuv.uv_async_cb _uv_async_cb = (handle) => AsyncCb(handle); private static readonly Libuv.uv_async_cb _uv_async_cb = (handle) => AsyncCb(handle);
private Action _callback; private Action _callback;
public UvAsyncHandle(IKestrelTrace logger) : base(logger) public UvAsyncHandle(IKestrelTrace logger) : base(logger)

View File

@ -9,7 +9,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking
{ {
public abstract class UvHandle : UvMemory public abstract class UvHandle : UvMemory
{ {
private static Libuv.uv_close_cb _destroyMemory = (handle) => DestroyMemory(handle); private static readonly Libuv.uv_close_cb _destroyMemory = (handle) => DestroyMemory(handle);
private Action<Action<IntPtr>, IntPtr> _queueCloseHandle; private Action<Action<IntPtr>, IntPtr> _queueCloseHandle;
protected UvHandle(IKestrelTrace logger) : base (logger) protected UvHandle(IKestrelTrace logger) : base (logger)

View File

@ -16,7 +16,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking
{ {
protected Libuv _uv; protected Libuv _uv;
protected int _threadId; protected int _threadId;
protected IKestrelTrace _log; protected readonly IKestrelTrace _log;
protected UvMemory(IKestrelTrace logger) : base(IntPtr.Zero, true) protected UvMemory(IKestrelTrace logger) : base(IntPtr.Zero, true)
{ {

View File

@ -11,7 +11,7 @@ namespace Microsoft.AspNet.Server.Kestrel.FunctionalTests
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
public class IPv6SupportedConditionAttribute : Attribute, ITestCondition public class IPv6SupportedConditionAttribute : Attribute, ITestCondition
{ {
private static Lazy<bool> _ipv6Supported = new Lazy<bool>(CanBindToIPv6Address); private static readonly Lazy<bool> _ipv6Supported = new Lazy<bool>(CanBindToIPv6Address);
public bool IsMet public bool IsMet
{ {