ctrl_c.rs |
|
2084 |
mod.rs |
Asynchronous signal handling for Tokio.
Note that signal handling is in general a very tricky topic and should be
used with great care. This crate attempts to implement 'best practice' for
signal handling, but it should be evaluated for your own applications' needs
to see if it's suitable.
There are some fundamental limitations of this crate documented on the OS
specific structures, as well.
# Examples
Print on "ctrl-c" notification.
```rust,no_run
use tokio::signal;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
signal::ctrl_c().await?;
println!("ctrl-c received!");
Ok(())
}
```
Wait for `SIGHUP` on Unix
```rust,no_run
# #[cfg(unix)] {
use tokio::signal::unix::{signal, SignalKind};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// An infinite stream of hangup signals.
let mut stream = signal(SignalKind::hangup())?;
// Print whenever a HUP signal is received
loop {
stream.recv().await;
println!("got signal HUP");
}
}
# }
``` |
2463 |
registry.rs |
|
7678 |
reusable_box.rs |
|
7118 |
unix.rs |
Unix-specific types for signal handling.
This module is only defined on Unix platforms and contains the primary
`Signal` type for receiving notifications of signals. |
17226 |
windows |
|
|
windows.rs |
Windows-specific types for signal handling.
This module is only defined on Windows and allows receiving "ctrl-c",
"ctrl-break", "ctrl-logoff", "ctrl-shutdown", and "ctrl-close"
notifications. These events are listened for via the `SetConsoleCtrlHandler`
function which receives the corresponding `windows_sys` event type. |
15724 |