コード例 #1
0
        private void Process()
        {
            var recieveArgs = socketEventArgsPool.Pop();

            bufferManager.SetBuffer(recieveArgs);

            if (!listener.ReceiveFromAsync(recieveArgs))
            {
                ProcessReceivedData(this, recieveArgs);
            }

            StartAccept(recieveArgs);
        }
コード例 #2
0
        public void Init(IBufferManager bufferManager, IPacketsHandler packetsHandler)
        {
            _cancellationTokenSource?.Cancel();

            _cancellationTokenSource = new CancellationTokenSource();
            _cancellationToken       = _cancellationTokenSource.Token;

            _bufferManager  = bufferManager;
            _packetsHandler = packetsHandler;

            _bufferManager.SetBuffer(_socketReceiveAsyncEventArgs, _socketSendAsyncEventArgs);
            _offsetReceive = _socketReceiveAsyncEventArgs.Offset;
            _offsetSend    = _socketSendAsyncEventArgs.Offset;

            ParseReceivedData();
        }
コード例 #3
0
        /// <summary>
        /// 初始化
        /// </summary>
        public void Init()
        {
            // Allocates one large byte buffer which all I/O operations use a piece of.  This gaurds
            // against memory fragmentation
            _bufferManager.InitBuffer();
            ClientList = new List <UserToken>();
            // preallocate pool of SocketAsyncEventArgs objects

            for (int i = 0; i < _maxConnectNum; i++)
            {
                var readWriteEventArg = new SocketAsyncEventArgs();
                readWriteEventArg.Completed += IO_Completed;
                readWriteEventArg.UserToken  = new UserToken();

                // assign a byte buffer from the buffer pool to the SocketAsyncEventArg object
                _bufferManager.SetBuffer(readWriteEventArg);
                // add SocketAsyncEventArg to the pool
                _pool.Push(readWriteEventArg);
            }
        }
コード例 #4
0
            /// <summary>
            /// Initializes sender buffer.
            ///
            /// We provide separate initialization methods to allow grouping of the send and receive buffers.
            /// </summary>
            public void InitSender(IBufferManager bufferManager)
            {
                bufferManager.SetBuffer(sender);

                senderWriter = new MemoryStream(sender.Buffer, sender.Offset, sender.Count);
            }
コード例 #5
0
 /// <summary>
 /// Initializes receiver buffer.
 ///
 /// We provide separate initialization methods to allow grouping of the send and receive buffers.
 /// </summary>
 public void InitReceiver(IBufferManager bufferManager)
 {
     bufferManager.SetBuffer(receiver);
 }