smoltcp-rs / smoltcp

a smol tcp/ip stack
BSD Zero Clause License
3.63k stars 402 forks source link

Enable resizing receive buffer after TCP connection is established #933

Open XOR-op opened 1 month ago

XOR-op commented 1 month ago

Closes #927.

This PR introduces the ability to resize TCP receive buffer after the connection is established, as well as corresponding constructor and getter function. This feature can help reduce memory footprint when establishing a lot of connections without sacrificing the maximum achievable throughput.

Current limitations and requirements include:

  1. The new buffer must be larger than the length of remaining data in the current buffer.
  2. The new buffer must be multiple of (1 << self.remote_win_shift), which is the window scaling negotiated in the handshake.
  3. Only Socket<'static> can support replacing buffers.