Skip to content

Commit

Permalink
Set the incoming socket buffer sizes properly on the listen socket.
Browse files Browse the repository at this point in the history
  • Loading branch information
notsure2 committed Dec 11, 2023
1 parent ad4a96f commit 0d53cf2
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions crates/shadowsocks/src/net/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,14 @@ impl TcpListener {
pub async fn bind_with_opts(addr: &SocketAddr, accept_opts: AcceptOpts) -> io::Result<TcpListener> {
let socket = create_inbound_tcp_socket(addr, &accept_opts).await?;

if accept_opts.tcp.send_buffer_size > Some(0) {
socket.set_send_buffer_size(accept_opts.tcp.send_buffer_size.unwrap())?;
}

if accept_opts.tcp.recv_buffer_size > Some(0) {
socket.set_recv_buffer_size(accept_opts.tcp.recv_buffer_size.unwrap())?;
}

// On platforms with Berkeley-derived sockets, this allows to quickly
// rebind a socket, without needing to wait for the OS to clean up the
// previous one.
Expand Down

0 comments on commit 0d53cf2

Please sign in to comment.