changeset 29:efc69e99db70

Set socket to nonblocking before passing it to tokio.
author Paul Fisher <paul@pfish.zone>
date Sat, 19 Apr 2025 01:41:25 -0400
parents cfef4593e207
children
files src/lib.rs
diffstat 1 files changed, 9 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib.rs	Sat Apr 19 01:33:50 2025 -0400
+++ b/src/lib.rs	Sat Apr 19 01:41:25 2025 -0400
@@ -370,7 +370,7 @@
     ///
     /// To be specific, it binds the socket or converts systemd socket to `tokio` 1.0 socket.
     ///
-    /// This method either `binds` the socket, if the address was provided or uses systemd socket
+    /// This method either `bind`s the socket, if the address was provided or uses systemd socket
     /// if the socket name was provided.
     #[cfg(feature = "tokio")]
     pub async fn bind_tokio(self) -> Result<tokio::net::TcpListener, TokioBindError> {
@@ -391,19 +391,23 @@
             }
             SocketAddrInner::Systemd(socket_name) => {
                 let (socket, addr) = Self::get_systemd(socket_name, true)?;
-                socket
-                    .try_into()
+                Self::wrap_tokio(socket)
                     .map_err(|error| TokioConversionError { addr, error }.into())
             }
             SocketAddrInner::SystemdNoPrefix(socket_name) => {
                 let (socket, addr) = Self::get_systemd(socket_name, false)?;
-                socket
-                    .try_into()
+                Self::wrap_tokio(socket)
                     .map_err(|error| TokioConversionError { addr, error }.into())
             }
         }
     }
 
+    #[cfg(feature = "tokio")]
+    fn wrap_tokio(socket: std::net::TcpListener) -> Result<tokio::net::TcpListener, std::io::Error> {
+        socket.set_nonblocking(true)?;
+        socket.try_into()
+    }
+
     /// Creates `tokio::net::TcpListener`
     ///
     /// To be specific, it binds the socket or converts systemd socket to `tokio` 0.2 socket.