Increment connection id for logging

This commit is contained in:
Stephen Halter 2015-09-09 12:27:10 -07:00
parent fea510f1d0
commit 0ef096b41c
3 changed files with 13 additions and 6 deletions

View File

@ -2,6 +2,7 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Threading;
using Microsoft.AspNet.Server.Kestrel.Infrastructure;
using Microsoft.AspNet.Server.Kestrel.Networking;
using Microsoft.Framework.Logging;
@ -13,6 +14,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
private static readonly Action<UvStreamHandle, int, Exception, object> _readCallback = ReadCallback;
private static readonly Func<UvStreamHandle, int, object, Libuv.uv_buf_t> _allocCallback = AllocCallback;
private static long _lastConnectionId;
private readonly UvStreamHandle _socket;
private Frame _frame;
private long _connectionId = 0;
@ -24,6 +27,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
{
_socket = socket;
ConnectionControl = this;
_connectionId = Interlocked.Increment(ref _lastConnectionId);
}
public void Start()
@ -31,7 +36,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
Log.ConnectionStart(_connectionId);
SocketInput = new SocketInput(Memory);
SocketOutput = new SocketOutput(Thread, _socket, Log);
SocketOutput = new SocketOutput(Thread, _socket, _connectionId, Log);
_frame = new Frame(this);
_socket.ReadStart(_allocCallback, _readCallback, this);
}

View File

@ -17,6 +17,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
private readonly KestrelThread _thread;
private readonly UvStreamHandle _socket;
private readonly long _connectionId;
private readonly IKestrelTrace _log;
// This locks access to to all of the below fields
@ -31,10 +32,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
private WriteContext _nextWriteContext;
private readonly Queue<CallbackContext> _callbacksPending;
public SocketOutput(KestrelThread thread, UvStreamHandle socket, IKestrelTrace log)
public SocketOutput(KestrelThread thread, UvStreamHandle socket, long connectionId, IKestrelTrace log)
{
_thread = thread;
_socket = socket;
_connectionId = connectionId;
_log = log;
_callbacksPending = new Queue<CallbackContext>();
}
@ -46,7 +48,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
Array.Copy(buffer.Array, buffer.Offset, copy, 0, buffer.Count);
buffer = new ArraySegment<byte>(copy);
_log.ConnectionWrite(0, buffer.Count);
_log.ConnectionWrite(_connectionId, buffer.Count);
bool triggerCallbackNow = false;
@ -155,7 +157,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
// This is called on the libuv event loop
private void OnWriteCompleted(Queue<ArraySegment<byte>> writtenBuffers, UvWriteReq req, int status, Exception error)
{
_log.ConnectionWriteCallback(0, status);
_log.ConnectionWriteCallback(_connectionId, status);
lock (_lockObj)
{

View File

@ -39,7 +39,7 @@ namespace Microsoft.AspNet.Server.KestrelTests
var kestrelThread = kestrelEngine.Threads[0];
var socket = new MockSocket(kestrelThread.Loop.ThreadId, new KestrelTrace(new TestLogger()));
var trace = new KestrelTrace(new TestLogger());
var socketOutput = new SocketOutput(kestrelThread, socket, trace);
var socketOutput = new SocketOutput(kestrelThread, socket, 0, trace);
// I doubt _maxBytesPreCompleted will ever be over a MB. If it is, we should change this test.
var bufferSize = 1048576;
@ -84,7 +84,7 @@ namespace Microsoft.AspNet.Server.KestrelTests
var kestrelThread = kestrelEngine.Threads[0];
var socket = new MockSocket(kestrelThread.Loop.ThreadId, new KestrelTrace(new TestLogger()));
var trace = new KestrelTrace(new TestLogger());
var socketOutput = new SocketOutput(kestrelThread, socket, trace);
var socketOutput = new SocketOutput(kestrelThread, socket, 0, trace);
var bufferSize = maxBytesPreCompleted;
var buffer = new ArraySegment<byte>(new byte[bufferSize], 0, bufferSize);