Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] Resize TCP socket buffer dynamically after TCP socket has been created #927

Open
XOR-op opened this issue May 12, 2024 · 5 comments · May be fixed by #933
Open

[Feature Request] Resize TCP socket buffer dynamically after TCP socket has been created #927

XOR-op opened this issue May 12, 2024 · 5 comments · May be fixed by #933

Comments

@XOR-op
Copy link

XOR-op commented May 12, 2024

Currently, the buffer for TCP socket needs to be preallocated in socket::tcp::Socket::new() and I found nowhere to change its size. However, a configurable window size is necessary to achieve a balance between good bandwidth and low memory footprint. I notice that TCP window scaling (RFC 1323) is advertised to be implemented but it seems it's only properly implemented for the remote endpoint. Can this feature be implemented in local side?

@XOR-op XOR-op changed the title [Feature Request] Resize TCP socket buffer size [Feature Request] Resize TCP socket buffer with TCP window scaling (RFC 1323) May 12, 2024
@Dirbaio
Copy link
Member

Dirbaio commented May 12, 2024

I'm not sure what feature you're requesting:

  • You can already use buffers any size you want. If you want a bigger buffer (hence a bigger window), use a bigger buffer.
  • TCP window scaling is fully implemented. if you set a buffer bigger than 65536, window scaling will be used to advertise the full buffer size to the remote side. (Also note window scaling is just a TCP extension allowing advertising window sizes larger than 16 bits, which is the window field size in the header. Window scaling by itself won't make the buffer bigger.)

@XOR-op
Copy link
Author

XOR-op commented May 12, 2024

Thanks for your replying. What I want to achieve is the following:

  • I don't know if the connection needs a big bandwidth initially, so I create a TCP socket with tcp::Socket::new(vec![0;65536], vec![0; 65536]) to reduce memory usage.
  • After some data exchange, I notice that we need a bigger receive window to satisfy BDP. Then I want to make the receive window to be 1MB. (Always allocating 1MB buffer for every socket at the beginning will lead to much bigger memory footprint)

Is this already possible?

@Dirbaio
Copy link
Member

Dirbaio commented May 12, 2024

ah okay! you want to dynamically change the buffer size after the TCP socket has already been created. Makes sense.

Unfortunately that's not possible now, no. Doing it if the buffer is borrowed might be hard, but should be doable if it's an owned Vec.

@XOR-op XOR-op changed the title [Feature Request] Resize TCP socket buffer with TCP window scaling (RFC 1323) [Feature Request] Resize TCP socket buffer dynamically after TCP socket has been created May 12, 2024
@XOR-op
Copy link
Author

XOR-op commented May 12, 2024

Then can we add such an API for sockets with owned Vec or Socket<'static> such as

fn replace_recv_buf<T: Into<SocketBuffer<'static>>(&mut self, new_buffer: T)->Option<SocketBuffer<'static>>

? Enabling this feature will be helpful to memory-constraint devices with skewed bandwidth needs.

@Dirbaio
Copy link
Member

Dirbaio commented May 12, 2024

sure! pull reuquests welcome

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

2 participants