mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-22 00:00:11 +02:00
signal: refactor: Prefer the implicit handle passing used by tokio
This commit is contained in:
committed by
Carl Lerche
parent
209232befd
commit
e73b8a0cc9
+25
-26
@@ -11,16 +11,14 @@ use std::thread;
|
||||
use std::time::Duration;
|
||||
|
||||
use futures::stream::Stream;
|
||||
use futures::{future, Future, IntoFuture};
|
||||
use futures::{Future, IntoFuture};
|
||||
use tokio_core::reactor::{Core, Timeout};
|
||||
use tokio_signal::unix::Signal;
|
||||
|
||||
#[test]
|
||||
fn simple() {
|
||||
let mut lp = Core::new().unwrap();
|
||||
let handle = lp.handle();
|
||||
let signal = lp.run(Signal::new(libc::SIGUSR1, &handle.new_tokio_handle()))
|
||||
.unwrap();
|
||||
let signal = lp.run(Signal::new(libc::SIGUSR1)).unwrap();
|
||||
unsafe {
|
||||
assert_eq!(libc::kill(libc::getpid(), libc::SIGUSR1), 0);
|
||||
}
|
||||
@@ -30,16 +28,15 @@ fn simple() {
|
||||
#[test]
|
||||
fn tokio_simple() {
|
||||
tokio::run(
|
||||
future::lazy(|| {
|
||||
Signal::new(libc::SIGUSR1, &tokio::reactor::Handle::default())
|
||||
.into_future()
|
||||
.and_then(|signal| {
|
||||
unsafe {
|
||||
assert_eq!(libc::kill(libc::getpid(), libc::SIGUSR1), 0);
|
||||
}
|
||||
signal.into_future().map(|_| ()).map_err(|(err, _)| err)
|
||||
})
|
||||
}).map_err(|err| panic!("{}", err)),
|
||||
Signal::new(libc::SIGUSR1)
|
||||
.into_future()
|
||||
.and_then(|signal| {
|
||||
unsafe {
|
||||
assert_eq!(libc::kill(libc::getpid(), libc::SIGUSR1), 0);
|
||||
}
|
||||
signal.into_future().map(|_| ()).map_err(|(err, _)| err)
|
||||
})
|
||||
.map_err(|err| panic!("{}", err)),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -47,10 +44,14 @@ fn tokio_simple() {
|
||||
fn notify_both() {
|
||||
let mut lp = Core::new().unwrap();
|
||||
let handle = lp.handle();
|
||||
let signal1 = lp.run(Signal::new(libc::SIGUSR2, &handle.new_tokio_handle()))
|
||||
.unwrap();
|
||||
let signal2 = lp.run(Signal::new(libc::SIGUSR2, &handle.new_tokio_handle()))
|
||||
.unwrap();
|
||||
let signal1 = lp.run(Signal::with_handle(
|
||||
libc::SIGUSR2,
|
||||
&handle.new_tokio_handle(),
|
||||
)).unwrap();
|
||||
let signal2 = lp.run(Signal::with_handle(
|
||||
libc::SIGUSR2,
|
||||
&handle.new_tokio_handle(),
|
||||
)).unwrap();
|
||||
unsafe {
|
||||
assert_eq!(libc::kill(libc::getpid(), libc::SIGUSR2), 0);
|
||||
}
|
||||
@@ -63,8 +64,10 @@ fn notify_both() {
|
||||
fn drop_then_get_a_signal() {
|
||||
let mut lp = Core::new().unwrap();
|
||||
let handle = lp.handle();
|
||||
let signal = lp.run(Signal::new(libc::SIGUSR1, &handle.new_tokio_handle()))
|
||||
.unwrap();
|
||||
let signal = lp.run(Signal::with_handle(
|
||||
libc::SIGUSR1,
|
||||
&handle.new_tokio_handle(),
|
||||
)).unwrap();
|
||||
drop(signal);
|
||||
unsafe {
|
||||
assert_eq!(libc::kill(libc::getpid(), libc::SIGUSR1), 0);
|
||||
@@ -76,9 +79,7 @@ fn drop_then_get_a_signal() {
|
||||
#[test]
|
||||
fn twice() {
|
||||
let mut lp = Core::new().unwrap();
|
||||
let handle = lp.handle();
|
||||
let signal = lp.run(Signal::new(libc::SIGUSR1, &handle.new_tokio_handle()))
|
||||
.unwrap();
|
||||
let signal = lp.run(Signal::new(libc::SIGUSR1)).unwrap();
|
||||
unsafe {
|
||||
assert_eq!(libc::kill(libc::getpid(), libc::SIGUSR1), 0);
|
||||
}
|
||||
@@ -102,9 +103,7 @@ fn multi_loop() {
|
||||
let sender = sender.clone();
|
||||
thread::spawn(move || {
|
||||
let mut lp = Core::new().unwrap();
|
||||
let handle = lp.handle();
|
||||
let signal = lp.run(Signal::new(libc::SIGHUP, &handle.new_tokio_handle()))
|
||||
.unwrap();
|
||||
let signal = lp.run(Signal::new(libc::SIGHUP)).unwrap();
|
||||
sender.send(()).unwrap();
|
||||
lp.run(signal.into_future()).ok().unwrap();
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user