Streamable HTTP resumability + redelivery + SSE polling via server-side disconnect (#1077)
Co-authored-by: Stephen Halter <halter73@gmail.com>
This commit is contained in:
parent
4cb2fd4655
commit
b8311756b4
1 changed files with 2675 additions and 246 deletions
35
src/Common/ServerSentEvents/PooledByteBufferWriter.cs
Normal file
35
src/Common/ServerSentEvents/PooledByteBufferWriter.cs
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
|
||||
// Copied from https://github.com/dotnet/runtime/blob/dcbf3413c5f7ae431a68fd0d3f09af095b525887/src/libraries/System.Net.ServerSentEvents/src/System/Net/ServerSentEvents/PooledByteBufferWriter.cs
|
||||
|
||||
using System.Buffers;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace System.Net.ServerSentEvents;
|
||||
|
||||
internal sealed class PooledByteBufferWriter : IBufferWriter<byte>, IDisposable
|
||||
{
|
||||
private const int MinimumBufferSize = 256;
|
||||
private ArrayBuffer _buffer = new(initialSize: 256, usePool: true);
|
||||
|
||||
public void Advance(int count) => _buffer.Commit(count);
|
||||
|
||||
public Memory<byte> GetMemory(int sizeHint = 0)
|
||||
{
|
||||
_buffer.EnsureAvailableSpace(Math.Max(sizeHint, MinimumBufferSize));
|
||||
return _buffer.AvailableMemory;
|
||||
}
|
||||
|
||||
public Span<byte> GetSpan(int sizeHint = 0)
|
||||
{
|
||||
_buffer.EnsureAvailableSpace(Math.Max(sizeHint, MinimumBufferSize));
|
||||
return _buffer.AvailableSpan;
|
||||
}
|
||||
|
||||
public ReadOnlyMemory<byte> WrittenMemory => _buffer.ActiveMemory;
|
||||
public int Capacity => _buffer.Capacity;
|
||||
public int WrittenCount => _buffer.ActiveLength;
|
||||
public void Reset() => _buffer.Discard(_buffer.ActiveLength);
|
||||
public void Dispose() => _buffer.Dispose();
|
||||
}
|
||||
Loading…
Reference in a new issue