Skip to content

Support 0 byte reads with SSLStream #37122

@davidfowl

Description

@davidfowl

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).

0 byte reads are supported by Sockets today and we take advantage of that to support the above scenario. We'd like to do the same for HTTPs based connections, so it would need to also work for SSLStream.

The typical layering looks like this for a WebSocket implemention (roughly):

WS.ReadAync(Buffer) 
    -> US.ReadAync(WSHeaderBuffer)
    -> US.ReadAync(Buffer)
        -> SSlStream.ReadAync(TlsFrameBuffer)
        -> SSlStream.ReadAync(Buffer) 
            -> NetworkStream.ReadAync(Buffer)
                -> Socket.ReadAsync(Buffer)

PS: I haven't tested it but if it just works then we should add test coverage so it doesn't regress.

cc: @stephentoub @wfurt

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions