mirror of https://github.com/fafhrd91/actix-net
use boxed future for signals
This commit is contained in:
parent
aa8d33a22b
commit
ab4ad69ad2
|
@ -30,6 +30,6 @@ actix-utils = { path = "actix-utils" }
|
||||||
actix-router = { path = "router" }
|
actix-router = { path = "router" }
|
||||||
bytestring = { path = "string" }
|
bytestring = { path = "string" }
|
||||||
|
|
||||||
bytes = { git = "https://github.com/tokio-rs/bytes.git" }
|
# FIXME: remove these overrides
|
||||||
tokio = { git = "https://github.com/tokio-rs/tokio.git" }
|
tokio = { git = "https://github.com/tokio-rs/tokio.git" }
|
||||||
tokio-util = { git = "https://github.com/tokio-rs/tokio.git" }
|
tokio-util = { git = "https://github.com/tokio-rs/tokio.git" }
|
|
@ -1,8 +1,9 @@
|
||||||
// use std::future::Future;
|
use std::future::Future;
|
||||||
// use std::pin::Pin;
|
use std::pin::Pin;
|
||||||
// use std::task::{Context, Poll};
|
use std::task::{Context, Poll};
|
||||||
|
|
||||||
use crate::server::Server;
|
use crate::server::Server;
|
||||||
|
use crate::LocalBoxFuture;
|
||||||
|
|
||||||
/// Different types of process signals
|
/// Different types of process signals
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
|
@ -19,11 +20,11 @@ pub(crate) enum Signal {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) struct Signals {
|
pub(crate) struct Signals {
|
||||||
// srv: Server,
|
srv: Server,
|
||||||
// #[cfg(not(unix))]
|
#[cfg(not(unix))]
|
||||||
// stream: Pin<Box<dyn Future<Output = std::io::Result<()>>>>,
|
signals: LocalBoxFuture<'static, std::io::Result<()>>,
|
||||||
// #[cfg(unix)]
|
#[cfg(unix)]
|
||||||
// streams: Vec<(Signal, actix_rt::signal::unix::Signal)>,
|
signals: Vec<(Signal, LocalBoxFuture<'static, ()>)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Signals {
|
impl Signals {
|
||||||
|
@ -46,15 +47,15 @@ impl Signals {
|
||||||
(unix::SignalKind::quit(), Signal::Quit),
|
(unix::SignalKind::quit(), Signal::Quit),
|
||||||
];
|
];
|
||||||
|
|
||||||
|
let mut signals = Vec::new();
|
||||||
|
|
||||||
for (kind, sig) in sig_map.iter() {
|
for (kind, sig) in sig_map.iter() {
|
||||||
match unix::signal(*kind) {
|
match unix::signal(*kind) {
|
||||||
Ok(mut stream) => {
|
Ok(mut stream) => {
|
||||||
let sig = *sig;
|
let fut = Box::pin(async move {
|
||||||
let srv = srv.clone();
|
let _ = stream.recv().await;
|
||||||
actix_rt::spawn(async move {
|
}) as _;
|
||||||
stream.recv().await;
|
signals.push((*sig, fut));
|
||||||
srv.signal(sig);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
Err(e) => log::error!(
|
Err(e) => log::error!(
|
||||||
"Can not initialize stream handler for {:?} err: {}",
|
"Can not initialize stream handler for {:?} err: {}",
|
||||||
|
@ -64,51 +65,33 @@ impl Signals {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// for (kind, sig) in sig_map.iter() {
|
actix_rt::spawn(Signals { srv, signals });
|
||||||
// match unix::signal(*kind) {
|
|
||||||
// Ok(stream) => streams.push((*sig, stream)),
|
|
||||||
// Err(e) => log::error!(
|
|
||||||
// "Can not initialize stream handler for {:?} err: {}",
|
|
||||||
// sig,
|
|
||||||
// e
|
|
||||||
// ),
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// actix_rt::spawn(Signals { srv, streams });
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// impl Future for Signals {
|
impl Future for Signals {
|
||||||
// type Output = ();
|
type Output = ();
|
||||||
//
|
|
||||||
// fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
||||||
// #[cfg(not(unix))]
|
#[cfg(not(unix))]
|
||||||
// match Pin::new(&mut self.stream).poll(cx) {
|
match Pin::new(&mut self.stream).poll(cx) {
|
||||||
// Poll::Ready(_) => {
|
Poll::Ready(_) => {
|
||||||
// self.srv.signal(Signal::Int);
|
self.srv.signal(Signal::Int);
|
||||||
// Poll::Ready(())
|
Poll::Ready(())
|
||||||
// }
|
}
|
||||||
// Poll::Pending => Poll::Pending,
|
Poll::Pending => Poll::Pending,
|
||||||
// }
|
}
|
||||||
// #[cfg(unix)]
|
#[cfg(unix)]
|
||||||
// {
|
{
|
||||||
// use futures_util::stream::Stream;
|
for (sig, fut) in self.signals.iter_mut() {
|
||||||
//
|
if fut.as_mut().poll(cx).is_ready() {
|
||||||
// for idx in 0..self.streams.len() {
|
let sig = *sig;
|
||||||
// loop {
|
self.srv.signal(sig);
|
||||||
// match Pin::new(&mut self.streams[idx].1).poll_next(cx) {
|
return Poll::Ready(());
|
||||||
// Poll::Ready(None) => return Poll::Ready(()),
|
}
|
||||||
// Poll::Pending => break,
|
}
|
||||||
// Poll::Ready(Some(_)) => {
|
Poll::Pending
|
||||||
// let sig = self.streams[idx].0;
|
}
|
||||||
// self.srv.signal(sig);
|
}
|
||||||
// }
|
}
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// Poll::Pending
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
Loading…
Reference in New Issue