Exemple #1
0
        private PendingWrite CreatePendingWrite(IActorRef commander, Tcp.WriteCommand write)
        {
            Func <Tcp.WriteCommand, Tcp.WriteCommand, PendingWrite> create = null;

            create = (head, tail) =>
            {
                if (head == IO.Tcp.Write.Empty)
                {
                    return(tail == IO.Tcp.Write.Empty
                        ? EmptyPendingWrite.Instance
                        : create(tail, IO.Tcp.Write.Empty));
                }
                var w = head as Tcp.Write;
                if (w != null && w.Data.NonEmpty)
                {
                    return(CreatePendingBufferWrite(commander, w.Data, w.Ack, tail));
                }
                //TODO: Port file IO
                var cwrite = head as Tcp.CompoundWrite;
                if (cwrite != null)
                {
                    return(create(cwrite.Head, cwrite.TailCommand));
                }
                if (w != null)  // empty write with either an ACK or a non-standard NoACK
                {
                    if (w.WantsAck)
                    {
                        commander.Tell(w.Ack);
                    }
                    return(create(tail, IO.Tcp.Write.Empty));
                }
                throw new InvalidOperationException("Non reachable code");
            };
            return(create(write, IO.Tcp.Write.Empty));
        }
Exemple #2
0
 public PendingBufferWrite(
     TcpConnection connection,
     IActorRef commander,
     ByteString remainingData,
     object ack,
     ByteBuffer buffer,
     Tcp.WriteCommand tail)
 {
     _connection    = connection;
     _commander     = commander;
     _remainingData = remainingData;
     _ack           = ack;
     _buffer        = buffer;
     _tail          = tail;
 }
Exemple #3
0
        private PendingWrite CreatePendingBufferWrite(IActorRef commander, ByteString data, Tcp.Event ack, Tcp.WriteCommand tail)
        {
            var buffer = _tcp.BufferPool.Acquire();

            try
            {
                var copied = data.CopyToBuffer(buffer);
                buffer.Flip();
                return(new PendingBufferWrite(this, commander, data.Drop(copied), ack, buffer, tail));
            }
            catch (Exception)
            {
                _tcp.BufferPool.Release(buffer);
                throw;
            }
        }