Commit Graph
4 Commits
Author SHA1 Message Date
Stephen Toub 7482b6a4b0 Expose and roll out ValueTask extensibility
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
2018-03-02 09:56:25 -08:00
Tarek Mahmoud Sayed 68e558d26e Remove Unbuffer Channel (dotnet/corefx#26689)
Commit migrated from https://github.com/dotnet/corefx/commit/1f8e408e7f2b0681056d1cac55b3ccc5586e8995
2018-01-30 18:09:58 -05:00
Stephen Toub 566b3dd2e6 Add back ChannelReader.ReadAsync
In the API review, we'd said to remove ReadAsync if we could, as we didn't like that it encouraged exceptions as control flow, due to exceptions getting thrown when attempting to read from a completed channel.

However, removing it is problematic for a few reasons:
- While for most channels its behavior can be achieved external to the channels on top of TryRead and WaitToReadAsync, that's not the case for UnbufferedChannel.  UnbufferedChannel.ReadAsync provides unique functionality that can only be achieved from within the implementation, as reads need to exist concurrently with writes in order for them to pair up.
- Channels in go don't have the notion of completion, which means the ReadAsync equivalent is very common there.  Any code written in that style and trying to port to this will expect a similar function but will instead be forced to emulate it with WaitToReadAsync/TryRead.

As such, I'm putting it back as a base virtual method and an override just on UnbufferedChannel's implementation.


Commit migrated from https://github.com/dotnet/corefx/commit/3c73f4621fe891aa25e97be2bbf772d7a747d263
2017-11-02 23:54:17 -04:00
Stephen Toub e424fbb097 Add System.Threading.Channels to corefx
Bring the source over from corefxlab, add a package, get everything building, etc.


Commit migrated from https://github.com/dotnet/corefx/commit/c8ec3a850bd05aa8d8a6067071b723366b5648a3
2017-10-25 19:45:02 -04:00