mirror of
https://github.com/fafhrd91/actix-net
synced 2024-11-27 18:02:58 +01:00
fix non unix signals support
This commit is contained in:
parent
f89a992daf
commit
fa48ddcfa1
@ -8,25 +8,23 @@ use futures::future::lazy;
|
|||||||
use crate::server::Server;
|
use crate::server::Server;
|
||||||
|
|
||||||
/// Different types of process signals
|
/// Different types of process signals
|
||||||
|
#[allow(dead_code)]
|
||||||
#[derive(PartialEq, Clone, Copy, Debug)]
|
#[derive(PartialEq, Clone, Copy, Debug)]
|
||||||
pub(crate) enum Signal {
|
pub(crate) enum Signal {
|
||||||
/// SIGHUP
|
/// SIGHUP
|
||||||
#[cfg_attr(not(unix), allow(dead_code))]
|
|
||||||
Hup,
|
Hup,
|
||||||
/// SIGINT
|
/// SIGINT
|
||||||
Int,
|
Int,
|
||||||
/// SIGTERM
|
/// SIGTERM
|
||||||
#[cfg_attr(not(unix), allow(dead_code))]
|
|
||||||
Term,
|
Term,
|
||||||
/// SIGQUIT
|
/// SIGQUIT
|
||||||
#[cfg_attr(not(unix), allow(dead_code))]
|
|
||||||
Quit,
|
Quit,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) struct Signals {
|
pub(crate) struct Signals {
|
||||||
srv: Server,
|
srv: Server,
|
||||||
#[cfg(not(unix))]
|
#[cfg(not(unix))]
|
||||||
stream: actix_rt::signal::CtrlC,
|
stream: Pin<Box<dyn Future<Output = io::Result<()>>>>,
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
streams: Vec<(Signal, actix_rt::signal::unix::Signal)>,
|
streams: Vec<(Signal, actix_rt::signal::unix::Signal)>,
|
||||||
}
|
}
|
||||||
@ -36,12 +34,11 @@ impl Signals {
|
|||||||
actix_rt::spawn(lazy(|_| {
|
actix_rt::spawn(lazy(|_| {
|
||||||
#[cfg(not(unix))]
|
#[cfg(not(unix))]
|
||||||
{
|
{
|
||||||
match actix_rt::signal::ctrl_c() {
|
actix_rt::spawn(Signals {
|
||||||
Ok(stream) => actix_rt::spawn(Signals { srv, stream }),
|
srv,
|
||||||
Err(e) => log::error!("Can not initialize ctrl-c handler err: {}", e),
|
stream: Box::pin(actix_rt::signal::ctrl_c()),
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
{
|
{
|
||||||
use actix_rt::signal::unix;
|
use actix_rt::signal::unix;
|
||||||
@ -79,12 +76,12 @@ impl Future for Signals {
|
|||||||
|
|
||||||
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))]
|
||||||
loop {
|
match Pin::new(&mut self.stream).poll(cx) {
|
||||||
match Pin::new(&mut self.stream).poll_next(cx) {
|
Poll::Ready(_) => {
|
||||||
Poll::Ready(Some(_)) => self.srv.signal(Signal::Int),
|
self.srv.signal(Signal::Int);
|
||||||
Poll::Ready(None) => return Poll::Ready(()),
|
Poll::Ready(())
|
||||||
Poll::Pending => return Poll::Pending,
|
|
||||||
}
|
}
|
||||||
|
Poll::Pending => return Poll::Pending,
|
||||||
}
|
}
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user