Exemplo n.º 1
0
 public override int Read(byte[] buffer, int offset, int count)
 {
     if (LimitBytesRead != 0)
     {
         int num = LimitBytesRead - TotalBytesRead;
         if (num == 0)
         {
             return(0);
         }
         if (num > buffer.Length)
         {
             num = buffer.Length;
         }
         if (_receiverHelper.HasData)
         {
             BytesRead = _receiverHelper.Read(buffer, offset, num);
         }
         else
         {
             BytesRead = _baseStream.Read(buffer, offset, num);
         }
     }
     else if (_receiverHelper.HasData)
     {
         BytesRead = _receiverHelper.Read(buffer, offset, count);
     }
     else
     {
         BytesRead = _baseStream.Read(buffer, offset, count);
     }
     TotalBytesRead += BytesRead;
     return(BytesRead);
 }
Exemplo n.º 2
0
        private IEnumerable <BytesWraper> ReceiveMessageBody(Stream stream)
        {
            BytesWraper bytesWraper = new BytesWraper();
            int         bufferSize  = _request.TcpClient.ReceiveBufferSize;

            byte[] buffer       = bytesWraper.Value = new byte[bufferSize];
            int    begBytesRead = 0;

            if (stream is GZipStream || stream is DeflateStream)
            {
                begBytesRead = stream.Read(buffer, 0, bufferSize);
            }
            else
            {
                if (_receiverHelper.HasData)
                {
                    begBytesRead = _receiverHelper.Read(buffer, 0, bufferSize);
                }
                if (begBytesRead < bufferSize)
                {
                    begBytesRead += stream.Read(buffer, begBytesRead, bufferSize - begBytesRead);
                }
            }
            bytesWraper.Length = begBytesRead;
            yield return(bytesWraper);

            bool isHtml = FindSignature(buffer, begBytesRead, _openHtmlSignature);

            if (isHtml && FindSignature(buffer, begBytesRead, _closeHtmlSignature))
            {
                yield break;
            }
            int num;

            while (true)
            {
                num = stream.Read(buffer, 0, bufferSize);
                if (isHtml)
                {
                    if (num == 0)
                    {
                        WaitData();
                        continue;
                    }
                    if (FindSignature(buffer, num, _closeHtmlSignature))
                    {
                        break;
                    }
                }
                else if (num == 0)
                {
                    yield break;
                }
                bytesWraper.Length = num;
                yield return(bytesWraper);
            }
            bytesWraper.Length = num;
            yield return(bytesWraper);
        }