ab56a9bcf7
SVN-Revision: r240
80 lines
3.2 KiB
C#
80 lines
3.2 KiB
C#
/******************************
|
|
* 说明:用户连接缓存
|
|
* 创建人:龚宇超
|
|
* 创建日期:2018-01-23
|
|
* 修改人:
|
|
* 修改日期:
|
|
* 修改备注:
|
|
* 版本:1.0.0.0
|
|
******************************/
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Net.Sockets;
|
|
|
|
namespace Lskj.SocketService
|
|
{
|
|
/// <summary>
|
|
/// 用户连接缓存
|
|
/// </summary>
|
|
public class AsyncSocketUserToken
|
|
{
|
|
protected SocketAsyncEventArgs _receiveEventArgs;
|
|
|
|
protected byte[] _asyncReceiveBuffer;
|
|
protected SocketAsyncEventArgs _sendEventArgs;
|
|
protected DynamicBufferManager _receiveBuffer;
|
|
protected AsyncSendBufferManager _sendBuffer;
|
|
protected AsyncSocketInvokeElement _asyncSocketInvokeElement; //协议对象
|
|
|
|
public SocketAsyncEventArgs ReceiveEventArgs { get { return _receiveEventArgs; } set { _receiveEventArgs = value; } }
|
|
public SocketAsyncEventArgs SendEventArgs { get { return _sendEventArgs; } set { _sendEventArgs = value; } }
|
|
public DynamicBufferManager ReceiveBuffer { get { return _receiveBuffer; } set { _receiveBuffer = value; } }
|
|
public AsyncSendBufferManager SendBuffer { get { return _sendBuffer; } set { _sendBuffer = value; } }
|
|
public AsyncSocketInvokeElement AsyncSocketInvokeElement { get { return _asyncSocketInvokeElement; } set { _asyncSocketInvokeElement = value; } }
|
|
|
|
protected Socket _connectSocket;
|
|
public Socket ConnectSocket
|
|
{
|
|
get
|
|
{
|
|
return _connectSocket;
|
|
}
|
|
set
|
|
{
|
|
_connectSocket = value;
|
|
if (_connectSocket == null) //清理缓存
|
|
{
|
|
if (_asyncSocketInvokeElement != null)
|
|
_asyncSocketInvokeElement.Close();
|
|
_receiveBuffer.Clear(_receiveBuffer.DataCount);
|
|
_sendBuffer.ClearPacket();
|
|
}
|
|
_asyncSocketInvokeElement = null;
|
|
_receiveEventArgs.AcceptSocket = _connectSocket;
|
|
_sendEventArgs.AcceptSocket = _connectSocket;
|
|
}
|
|
}
|
|
|
|
protected DateTime _ConnectDateTime;
|
|
public DateTime ConnectDateTime { get { return _ConnectDateTime; } set { _ConnectDateTime = value; } }
|
|
protected DateTime _ActiveDateTime;
|
|
public DateTime ActiveDateTime { get { return _ActiveDateTime; } set { _ActiveDateTime = value; } }
|
|
|
|
public AsyncSocketUserToken(int asyncReceiveBufferSize)
|
|
{
|
|
_connectSocket = null;
|
|
_asyncSocketInvokeElement = null;
|
|
_receiveEventArgs = new SocketAsyncEventArgs();
|
|
_receiveEventArgs.UserToken = this;
|
|
_asyncReceiveBuffer = new byte[asyncReceiveBufferSize];
|
|
_receiveEventArgs.SetBuffer(_asyncReceiveBuffer, 0, _asyncReceiveBuffer.Length);
|
|
_sendEventArgs = new SocketAsyncEventArgs();
|
|
_sendEventArgs.UserToken = this;
|
|
_receiveBuffer = new DynamicBufferManager(ProtocolConst.InitBufferSize);
|
|
_sendBuffer = new AsyncSendBufferManager(ProtocolConst.InitBufferSize); ;
|
|
}
|
|
}
|
|
}
|