コード例 #1
0
ファイル: BigEndianInt32Frame.cs プロジェクト: ymf1/NetGain
 protected virtual void Write(NetContext context, Connection connection, Stream stream)
 {
     byte[] buffer = null;
     try
     {
         buffer    = context.GetBuffer();
         buffer[0] = (byte)(value >> 24);
         buffer[1] = (byte)(value >> 16);
         buffer[2] = (byte)(value >> 8);
         buffer[3] = (byte)(value);
         stream.Write(buffer, 0, 4);
     } finally
     {
         context.Recycle(buffer);
     }
 }
コード例 #2
0
ファイル: BigEndianInt32Frame.cs プロジェクト: mpotra/NetGain
 protected virtual void Write(NetContext context, Connection connection, Stream stream)
 {
     byte[] buffer = null;
     try
     {
         buffer = context.GetBuffer();
         buffer[0] = (byte) (value >> 24);
         buffer[1] = (byte) (value >> 16);
         buffer[2] = (byte) (value >> 8);
         buffer[3] = (byte) (value);
         stream.Write(buffer, 0, 4);
     } finally
     {
         context.Recycle(buffer);   
     }
 }
コード例 #3
0
ファイル: BufferStream.cs プロジェクト: yaserOSource/NetGain
        private void Grow(int newLength)
        {
            if (maxLength > 0 && newLength > maxLength)
            {
                throw new InvalidOperationException(string.Format("Buffer maximum length exceeded ({0} vs {1})",
                                                                  newLength, maxLength));
            }
            int spaceRequired = checked (newLength + offset);
            int chunkCount    = spaceRequired / NetContext.BufferSize;

            if ((spaceRequired % NetContext.BufferSize) != 0)
            {
                chunkCount++;
            }
            while (buffers.Count < chunkCount)
            {
                buffers.Push(context.GetBuffer());
            }
        }
コード例 #4
0
ファイル: StringFrame.cs プロジェクト: mpotra/NetGain
 protected virtual void Write(NetContext context, Connection connection, Stream stream)
 {
     byte[] buffer = null;
     try
     {
         buffer = context.GetBuffer();
         if(encoding.GetMaxByteCount(value.Length) <= buffer.Length || encoding.GetByteCount(value) <= buffer.Length)
         {
             int len = encoding.GetBytes(value, 0, value.Length, buffer, 0);
             stream.Write(buffer, 0, len);
         } else
         { // need to do things the hard way...
             throw new NotImplementedException();
         }
     }
     finally
     {
         context.Recycle(buffer);
     }
 }
コード例 #5
0
ファイル: StringFrame.cs プロジェクト: ymf1/NetGain
 protected virtual void Write(NetContext context, Connection connection, Stream stream)
 {
     byte[] buffer = null;
     try
     {
         buffer = context.GetBuffer();
         if (encoding.GetMaxByteCount(value.Length) <= buffer.Length || encoding.GetByteCount(value) <= buffer.Length)
         {
             int len = encoding.GetBytes(value, 0, value.Length, buffer, 0);
             stream.Write(buffer, 0, len);
         }
         else
         { // need to do things the hard way...
             throw new NotImplementedException();
         }
     }
     finally
     {
         context.Recycle(buffer);
     }
 }
コード例 #6
0
ファイル: TcpHandler.cs プロジェクト: woxihuanjia/NetGain
        void SetFullBuffer(SocketAsyncEventArgs args)
        {
            var buffer = context.GetBuffer();

            args.SetBuffer(buffer, 0, buffer.Length);
        }