Server: Maintain connection last send time

This commit is contained in:
Tal Aloni 2017-12-13 20:23:18 +02:00
parent 765443591f
commit bb8cadee93
4 changed files with 62 additions and 0 deletions

View file

@ -24,6 +24,7 @@ namespace SMBLibrary.Server
private BlockingQueue<SessionPacket> m_sendQueue;
private DateTime m_creationDT;
private DateTime m_lastReceiveDT;
private Reference<DateTime> m_lastSendDTRef; // We must use a reference because the sender thread will keep using the original ConnectionState object
private LogDelegate LogToServerHandler;
public SMBDialect Dialect;
public GSSContext AuthenticationContext;
@ -36,6 +37,7 @@ namespace SMBLibrary.Server
m_sendQueue = new BlockingQueue<SessionPacket>();
m_creationDT = DateTime.UtcNow;
m_lastReceiveDT = DateTime.UtcNow;
m_lastSendDTRef = DateTime.UtcNow;
LogToServerHandler = logToServerHandler;
Dialect = SMBDialect.NotSet;
}
@ -48,6 +50,7 @@ namespace SMBLibrary.Server
m_sendQueue = state.SendQueue;
m_creationDT = state.CreationDT;
m_lastReceiveDT = state.LastReceiveDT;
m_lastSendDTRef = state.LastSendDTRef;
LogToServerHandler = state.LogToServerHandler;
Dialect = state.Dialect;
}
@ -126,11 +129,32 @@ namespace SMBLibrary.Server
}
}
public DateTime LastSendDT
{
get
{
return LastSendDTRef.Value;
}
}
internal Reference<DateTime> LastSendDTRef
{
get
{
return m_lastSendDTRef;
}
}
public void UpdateLastReceiveDT()
{
m_lastReceiveDT = DateTime.UtcNow;
}
public void UpdateLastSendDT()
{
m_lastSendDTRef.Value = DateTime.UtcNow;
}
public string ConnectionIdentifier
{
get

View file

@ -399,6 +399,7 @@ namespace SMBLibrary.Server
m_connectionManager.ReleaseConnection(state.ClientEndPoint);
return;
}
state.UpdateLastSendDT();
}
}

View file

@ -0,0 +1,36 @@
using System;
using System.Collections.Generic;
namespace Utilities
{
public class Reference<T> where T : struct
{
T m_value;
public Reference(T value)
{
m_value = value;
}
public T Value
{
get { return m_value; }
set { m_value = value; }
}
public override string ToString()
{
return m_value.ToString();
}
public static implicit operator T(Reference<T> wrapper)
{
return wrapper.Value;
}
public static implicit operator Reference<T>(T value)
{
return new Reference<T>(value);
}
}
}

View file

@ -46,6 +46,7 @@
<Compile Include="Generics\BlockingQueue.cs" />
<Compile Include="Generics\KeyValuePairList.cs" />
<Compile Include="Generics\Map.cs" />
<Compile Include="Generics\Reference.cs" />
<Compile Include="Generics\SortedList.cs" />
<Compile Include="IFileSystem\FileSystem.cs" />
<Compile Include="IFileSystem\FileSystemEntry.cs" />