about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--kittybox-rs/src/main.rs49
1 files changed, 36 insertions, 13 deletions
diff --git a/kittybox-rs/src/main.rs b/kittybox-rs/src/main.rs
index c588ad8..cc11f3a 100644
--- a/kittybox-rs/src/main.rs
+++ b/kittybox-rs/src/main.rs
@@ -264,11 +264,43 @@ async fn main() {
         match listenfd.take_tcp_listener(i) {
             Ok(Some(tcp)) => servers.push(build_hyper(tcp)),
             Ok(None) => {},
-            Err(err) => {
-                tracing::error!("Error binding to socket in fd {}: {}", i, err);
-            }
+            Err(err) => tracing::error!("Error binding to socket in fd {}: {}", i, err)
         }
     }
+    // TODO this requires the `hyperlocal` crate
+    //#[rustfmt::skip]
+    /*#[cfg(unix)] {
+        let build_hyper_unix = |unix: std::os::unix::net::UnixListener| {
+            {
+                use std::os::linux::net::SocketAddrExt;
+
+                let local_addr = unix.local_addr().unwrap();
+                if let Some(pathname) = local_addr.as_pathname() {
+                    tracing::info!("Listening on unix:{}", pathname.display());
+                } else if let Some(name) = {
+                    #[cfg(linux)]
+                    local_addr.as_abstract_name();
+                    #[cfg(not(linux))]
+                    None::<&[u8]>
+                } {
+                    tracing::info!("Listening on unix:@{}", String::from_utf8_lossy(name));
+                } else {
+                    tracing::info!("Listening on unnamed unix socket");
+                }
+            }
+            unix.set_nonblocking(true).unwrap();
+
+            hyper::server::Server::builder(unix)
+                .serve(router.clone().into_make_service())
+        };
+        for i in 0..(listenfd.len()) {
+            match listenfd.take_unix_listener(i) {
+                Ok(Some(unix)) => servers.push(build_hyper_unix(unix)),
+                Ok(None) => {},
+                Err(err) => tracing::error!("Error binding to socket in fd {}: {}", i, err)
+            }
+        }
+    }*/
     if servers.is_empty() {
         servers.push(build_hyper({
             let listen_addr = env::var("SERVE_AT")
@@ -292,16 +324,7 @@ async fn main() {
             ),
             #[cfg(tokio_unstable)] |server| {
                 tokio::task::Builder::new()
-                    // We leak the String here. It is acceptable, as the string
-                    // is reasonably small and needs to live forever.
-                    .name({
-                        let name = format!("Kittybox HTTP acceptor: {}", server.local_addr());
-
-                        // Polyfill for unstablized [`String::leak`]
-                        //
-                        // SAFETY: the bytes come from a [`String`], which is valid UTF-8.
-                        unsafe { std::str::from_utf8_unchecked(name.into_bytes().leak()) }
-                    })
+                    .name(format!("Kittybox HTTP acceptor: {}", server.local_addr()).as_str())
                     .spawn(
                         server.with_graceful_shutdown(
                             cancellation_token.clone().cancelled_owned()