Skip to content
This repository has been archived by the owner on Dec 18, 2018. It is now read-only.

Commit

Permalink
Respond to corefxlab rename (build break)
Browse files Browse the repository at this point in the history
  • Loading branch information
benaadams committed Mar 21, 2017
1 parent 24ed932 commit 39f3701
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ private async Task ReadInputAsync()

try
{
var array = block.Memory.GetArray();
var array = block.Buffer.GetArray();
try
{
bytesRead = await _filteredStream.ReadAsync(array.Array, array.Offset, array.Count);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,12 +234,12 @@ private unsafe Libuv.uv_buf_t OnAlloc(UvStreamHandle handle, int suggestedSize)
var currentWritableBuffer = Input.Writer.Alloc(MinAllocBufferSize);
_currentWritableBuffer = currentWritableBuffer;
void* dataPtr;
var tryGetPointer = currentWritableBuffer.Memory.TryGetPointer(out dataPtr);
var tryGetPointer = currentWritableBuffer.Buffer.TryGetPointer(out dataPtr);
Debug.Assert(tryGetPointer);

return handle.Libuv.buf_init(
(IntPtr)dataPtr,
currentWritableBuffer.Memory.Length);
currentWritableBuffer.Buffer.Length);
}

private static void ReadCallback(UvStreamHandle handle, int status, object state)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using System.Diagnostics;
using System.Buffers;
using System.IO.Pipelines;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http
Expand Down Expand Up @@ -85,28 +83,28 @@ public static Span<byte> ToSpan(this ReadableBuffer buffer)
return buffer.ToArray();
}

public static ArraySegment<byte> GetArray(this Memory<byte> memory)
public static ArraySegment<byte> GetArray(this Buffer<byte> buffer)
{
ArraySegment<byte> result;
if (!memory.TryGetArray(out result))
if (!buffer.TryGetArray(out result))
{
throw new InvalidOperationException("Memory backed by array was expected");
throw new InvalidOperationException("Buffer backed by array was expected");
}
return result;
}

// Temporary until the fast write implementation propagates from corefx
public unsafe static void WriteFast(this WritableBuffer buffer, ReadOnlySpan<byte> source)
{
var dest = buffer.Memory.Span;
var dest = buffer.Buffer.Span;
var destLength = dest.Length;

if (destLength == 0)
{
buffer.Ensure();

// Get the new span and length
dest = buffer.Memory.Span;
dest = buffer.Buffer.Span;
destLength = dest.Length;
}

Expand All @@ -132,7 +130,7 @@ private static unsafe void WriteMultiBuffer(this WritableBuffer buffer, ReadOnly
{
while (remaining > 0)
{
var writable = Math.Min(remaining, buffer.Memory.Length);
var writable = Math.Min(remaining, buffer.Buffer.Length);

buffer.Ensure(writable);

Expand All @@ -141,7 +139,7 @@ private static unsafe void WriteMultiBuffer(this WritableBuffer buffer, ReadOnly
continue;
}

fixed (byte* pDest = &buffer.Memory.Span.DangerousGetPinnableReference())
fixed (byte* pDest = &buffer.Buffer.Span.DangerousGetPinnableReference())
{
Unsafe.CopyBlockUnaligned(pDest, pSource + offset, (uint)writable);
}
Expand All @@ -158,16 +156,16 @@ public unsafe static void WriteAscii(this WritableBuffer buffer, string data)
{
if (!string.IsNullOrEmpty(data))
{
if (buffer.Memory.IsEmpty)
if (buffer.Buffer.IsEmpty)
{
buffer.Ensure();
}

// Fast path, try copying to the available memory directly
if (data.Length <= buffer.Memory.Length)
if (data.Length <= buffer.Buffer.Length)
{
fixed (char* input = data)
fixed (byte* output = &buffer.Memory.Span.DangerousGetPinnableReference())
fixed (byte* output = &buffer.Buffer.Span.DangerousGetPinnableReference())
{
EncodeAsciiCharsToBytes(input, output, data.Length);
}
Expand All @@ -186,15 +184,15 @@ public unsafe static void WriteNumeric(this WritableBuffer buffer, ulong number)
{
const byte AsciiDigitStart = (byte)'0';

if (buffer.Memory.IsEmpty)
if (buffer.Buffer.IsEmpty)
{
buffer.Ensure();
}

// Fast path, try copying to the available memory directly
var bytesLeftInBlock = buffer.Memory.Length;
var bytesLeftInBlock = buffer.Buffer.Length;
var simpleWrite = true;
fixed (byte* output = &buffer.Memory.Span.DangerousGetPinnableReference())
fixed (byte* output = &buffer.Buffer.Span.DangerousGetPinnableReference())
{
var start = output;
if (number < 10 && bytesLeftInBlock >= 1)
Expand Down Expand Up @@ -266,7 +264,7 @@ private unsafe static void WriteAsciiMultiWrite(this WritableBuffer buffer, stri

while (remaining > 0)
{
var writable = Math.Min(remaining, buffer.Memory.Length);
var writable = Math.Min(remaining, buffer.Buffer.Length);

buffer.Ensure(writable);

Expand All @@ -275,7 +273,7 @@ private unsafe static void WriteAsciiMultiWrite(this WritableBuffer buffer, stri
continue;
}

fixed (byte* output = &buffer.Memory.Span.DangerousGetPinnableReference())
fixed (byte* output = &buffer.Buffer.Span.DangerousGetPinnableReference())
{
EncodeAsciiCharsToBytes(inputSlice, output, writable);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class UvWriteReq : UvRequest

private LibuvAwaitable<UvWriteReq> _awaitable = new LibuvAwaitable<UvWriteReq>();
private List<GCHandle> _pins = new List<GCHandle>(BUFFER_COUNT + 1);
private List<MemoryHandle> _handles = new List<MemoryHandle>(BUFFER_COUNT + 1);
private List<BufferHandle> _handles = new List<BufferHandle>(BUFFER_COUNT + 1);

public UvWriteReq(IKestrelTrace logger) : base(logger)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ public async Task CopyToAsyncDoesNotCopyBlocks(FrameRequestHeaders headers, stri
var bytes = Encoding.ASCII.GetBytes(data[0]);
var buffer = socketInput.Writer.Alloc(2048);
ArraySegment<byte> block;
Assert.True(buffer.Memory.TryGetArray(out block));
Assert.True(buffer.Buffer.TryGetArray(out block));
Buffer.BlockCopy(bytes, 0, block.Array, block.Offset, bytes.Length);
buffer.Advance(bytes.Length);
await buffer.FlushAsync();
Expand All @@ -296,7 +296,7 @@ public async Task CopyToAsyncDoesNotCopyBlocks(FrameRequestHeaders headers, stri
writeTcs = new TaskCompletionSource<byte[]>();
bytes = Encoding.ASCII.GetBytes(data[1]);
buffer = socketInput.Writer.Alloc(2048);
Assert.True(buffer.Memory.TryGetArray(out block));
Assert.True(buffer.Buffer.TryGetArray(out block));
Buffer.BlockCopy(bytes, 0, block.Array, block.Offset, bytes.Length);
buffer.Advance(bytes.Length);
await buffer.FlushAsync();
Expand Down

0 comments on commit 39f3701

Please sign in to comment.