基线 SVN r240

SVN-Revision: r240
This commit is contained in:
cyf
2025-02-06 06:46:06 +00:00
commit ab56a9bcf7
5317 changed files with 902274 additions and 0 deletions
@@ -0,0 +1,63 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
namespace Lskj.SocketService
{
class DaemonThread : Object
{
private Thread _thread;
private AsyncSocketServer _asyncSocketServer;
public DaemonThread(AsyncSocketServer asyncSocketServer)
{
_asyncSocketServer = asyncSocketServer;
_thread = new Thread(DaemonThreadStart);
_thread.Start();
}
public void DaemonThreadStart()
{
while (_thread.IsAlive)
{
AsyncSocketUserToken[] userTokenArray = null;
_asyncSocketServer.AsyncSocketUserTokenList.CopyList(ref userTokenArray);
for (int i = 0; i < userTokenArray.Length; i++)
{
if (!_thread.IsAlive)
break;
try
{
if ((DateTime.Now - userTokenArray[i].ActiveDateTime).Milliseconds > _asyncSocketServer.SocketTimeOutMS) //超时Socket断开
{
lock (userTokenArray[i])
{
_asyncSocketServer.CloseClientSocket(userTokenArray[i]);
}
}
}
catch (Exception E)
{
Program.Logger.ErrorFormat("Daemon thread check timeout socket error, message: {0}", E.Message);
Program.Logger.Error(E.StackTrace);
}
}
for (int i = 0; i < 60 * 1000 / 10; i++) //每分钟检测一次
{
if (!_thread.IsAlive)
break;
Thread.Sleep(10);
}
}
}
public void Close()
{
_thread.Abort();
_thread.Join();
}
}
}