Exemple #1
0
 private void ReadHeader(PacketToken token)
 {
     token.ID      = (ushort)((token.Header[0] << 8) | (token.Header[1]));
     token.Length  = (token.Header[2] << 16) | (token.Header[3] << 8) | (token.Header[4]);
     token.Version = (ushort)((token.Header[5] << 8) | (token.Header[6]));
     token.Body    = new byte[token.Length];
 }
Exemple #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SocketAsyncEventArgsPool"/> class with
 /// the specified capacity.
 /// </summary>
 /// <param name="capacity">Max capacity of the pool.</param>
 public SocketAsyncEventArgsPool(int capacity)
 {
     Capacity = capacity;
     Pool     = new Stack <SocketAsyncEventArgs>(capacity);
     for (int i = 0; i < capacity; i++)
     {
         var args         = new SocketAsyncEventArgs();
         var packetBuffer = new PacketToken(args);
         Push(args);
     }
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="SocketAsyncEventArgsPool"/> class with
 /// the specified capacity.
 /// </summary>
 /// <param name="capacity">Max capacity of the pool.</param>
 public SocketAsyncEventArgsPool(int capacity)
 {
     Capacity = capacity;
     Pool = new Stack<SocketAsyncEventArgs>(capacity);
     for (int i = 0; i < capacity; i++)
     {
         var args = new SocketAsyncEventArgs();
         var packetBuffer = new PacketToken(args);
         Push(args);
     }
 }
        private void SetAsyncOperationPools()
        {
            BufferManager = new PacketBufferManager(Settings.ReceiveOperationCount, Settings.SendOperationCount, Settings.BufferSize);

            for (int i = 0; i < ReceiveEventPool.Capacity; i++)
            {
                var args = new SocketAsyncEventArgs();
                args.Completed += AsyncOperationCompleted;
                BufferManager.SetBuffer(args);
                PacketToken.Create(args);
                ReceiveEventPool.Push(args);
            }
            for (int i = 0; i < SendEventPool.Capacity; i++)
            {
                var args = new SocketAsyncEventArgs();
                args.Completed += AsyncOperationCompleted;
                BufferManager.SetBuffer(args);
                PacketToken.Create(args);
                SendEventPool.Push(args);
            }
        }
 private void ReadHeader(PacketToken token)
 {
     token.ID = (ushort)((token.Header[0] << 8) | (token.Header[1]));
     token.Length = (token.Header[2] << 16) | (token.Header[3] << 8) | (token.Header[4]);
     token.Version = (ushort)((token.Header[5] << 8) | (token.Header[6]));
     token.Body = new byte[token.Length];
 }