Skip to content

Simplify Receive Buffer Implementation #4818

Closed
@guhetier

Description

@guhetier

The recv_buffer implementation supports multiple mode, and the number of diverging code paths based on the mode has been increasing.
Some refactoring could consolidate these path, helping with the maintainability of the code.

Potential improvements

  1. Mark "retired" chunks clearly and/or move them out of the chunk list

    • "retired" chunks are the ones that won't be used for any read/write operation anymore and will be freed as soon as they are no longer externally referenced
    • currently, retired buffer staying in the list means that "single" and "circular" mode look at the last chunk for read/write while other modes start by looking at the first chunk
  2. Always treat the first chunk as circular with limited capacity

    • "ReadStart" and "Capacity" are enough to ensure operations won't loop around for modes that don't want it
    • This should allow to consolidate most paths in "Read" and "Write" operations
  3. Refactor the drain logic

    • "Partial drain" and "Full drain" evolved to have different meaning for different buffer modes, making it tricky to modify
  4. The preallocated chunk pointer could be moved to the stream

    • It is allocated and freed by the stream but stored in the recv_buffer, leading to a confusing deinitialization pattern: the recv_buffer must be accessed after being deinitialized to free the chunk

Metadata

Metadata

Assignees

Labels

Area: CoreRelated to the shared, core protocol logic

Type

Projects

Status

Done

Relationships

None yet

Development

No branches or pull requests

Issue actions