Ejemplo n.º 1
0
        public IWritableChannel MakeWriteableChannel(IWritableChannel channel, Func <IReadableChannel, IWritableChannel, Task> consume)
        {
            var newChannel = new MemoryPoolChannel(_pool);

            consume(newChannel, channel).ContinueWith(t =>
            {
            });

            return(newChannel);
        }
Ejemplo n.º 2
0
        internal WritableBuffer(MemoryPoolChannel channel, MemoryPool pool, MemoryBlockSegment segment)
        {
            _channel = channel;
            _pool    = pool;

            _tail      = segment;
            _tailIndex = segment?.End ?? 0;

            _head      = segment;
            _headIndex = _tailIndex;
        }
Ejemplo n.º 3
0
        public IReadableChannel MakeReadableChannel(IReadableChannel channel, Func <IReadableChannel, IWritableChannel, Task> produce)
        {
            var newChannel = new MemoryPoolChannel(_pool);

            // TODO: Avoid closure
            newChannel.OnStartReading(() =>
            {
                produce(channel, newChannel).ContinueWith(t =>
                {
                });
            });

            return(newChannel);
        }
Ejemplo n.º 4
0
        internal ReadableBuffer(MemoryPoolChannel channel, ReadCursor start, ReadCursor end, bool isOwner)
        {
            _channel  = channel;
            _start    = start;
            _end      = end;
            _isOwner  = isOwner;
            _disposed = false;

            var begin = start;

            begin.TryGetBuffer(end, out _span);

            begin   = start;
            _length = begin.GetLength(end);
        }
Ejemplo n.º 5
0
        public IWritableChannel MakeWriteableChannel(Stream stream)
        {
            if (!stream.CanWrite)
            {
                throw new InvalidOperationException();
            }

            var channel = new MemoryPoolChannel(_pool);

            channel.CopyToAsync(stream).ContinueWith((task) =>
            {
                channel.CompleteReading();
            });

            return(channel);
        }
Ejemplo n.º 6
0
        public IWritableChannel CreateWritableChannel(Stream stream)
        {
            if (!stream.CanWrite)
            {
                throw new InvalidOperationException();
            }

            var channel = new MemoryPoolChannel(_pool);

            channel.CopyToAsync(stream).ContinueWith((task, state) =>
            {
                ((Stream)state).Dispose();
            },
                                                     stream);

            return(channel);
        }
Ejemplo n.º 7
0
        public IReadableChannel MakeReadableChannel(Stream stream)
        {
            if (!stream.CanRead)
            {
                throw new InvalidOperationException();
            }

            var channel = new MemoryPoolChannel(_pool);

            channel.OnStartReading(() =>
            {
                stream.CopyToAsync(channel).ContinueWith(task =>
                {
                });
            });

            return(channel);
        }
Ejemplo n.º 8
0
 public ReadableChannel(MemoryPool pool)
 {
     _channel = new MemoryPoolChannel(pool);
 }
Ejemplo n.º 9
0
 internal ReadableBuffer(MemoryPoolChannel channel, ReadCursor start, ReadCursor end) :
     this(channel, start, end, isOwner : false)
 {
 }