Beispiel #1
0
        public override void Write(byte[] b, int off, int len)
        {
            while (0 < len)
            {
                int capacity = _buffer.Length - cnt;
                if (cnt == HDR_SIZE && capacity < len)
                {
                    // Our block to write is bigger than the packet size,
                    // stream it out as-is to avoid unnecessary copies.
                    PacketLineOut.FormatLength(_buffer, _buffer.Length);
                    _out.Write(_buffer, 0, HDR_SIZE);
                    _out.Write(b, off, capacity);
                    off += capacity;
                    len -= capacity;
                }
                else
                {
                    if (capacity == 0)
                    {
                        WriteBuffer();
                    }

                    int n = Math.Min(len, capacity);
                    Array.Copy(b, off, _buffer, cnt, n);
                    cnt += n;
                    off += n;
                    len -= n;
                }
            }
        }
Beispiel #2
0
 private void WriteBuffer()
 {
     PacketLineOut.FormatLength(_buffer, cnt);
     _out.Write(_buffer, 0, cnt);
     cnt = HDR_SIZE;
 }