Example #1
0
 public override void Flush()
 {
     if (mPipeStream != null)
     {
         mPipeStream.Flush();
     }
     base.Flush();
 }
Example #2
0
        private void loadChunkedData(PipeStream stream)
        {
Next:
            string line;

            if (chunkeLength == 0)
            {
                if (!stream.TryReadWith(HeaderTypeFactory.LINE_BYTES, out line))
                {
                    return;
                }
                chunkeLength = int.Parse(line, System.Globalization.NumberStyles.HexNumber);
                if (chunkeLength == 0)
                {
                    stream.ReadFree(2);
                    var item = response;
                    pipeStream.Flush();
                    item.Stream = pipeStream;
                    response    = null;
                    pipeStream  = null;
                    Completed?.Invoke(Client, item);
                    return;
                }
                response.Length += chunkeLength;
            }
            else if (chunkeLength == -1)
            {
                if (stream.TryReadWith(HeaderTypeFactory.LINE_BYTES, out line))
                {
                    chunkeLength = 0;
                }
                else
                {
                    return;
                }
            }
            if (chunkeLength > 0)
            {
                if (pipeStream == null)
                {
                    pipeStream = new PipeStream();
                }
                while (true)
                {
                    byte[] buffer = HttpParse.GetByteBuffer();
                    int    count  = buffer.Length;
                    if (count > chunkeLength)
                    {
                        count = chunkeLength;
                    }
                    int read = stream.Read(buffer, 0, count);
                    if (read == 0)
                    {
                        return;
                    }
                    pipeStream.Write(buffer, 0, read);
                    chunkeLength -= read;
                    if (chunkeLength == 0)
                    {
                        chunkeLength = -1;
                        break;
                    }
                }
            }
            if (stream.Length > 0)
            {
                goto Next;
            }
        }
        private void loadChunkedData(PipeStream stream)
        {

        Next:
            string line;
            if (chunkeLength > 0)
            {
                if (pipeStream == null)
                    pipeStream = new PipeStream();
                while (true)
                {
                    byte[] buffer = HttpParse.GetByteBuffer();
                    int count = buffer.Length;
                    if (count > chunkeLength)
                        count = chunkeLength;
                    int read = stream.Read(buffer, 0, count);
                    if (read == 0)
                        return;
                    pipeStream.Write(buffer, 0, read);
                    chunkeLength -= read;
                    if (chunkeLength == 0)
                    {
                        chunkeLength = 0;
                        break;
                    }
                }
            }
            else
            {
                if (!stream.TryReadWith(HeaderTypeFactory.LINE_BYTES, out line))
                    return;
                if (string.IsNullOrEmpty(line))
                {
                    if (end)
                    {
                        var item = response;
                        pipeStream.Flush();
                        item.Stream = pipeStream;
                        response = null;
                        pipeStream = null;
                        end = false;
                        Completed?.Invoke(Client, item);
                        return;
                    }
                    else
                    {
                        goto Next;
                    }
                }
                else
                {
                    try
                    {
                        chunkeLength = int.Parse(line, System.Globalization.NumberStyles.HexNumber);
                        if (chunkeLength == 0)
                        {
                            end = true;
                        }
                        else
                            response.Length += chunkeLength;
                    }
                    catch (Exception e_)
                    {
                        throw e_;
                    }
                }
            }
            if (stream.Length > 0)
                goto Next;
        }