Consume() public method

public Consume ( Firefly.Http.Baton baton, Exception>.Action callback ) : bool
baton Firefly.Http.Baton
callback Exception>.Action
return bool
Esempio n. 1
0
 public FrameTestsBase()
 {
     Services = new FakeServices();
     App = new FakeApp();
     Output = new FakeOutput();
     Input = new FakeInput();
     Frame = new Frame(
         new FrameContext
         {
             Services = Services,
             App = App.Call,
             Write = Output.Write,
             Flush = Output.Flush,
             End = Output.End,
         });
     Input.Consume = (baton, callback) => Frame.Consume(baton, (frame, ex) => callback(ex));
 }
Esempio n. 2
0
        private void Go(bool newFrame, Frame frame)
        {
            if (newFrame)
            {
                frame = _frame = new Frame(
                    new FrameContext
                    {
                        Services = _services,
                        App = _app,
                        Write = _socketSender.Write,
                        Flush = _socketSender.Flush,
                        End = ProduceEnd
                    });

                if (_baton.Buffer.Count != 0)
                {
                    if (frame.Consume(
                        _baton,
                        _frameConsumeCallback,
                        _fault))
                    {
                        return;
                    }
                }
            }

            while (frame.LocalIntakeFin == false)
            {
                SocketError recvError;
                var buffer = _baton.Available(128);
                var receiveCount = _socket.Receive(
                    buffer.Array,
                    buffer.Offset,
                    buffer.Count,
                    SocketFlags.None,
                    out recvError);

                if (recvError == SocketError.WouldBlock)
                {
                    _baton.Free();
                    if (ReceiveAsync(frame))
                    {
                        return;
                    }

                    continue;
                }

                if (recvError != SocketError.Success || receiveCount == 0)
                {
                    _baton.RemoteIntakeFin = true;
                }
                else
                {
                    _baton.Extend(receiveCount);
                }

                if (frame.Consume(
                    _baton,
                    _frameConsumeCallback,
                    _fault))
                {
                    return;
                }
            }
        }
Esempio n. 3
0
        private void Go(bool newFrame, Frame frame)
        {
            if (newFrame)
            {
                frame = _frame = new Frame(
                    new FrameContext
                {
                    Services = _services,
                    Socket   = _socket,
                    App      = _app,
                    Write    = _socketSender.Write,
                    Flush    = _socketSender.Flush,
                    End      = ProduceEnd
                });

                if (_baton.Buffer.Count != 0)
                {
                    if (frame.Consume(
                            _baton,
                            _frameConsumeCallback))
                    {
                        return;
                    }
                }
            }

            while (frame.LocalIntakeFin == false)
            {
                SocketError recvError;
                var         buffer       = _baton.Available(128);
                var         receiveCount = _socket.Receive(
                    buffer.Array,
                    buffer.Offset,
                    buffer.Count,
                    SocketFlags.None,
                    out recvError);

                if (recvError == SocketError.WouldBlock)
                {
                    _baton.Free();
                    if (ReceiveAsync(frame))
                    {
                        return;
                    }

                    continue;
                }

                if (recvError != SocketError.Success || receiveCount == 0)
                {
                    _baton.RemoteIntakeFin = true;
                }
                else
                {
                    _baton.Extend(receiveCount);
                }

                if (frame.Consume(
                        _baton,
                        _frameConsumeCallback))
                {
                    return;
                }
            }
        }