mirror of
https://github.com/BepInEx/dotnet-runtime.git
synced 2026-11-22 19:10:41 -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
135 lines
8.6 KiB
C#
135 lines
8.6 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.Net.WebSockets
|
|
{
|
|
public readonly partial struct ValueWebSocketReceiveResult
|
|
{
|
|
private readonly int _dummy;
|
|
public ValueWebSocketReceiveResult(int count, System.Net.WebSockets.WebSocketMessageType messageType, bool endOfMessage) { throw null; }
|
|
public int Count { get { throw null; } }
|
|
public bool EndOfMessage { get { throw null; } }
|
|
public System.Net.WebSockets.WebSocketMessageType MessageType { get { throw null; } }
|
|
}
|
|
public abstract partial class WebSocket : System.IDisposable
|
|
{
|
|
protected WebSocket() { }
|
|
public abstract System.Nullable<System.Net.WebSockets.WebSocketCloseStatus> CloseStatus { get; }
|
|
public abstract string CloseStatusDescription { get; }
|
|
public static System.TimeSpan DefaultKeepAliveInterval { get { throw null; } }
|
|
public abstract System.Net.WebSockets.WebSocketState State { get; }
|
|
public abstract string SubProtocol { get; }
|
|
public abstract void Abort();
|
|
public abstract System.Threading.Tasks.Task CloseAsync(System.Net.WebSockets.WebSocketCloseStatus closeStatus, string statusDescription, System.Threading.CancellationToken cancellationToken);
|
|
public abstract System.Threading.Tasks.Task CloseOutputAsync(System.Net.WebSockets.WebSocketCloseStatus closeStatus, string statusDescription, System.Threading.CancellationToken cancellationToken);
|
|
public static System.ArraySegment<byte> CreateClientBuffer(int receiveBufferSize, int sendBufferSize) { throw null; }
|
|
[System.ComponentModel.EditorBrowsableAttribute((System.ComponentModel.EditorBrowsableState)(1))]
|
|
public static System.Net.WebSockets.WebSocket CreateClientWebSocket(System.IO.Stream innerStream, string subProtocol, int receiveBufferSize, int sendBufferSize, System.TimeSpan keepAliveInterval, bool useZeroMaskingKey, System.ArraySegment<byte> internalBuffer) { throw null; }
|
|
public static System.Net.WebSockets.WebSocket CreateFromStream(System.IO.Stream stream, bool isServer, string subProtocol, System.TimeSpan keepAliveInterval, System.Memory<byte> buffer=default(System.Memory<byte>)) { throw null; }
|
|
public static System.ArraySegment<byte> CreateServerBuffer(int receiveBufferSize) { throw null; }
|
|
public abstract void Dispose();
|
|
[System.ComponentModel.EditorBrowsableAttribute((System.ComponentModel.EditorBrowsableState)(1))]
|
|
[System.ObsoleteAttribute("This API supports the .NET Framework infrastructure and is not intended to be used directly from your code.")]
|
|
public static bool IsApplicationTargeting45() { throw null; }
|
|
protected static bool IsStateTerminal(System.Net.WebSockets.WebSocketState state) { throw null; }
|
|
public abstract System.Threading.Tasks.Task<System.Net.WebSockets.WebSocketReceiveResult> ReceiveAsync(System.ArraySegment<byte> buffer, System.Threading.CancellationToken cancellationToken);
|
|
public virtual System.Threading.Tasks.ValueTask<System.Net.WebSockets.ValueWebSocketReceiveResult> ReceiveAsync(System.Memory<byte> buffer, System.Threading.CancellationToken cancellationToken) { throw null; }
|
|
[System.ComponentModel.EditorBrowsableAttribute((System.ComponentModel.EditorBrowsableState)(1))]
|
|
public static void RegisterPrefixes() { }
|
|
public abstract System.Threading.Tasks.Task SendAsync(System.ArraySegment<byte> buffer, System.Net.WebSockets.WebSocketMessageType messageType, bool endOfMessage, System.Threading.CancellationToken cancellationToken);
|
|
public virtual System.Threading.Tasks.ValueTask SendAsync(System.ReadOnlyMemory<byte> buffer, System.Net.WebSockets.WebSocketMessageType messageType, bool endOfMessage, System.Threading.CancellationToken cancellationToken) { throw null; }
|
|
protected static void ThrowOnInvalidState(System.Net.WebSockets.WebSocketState state, params System.Net.WebSockets.WebSocketState[] validStates) { }
|
|
}
|
|
public enum WebSocketCloseStatus
|
|
{
|
|
Empty = 1005,
|
|
EndpointUnavailable = 1001,
|
|
InternalServerError = 1011,
|
|
InvalidMessageType = 1003,
|
|
InvalidPayloadData = 1007,
|
|
MandatoryExtension = 1010,
|
|
MessageTooBig = 1009,
|
|
NormalClosure = 1000,
|
|
PolicyViolation = 1008,
|
|
ProtocolError = 1002,
|
|
}
|
|
public abstract partial class WebSocketContext
|
|
{
|
|
public abstract System.Net.CookieCollection CookieCollection { get; }
|
|
public abstract System.Collections.Specialized.NameValueCollection Headers { get; }
|
|
public abstract bool IsAuthenticated { get; }
|
|
public abstract bool IsLocal { get; }
|
|
public abstract bool IsSecureConnection { get; }
|
|
public abstract string Origin { get; }
|
|
public abstract System.Uri RequestUri { get; }
|
|
public abstract string SecWebSocketKey { get; }
|
|
public abstract System.Collections.Generic.IEnumerable<string> SecWebSocketProtocols { get; }
|
|
public abstract string SecWebSocketVersion { get; }
|
|
public abstract System.Security.Principal.IPrincipal User { get; }
|
|
public abstract System.Net.WebSockets.WebSocket WebSocket { get; }
|
|
}
|
|
public enum WebSocketError
|
|
{
|
|
ConnectionClosedPrematurely = 8,
|
|
Faulted = 2,
|
|
HeaderError = 7,
|
|
InvalidMessageType = 1,
|
|
InvalidState = 9,
|
|
NativeError = 3,
|
|
NotAWebSocket = 4,
|
|
Success = 0,
|
|
UnsupportedProtocol = 6,
|
|
UnsupportedVersion = 5,
|
|
}
|
|
public sealed partial class WebSocketException : System.ComponentModel.Win32Exception
|
|
{
|
|
public WebSocketException() { }
|
|
public WebSocketException(int nativeError) { }
|
|
public WebSocketException(int nativeError, System.Exception innerException) { }
|
|
public WebSocketException(int nativeError, string message) { }
|
|
public WebSocketException(System.Net.WebSockets.WebSocketError error) { }
|
|
public WebSocketException(System.Net.WebSockets.WebSocketError error, System.Exception innerException) { }
|
|
public WebSocketException(System.Net.WebSockets.WebSocketError error, int nativeError) { }
|
|
public WebSocketException(System.Net.WebSockets.WebSocketError error, int nativeError, System.Exception innerException) { }
|
|
public WebSocketException(System.Net.WebSockets.WebSocketError error, int nativeError, string message) { }
|
|
public WebSocketException(System.Net.WebSockets.WebSocketError error, int nativeError, string message, System.Exception innerException) { }
|
|
public WebSocketException(System.Net.WebSockets.WebSocketError error, string message) { }
|
|
public WebSocketException(System.Net.WebSockets.WebSocketError error, string message, System.Exception innerException) { }
|
|
public WebSocketException(string message) { }
|
|
public WebSocketException(string message, System.Exception innerException) { }
|
|
public override int ErrorCode { get { throw null; } }
|
|
public System.Net.WebSockets.WebSocketError WebSocketErrorCode { get { throw null; } }
|
|
public override void GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { }
|
|
}
|
|
public enum WebSocketMessageType
|
|
{
|
|
Binary = 1,
|
|
Close = 2,
|
|
Text = 0,
|
|
}
|
|
public partial class WebSocketReceiveResult
|
|
{
|
|
public WebSocketReceiveResult(int count, System.Net.WebSockets.WebSocketMessageType messageType, bool endOfMessage) { }
|
|
public WebSocketReceiveResult(int count, System.Net.WebSockets.WebSocketMessageType messageType, bool endOfMessage, System.Nullable<System.Net.WebSockets.WebSocketCloseStatus> closeStatus, string closeStatusDescription) { }
|
|
public System.Nullable<System.Net.WebSockets.WebSocketCloseStatus> CloseStatus { get { throw null; } }
|
|
public string CloseStatusDescription { get { throw null; } }
|
|
public int Count { get { throw null; } }
|
|
public bool EndOfMessage { get { throw null; } }
|
|
public System.Net.WebSockets.WebSocketMessageType MessageType { get { throw null; } }
|
|
}
|
|
public enum WebSocketState
|
|
{
|
|
Aborted = 6,
|
|
Closed = 5,
|
|
CloseReceived = 4,
|
|
CloseSent = 3,
|
|
Connecting = 1,
|
|
None = 0,
|
|
Open = 2,
|
|
}
|
|
}
|