mirror of
https://github.com/BepInEx/dotnet-runtime.git
synced 2026-11-23 03:39:35 -10:00
This commit does several things: - Exposes the new `ValueTask` extensibility model being added in coreclr. The ValueTask-related files will separately be mirrored over to corefx to enable the netstandard build of System.Threading.Tasks.Extensions. - Adapts all `Stream`-derived types to return `ValueTask` instead of `Task` from `WriteAsync`. - Changes the new `WebSocket` `SendAsync` method to return `ValueTask` instead of `Task`, and updates the `ManagedWebSocket` implementation accordingly. Most `SendAsync`s on `ManagedWebSocket` should now return a `ValueTask` that's either completed synchronously (no allocation) or using a pooled object. It now uses the underlying transport's new `WriteAsync` overload that returns `ValueTask`. - Switches more uses of `ReadAsync` and `WriteAsync` over to the new overloads, including in Process, DeflateStream, BrotliStream, File, HttpClient, SslStream, WebClient, BufferedStream, CryptoStream, - Removed some unnecessary array clearing from various routines using ArrayPool (after the clearing was added we changed our minds and decided clearing was only necessary in very specific circumstances) - Implements a custom `IValueTaskSource` in Socket, such that async receives and sends become allocation-free (ammortized). `NetworkStream` then inherits this functionality, such that its new `ReadAsync` and `WriteAsync` are also allocation-free (in the unbounded channel implementations; we can subsequently add it in for bounded). - Implements a custom `IValueTaskSource` in System.Threading.Channels, such that reading and writing are ammortized allocation-free up to one concurrent reader and writer. - A few random things I noticed as I was going through, e.g. missing ConfigureAwait, some incorrect synchronization in tests, etc. - Adds a ton of new tests, mainly in System.Threading.Tasks.Extensions, System.Threading.Channels, and System.Net.Sockets. Commit migrated from https://github.com/dotnet/corefx/commit/6d1671b2cfcf130b7bc6c059bb0508073426532a
78 lines
4.1 KiB
C#
78 lines
4.1 KiB
C#
// Licensed to the .NET Foundation under one or more agreements.
|
|
// The .NET Foundation licenses this file to you under the MIT license.
|
|
// See the LICENSE file in the project root for more information.
|
|
// ------------------------------------------------------------------------------
|
|
// Changes to this file must follow the http://aka.ms/api-review process.
|
|
// ------------------------------------------------------------------------------
|
|
|
|
namespace System.Threading.Channels
|
|
{
|
|
public enum BoundedChannelFullMode
|
|
{
|
|
DropNewest = 1,
|
|
DropOldest = 2,
|
|
DropWrite = 3,
|
|
Wait = 0,
|
|
}
|
|
public sealed partial class BoundedChannelOptions : System.Threading.Channels.ChannelOptions
|
|
{
|
|
public BoundedChannelOptions(int capacity) { }
|
|
public int Capacity { get { throw null; } set { } }
|
|
public System.Threading.Channels.BoundedChannelFullMode FullMode { get { throw null; } set { } }
|
|
}
|
|
public static partial class Channel
|
|
{
|
|
public static System.Threading.Channels.Channel<T> CreateBounded<T>(int capacity) { throw null; }
|
|
public static System.Threading.Channels.Channel<T> CreateBounded<T>(System.Threading.Channels.BoundedChannelOptions options) { throw null; }
|
|
public static System.Threading.Channels.Channel<T> CreateUnbounded<T>() { throw null; }
|
|
public static System.Threading.Channels.Channel<T> CreateUnbounded<T>(System.Threading.Channels.UnboundedChannelOptions options) { throw null; }
|
|
}
|
|
public partial class ChannelClosedException : System.InvalidOperationException
|
|
{
|
|
public ChannelClosedException() { }
|
|
public ChannelClosedException(System.Exception innerException) { }
|
|
public ChannelClosedException(string message) { }
|
|
public ChannelClosedException(string message, System.Exception innerException) { }
|
|
}
|
|
public abstract partial class ChannelOptions
|
|
{
|
|
protected ChannelOptions() { }
|
|
public bool AllowSynchronousContinuations { get { throw null; } set { } }
|
|
public bool SingleReader { get { throw null; } set { } }
|
|
public bool SingleWriter { get { throw null; } set { } }
|
|
}
|
|
public abstract partial class ChannelReader<T>
|
|
{
|
|
protected ChannelReader() { }
|
|
public virtual System.Threading.Tasks.Task Completion { get { throw null; } }
|
|
public virtual System.Threading.Tasks.ValueTask<T> ReadAsync(CancellationToken cancellationToken = default) { throw null; }
|
|
public abstract bool TryRead(out T item);
|
|
public abstract System.Threading.Tasks.ValueTask<bool> WaitToReadAsync(System.Threading.CancellationToken cancellationToken=default);
|
|
}
|
|
public abstract partial class ChannelWriter<T>
|
|
{
|
|
protected ChannelWriter() { }
|
|
public void Complete(System.Exception error=null) { }
|
|
public virtual bool TryComplete(System.Exception error=null) { throw null; }
|
|
public abstract bool TryWrite(T item);
|
|
public abstract System.Threading.Tasks.ValueTask<bool> WaitToWriteAsync(System.Threading.CancellationToken cancellationToken=default);
|
|
public virtual System.Threading.Tasks.ValueTask WriteAsync(T item, System.Threading.CancellationToken cancellationToken=default) { throw null; }
|
|
}
|
|
public abstract partial class Channel<T> : System.Threading.Channels.Channel<T, T>
|
|
{
|
|
protected Channel() { }
|
|
}
|
|
public abstract partial class Channel<TWrite, TRead>
|
|
{
|
|
protected Channel() { }
|
|
public System.Threading.Channels.ChannelReader<TRead> Reader { get { throw null; } protected set { } }
|
|
public System.Threading.Channels.ChannelWriter<TWrite> Writer { get { throw null; } protected set { } }
|
|
public static implicit operator System.Threading.Channels.ChannelReader<TRead> (System.Threading.Channels.Channel<TWrite, TRead> channel) { throw null; }
|
|
public static implicit operator System.Threading.Channels.ChannelWriter<TWrite> (System.Threading.Channels.Channel<TWrite, TRead> channel) { throw null; }
|
|
}
|
|
public sealed partial class UnboundedChannelOptions : System.Threading.Channels.ChannelOptions
|
|
{
|
|
public UnboundedChannelOptions() { }
|
|
}
|
|
}
|