listenfd

Crates.iolistenfd
lib.rslistenfd
version
sourcesrc
created_at2018-05-17 00:48:16.906123+00
updated_at2025-01-19 16:09:12.481992+00
descriptionA simple library to work with listenfds passed from the outside (systemd/catflap socket activation)
homepagehttps://github.com/mitsuhiko/listenfd
repository
max_upload_size
id65800
Cargo.toml error:TOML parse error at line 18, column 1 | 18 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include`
size0
Armin Ronacher (mitsuhiko)

documentation

README

listenfd

Crates.io License rustc 1.42.0 Documentation

listenfd is a crate that provides support for working with externally managed and passed file descriptors. This lets you work with systems that support socket activation or similar.

Currently this supports systemd (including systemd-socket-activate) on Unix and systemfd on Unix and Windows. systemfd is very convenient in combination with cargo-watch for development purposes whereas systemd is useful for production deployments on linux.

Example

use listenfd::ListenFd;

let mut listenfd = ListenFd::from_env();
let mut server = make_a_server();

// if we are given a tcp listener on listen fd 0, we use that one
server = if let Some(listener) = listenfd.take_tcp_listener(0)? {
    server.listen(listener)
// otherwise fall back to local listening
} else {
    server.bind("127.0.0.1:3000")?
};

You can then use this with cargo watch and systemfd:

$ cargo install systemfd cargo-watch
systemfd --no-pid -s http::3000 -- cargo watch -x run

Now systemfd will open the socket and keep it open. cargo watch will recompile the code on demand and the server will pick up the socket that systemfd opened. No more connection resets.

License and Links

Commit count: 0

cargo fmt