Exemplo n.º 1
0
        /// <summary>
        /// TCP初始化IUserToken
        /// </summary>
        /// <returns></returns>
        IUserToken InitUserToken()
        {
            IUserToken userToken = _userTokenPool.Dequeue();

            userToken.ReadArgs = _argsPool.Dequeue();
            _bufferManager.SetBuffer(userToken.ReadArgs);
            userToken.WriteArgs          = _argsPool.Dequeue();
            userToken.ReadArgs.UserToken = userToken.WriteArgs.UserToken = userToken;
            return(userToken);
        }
Exemplo n.º 2
0
        /// <summary>
        /// TCP获取usertoken
        /// 如果IUserToken数量耗尽时会出现死锁
        /// </summary>
        /// <param name="socket"></param>
        /// <returns></returns>
        public IUserToken BindUserToken(Socket socket)
        {
            _semaphore.WaitOne();
            IUserToken userToken = _userTokenPool.Dequeue();

            userToken.Socket  = socket;
            userToken.ID      = socket.RemoteEndPoint.ToString();
            userToken.Actived = userToken.Linked = DateTimeHelper.Now;
            _sessionCache.Set(userToken.ID, userToken, _freeTime);
            return(userToken);
        }