コード例 #1
0
ファイル: ChannelFactory.cs プロジェクト: myFirstway/Channels
        public IWritableChannel MakeWriteableChannel(IWritableChannel channel, Func <IReadableChannel, IWritableChannel, Task> consume)
        {
            var newChannel = new MemoryPoolChannel(_pool);

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

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

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

            _head      = segment;
            _headIndex = _tailIndex;
        }
コード例 #3
0
ファイル: ChannelFactory.cs プロジェクト: myFirstway/Channels
        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);
        }
コード例 #4
0
ファイル: ReadableBuffer.cs プロジェクト: myFirstway/Channels
        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);
        }
コード例 #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);
        }
コード例 #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);
        }
コード例 #7
0
ファイル: ChannelFactory.cs プロジェクト: myFirstway/Channels
        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);
        }
コード例 #8
0
ファイル: ReadableChannel.cs プロジェクト: ericl85/Channels
 public ReadableChannel(MemoryPool pool)
 {
     _channel = new MemoryPoolChannel(pool);
 }
コード例 #9
0
ファイル: ReadableBuffer.cs プロジェクト: myFirstway/Channels
 internal ReadableBuffer(MemoryPoolChannel channel, ReadCursor start, ReadCursor end) :
     this(channel, start, end, isOwner : false)
 {
 }