Пример #1
0
 public UserTokenPool(IContext context, int count)
 {
     _clientAcceptManager = new Semaphore(count, count);
     for (int i = 0; i < count; i++)
     {
         IUserToken userToken = UserTokenFactory.Create(context);
         concurrentQueue.Enqueue(userToken);
     }
 }
Пример #2
0
        public UserTokenPool(IContext context, int count)
        {
            _userTokenFactory = new UserTokenFactory();

            for (int i = 0; i < count; i++)
            {
                IUserToken userToken = _userTokenFactory.Create(context);
                concurrentQueue.Enqueue(userToken);
            }
        }
Пример #3
0
        /// <summary>
        /// UserTokenPool
        /// </summary>
        /// <param name="context"></param>
        /// <param name="count"></param>
        /// <param name="bufferSize"></param>
        /// <param name="completed"></param>
        public UserTokenPool(IContext <IUnpacker> context, int count, int bufferSize, EventHandler <SocketAsyncEventArgs> completed)
        {
            _userTokenFactory = new UserTokenFactory();

            _bufferManager = new BufferManager(bufferSize * count, bufferSize);

            for (int i = 0; i < count; i++)
            {
                IUserToken userToken = _userTokenFactory.Create(context);

                var writeArgs = new SocketAsyncEventArgs();
                writeArgs.Completed += completed;
                userToken.WriteArgs  = writeArgs;

                var readArgs = new SocketAsyncEventArgs();
                readArgs.Completed += completed;
                userToken.ReadArgs  = readArgs;

                userToken.ReadArgs.UserToken = userToken.WriteArgs.UserToken = userToken;
                _concurrentQueue.Enqueue(userToken);
            }
        }