singrdk/base/Services/NetStack/Runtime/TcpSessionPool.cs

54 lines
1.4 KiB
C#
Raw Normal View History

2008-03-05 09:52:00 -05:00
///////////////////////////////////////////////////////////////////////////////
//
// Microsoft Research Singularity
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
///////////////////////////////////////////////////////////////////////////////
using System;
using System.Collections;
namespace NetStack.Runtime
{
public class TcpSessionPool
{
static TcpModule tcpModule;
static ArrayList tcpSessions = new ArrayList();
static long allocations;
static long getCalls;
static long recycleCalls;
public static void SetTcpModule(TcpModule m)
{
tcpModule = m;
}
public static TcpSession! Get()
{
lock (tcpSessions) {
getCalls++;
foreach (TcpSession! ts in tcpSessions) {
if (ts.IsClosed) {
Core.Instance().DeregisterSession(ts.Protocol, ts);
tcpSessions.Remove(ts);
return tcpModule.ReInitializeSession(ts);
}
}
allocations++;
}
return new TcpSession(tcpModule);
}
public static void Recycle(TcpSession! ts)
{
lock (tcpSessions) {
recycleCalls++;
tcpSessions.Add(ts);
}
}
}
}