From 9077762545da312c3527ba45b0bba37ba4b4fb7f Mon Sep 17 00:00:00 2001 From: "M.Amin Rayej" Date: Tue, 30 Jan 2024 21:46:37 +0330 Subject: [PATCH] net: expose keepalive option on `TcpSocket` (#6311) --- tokio/src/net/tcp/socket.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tokio/src/net/tcp/socket.rs b/tokio/src/net/tcp/socket.rs index 679e95866c5..c528a14fe8e 100644 --- a/tokio/src/net/tcp/socket.rs +++ b/tokio/src/net/tcp/socket.rs @@ -185,6 +185,16 @@ impl TcpSocket { Ok(TcpSocket { inner }) } + /// Sets value for the `SO_KEEPALIVE` option on this socket. + pub fn set_keepalive(&self, keepalive: bool) -> io::Result<()> { + self.inner.set_keepalive(keepalive) + } + + /// Gets the value of the `SO_KEEPALIVE` option on this socket. + pub fn keepalive(&self) -> io::Result { + self.inner.keepalive() + } + /// Allows the socket to bind to an in-use address. /// /// Behavior is platform specific. Refer to the target platform's