public IWritableChannel MakeWriteableChannel(IWritableChannel channel, Func <IReadableChannel, IWritableChannel, Task> consume)
        {
            var newChannel = new MemoryPoolChannel(_pool);

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

            return(newChannel);
        }
Exemple #2
0
        internal WritableBuffer(MemoryPoolChannel channel, MemoryPool pool, MemoryBlockSegment segment)
        {
            _channel = channel;
            _pool    = pool;

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

            _head      = segment;
            _headIndex = _tailIndex;
        }
        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);
        }
        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);
        }
Exemple #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);
        }
Exemple #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);
        }
        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);
        }
Exemple #8
0
 public ReadableChannel(MemoryPool pool)
 {
     _channel = new MemoryPoolChannel(pool);
 }
 internal ReadableBuffer(MemoryPoolChannel channel, ReadCursor start, ReadCursor end) :
     this(channel, start, end, isOwner : false)
 {
 }