use std::time::Duration;
use anyhow::{Context, Result};
use socket2::{SockRef, TcpKeepalive};
use tokio::net::TcpStream;
pub fn set_tcp_keepalive(conn: &TcpStream) -> Result<()> {
let s = SockRef::from(conn);
let keepalive = TcpKeepalive::new().with_time(Duration::from_secs(60));
s.set_tcp_keepalive(&keepalive)
.with_context(|| "Failed to set keepalive")
}