Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

agent: Add run_listener to the Agent trait #28

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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.

None yet

1 participant