Skip to content

Add ability to perform zero byte reads in StreamPipeReader #37539

Closed
@davidfowl

Description

@davidfowl

Background and Motivation

Bufferless reads are a technique used in a couple of places in ASP.NET Core to avoid renting memory from the memory pool if there's no data available on the socket; this helps when trying to reduce the memory usage for idle connections for applications that are trying to handle a large number of concurrent connections (like websocket based applications).

We'd like to use this for websocket applications to remove the need to allocate any memory (see #37122 for an example)

Proposed API

namespace System.Collections.Generic
{
    public class StreamPipeReaderOptions 
    {
+      public bool WaitForData { get; set; }
    }

WaitForData tells the PipeReader implementation that it should wait for data from the underlying stream before allocating memory. It relies on the stream supporting zero byte reads (which networking and SSL do)

Usage Examples

var reader = PipeReader.Create(stream, new StreamPipeReaderOptions { WaitForData = true })

Numbers in SSLStream

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions