@@ -85,7 +85,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Filter
 
         private Task<int> ReadAsync(ArraySegment<byte> buffer)
         {
-            return _input.ReadAsync(buffer);
+            return _input.ReadAsync(buffer.Array, buffer.Offset, buffer.Count);
         }
     }
 }
﻿// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNet.Server.Kestrel.Http;

namespace Microsoft.AspNet.Server.Kestrel.Filter
{
    public class LibuvStream : Stream
    {
        private readonly SocketInput _input;
        private readonly ISocketOutput _output;

        public LibuvStream(SocketInput input, ISocketOutput output)
        {
            _input = input;
            _output = output;
        }

        public override bool CanRead => true;

        public override bool CanSeek => false;

        public override bool CanWrite => true;

        public override long Length
        {
            get
            {
                throw new NotSupportedException();
            }
        }

        public override long Position
        {
            get
            {
                throw new NotSupportedException();
            }
            set
            {
                throw new NotSupportedException();
            }
        }

        public override long Seek(long offset, SeekOrigin origin)
        {
            throw new NotSupportedException();
        }

        public override void SetLength(long value)
        {
            throw new NotSupportedException();
        }

        public override int Read(byte[] buffer, int offset, int count)
        {
            return ReadAsync(new ArraySegment<byte>(buffer, offset, count)).GetAwaiter().GetResult();
        }

        public override Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
        {
            return ReadAsync(new ArraySegment<byte>(buffer, offset, count));
        }

        public override void Write(byte[] buffer, int offset, int count)
        {
            var segment = new ArraySegment<byte>(buffer, offset, count);
            _output.Write(segment);
        }

        public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken token)
        {
            var segment = new ArraySegment<byte>(buffer, offset, count);
            return _output.WriteAsync(segment, cancellationToken: token);
        }

        public override void Flush()
        {
            // No-op since writes are immediate.
        }

        private Task<int> ReadAsync(ArraySegment<byte> buffer)
        {
            return _input.ReadAsync(buffer);
        }
    }
}

Worth just overloading this on `SocketInput`? Notice a bunch of other methods here create an array segment to call this method. At least least, you could clean all of those up to avoid creating the `ArraySegment`