/// <summary> /// 构造会话管理器 /// </summary> /// <param name="context"></param> /// <param name="bufferSize"></param> /// <param name="count"></param> /// <param name="completed"></param> public SessionManager(IContext context, int bufferSize, int count, EventHandler <SocketAsyncEventArgs> completed, TimeSpan timeOut) { _userTokenPool = new UserTokenPool(context, count); _session = new OuterMemoryCacheHelper <IUserToken>(); _timeOut = timeOut; _bufferSize = bufferSize; _completed = completed; _bufferManager = new BufferManager(bufferSize * count, bufferSize); _bufferManager.InitBuffer(); _argsPool = new SocketAsyncEventArgsPool(count * 2); _argsPool.InitPool(_completed); //超时处理 timeout handler ThreadHelper.PulseAction(() => { var values = _session.List.Where(b => b.Expired < DateTimeHelper.Now); if (values != null) { foreach (var val in values) { if (val != null) { OnTimeOut?.Invoke(val.Value); } } } }, new TimeSpan(0, 0, 10), false); }
/// <summary> /// 构造会话管理器 /// </summary> /// <param name="context"></param> /// <param name="bufferSize"></param> /// <param name="count"></param> /// <param name="completed"></param> /// <param name="freetime"></param> public SessionManager(IContext <IUnpacker> context, int bufferSize, int count, EventHandler <SocketAsyncEventArgs> completed, TimeSpan freetime) { _sessionCache = new MemoryCache <IUserToken>(); _freeTime = freetime; _userTokenPool = new UserTokenPool(context, count, bufferSize, completed); _sessionCache.OnChanged += _sessionCache_OnChanged; }
/// <summary> /// 构造会话管理器 /// </summary> /// <param name="context"></param> /// <param name="bufferSize"></param> /// <param name="count"></param> /// <param name="completed"></param> public SessionManager(IContext context, int bufferSize, int count, EventHandler <SocketAsyncEventArgs> completed, TimeSpan timeOut) { _userTokenPool = new UserTokenPool(context, count); _session = new MemoryCacheHelper <IUserToken>(); _timeOut = timeOut; _bufferSize = bufferSize; _completed = completed; _bufferManager = new BufferManager(_bufferSize * count, _bufferSize); _bufferManager.InitBuffer(); _argsPool = new SocketAsyncEventArgsPool(count * 2); _argsPool.InitPool(_completed); //不存在时处理 _session.OnChanged += _session_OnChanged; }