Skip to content

Commit

Permalink
configuring tcp socket keepalive and nagle
Browse files Browse the repository at this point in the history
  • Loading branch information
babymotte committed Oct 13, 2024
1 parent c9357f4 commit bbabe92
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions worterbuch/src/server/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use crate::{
use std::net::{IpAddr, SocketAddr};
use tokio::{
io::{AsyncBufReadExt, BufReader},
net::{TcpListener, TcpStream},
net::{TcpSocket, TcpStream},
select, spawn,
sync::mpsc,
};
Expand All @@ -41,7 +41,13 @@ pub async fn start(
let addr = format!("{bind_addr}:{port}");

log::info!("Serving TCP endpoint at {addr}");
let listener = TcpListener::bind(&addr).await?;
let sock = TcpSocket::new_v4()?;
sock.set_keepalive(true)?;
sock.set_nodelay(true)?;
#[cfg(not(target_os = "windows"))]
sock.set_reuseaddr(true)?;
sock.bind(addr.parse()?)?;
let listener = sock.listen(1024)?;

let (conn_closed_tx, mut conn_closed_rx) = mpsc::channel(100);
let mut open_connections = 0;
Expand Down

0 comments on commit bbabe92

Please sign in to comment.