Skip to content

Conversation

@wiktor-k
Copy link

This change exposes Agent::run_listener that takes a raw UnixListener object.

This allows starting the agent with listeners that are backed by raw file descriptors. This in turn makes writing agents that are started with systemd's socket activation.

The following example starts the agent from systemd's supplied input:

use std::os::unix::io::FromRawFd;

let fds = std::env::var("LISTEN_FDS").unwrap();
let fds: i32 = fds.parse()?;
let listener = unsafe { std::os::unix::net::UnixListener::from_raw_fd(fds + 2) };
listener.set_nonblocking(true)?;

let handle = tokio_reactor::Handle::default();
let listener = tokio_uds::UnixListener::from_std(listener, &handle)?;

let agent = Backend::default();
agent.run_listener(listener);

This change exposes `Agent::run_listener` that takes a raw
`UnixListener` object. This allows starting the agent with listeners
that are backed by raw file descriptors. This in turn makes writing
agents that are started with systemd's socket activation [0].

[0]: https://0pointer.de/blog/projects/socket-activation.html

The following example starts the agent from systemd's supplied input:

```rs
use std::os::unix::io::FromRawFd;

let fds = std::env::var("LISTEN_FDS").unwrap();
let fds: i32 = fds.parse()?;
let listener = unsafe { std::os::unix::net::UnixListener::from_raw_fd(fds + 2) };
listener.set_nonblocking(true)?;

let handle = tokio_reactor::Handle::default();
let listener = tokio_uds::UnixListener::from_std(listener, &handle)?;

let agent = Backend::default();
agent.run_listener(listener);
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant