mirror of
https://github.com/actix/actix-extras.git
synced 2025-06-30 03:44:27 +02:00
update actix api
This commit is contained in:
@ -54,7 +54,7 @@ pub(crate) const MAX_WRITE_BUFFER_SIZE: usize = 65_536;
|
||||
/// .bind("127.0.0.1:59090").unwrap()
|
||||
/// .start();
|
||||
///
|
||||
/// # actix::Arbiter::system().do_send(actix::msgs::SystemExit(0));
|
||||
/// # actix::System::current().stop();
|
||||
/// });
|
||||
/// }
|
||||
/// ```
|
||||
|
@ -4,8 +4,8 @@ use std::time::Duration;
|
||||
use std::{io, net, thread};
|
||||
|
||||
use actix::{
|
||||
fut, msgs, signal, Actor, ActorContext, ActorFuture, Addr, Arbiter, AsyncContext,
|
||||
Context, ContextFutureSpawner, Handler, Response, StreamHandler, System, WrapFuture,
|
||||
fut, signal, Actor, ActorContext, ActorFuture, Addr, Arbiter, AsyncContext, Context,
|
||||
ContextFutureSpawner, Handler, Response, StreamHandler, System, WrapFuture,
|
||||
};
|
||||
|
||||
use futures::sync::mpsc;
|
||||
@ -64,16 +64,8 @@ where
|
||||
no_signals: bool,
|
||||
}
|
||||
|
||||
unsafe impl<H> Sync for HttpServer<H>
|
||||
where
|
||||
H: IntoHttpHandler,
|
||||
{
|
||||
}
|
||||
unsafe impl<H> Send for HttpServer<H>
|
||||
where
|
||||
H: IntoHttpHandler,
|
||||
{
|
||||
}
|
||||
unsafe impl<H> Sync for HttpServer<H> where H: IntoHttpHandler {}
|
||||
unsafe impl<H> Send for HttpServer<H> where H: IntoHttpHandler {}
|
||||
|
||||
enum ServerCommand {
|
||||
WorkerDied(usize, Slab<SocketInfo>),
|
||||
@ -170,10 +162,9 @@ where
|
||||
self
|
||||
}
|
||||
|
||||
/// Send `SystemExit` message to actix system
|
||||
/// Stop actix system.
|
||||
///
|
||||
/// `SystemExit` message stops currently running system arbiter and all
|
||||
/// nested arbiters.
|
||||
/// `SystemExit` message stops currently running system.
|
||||
pub fn system_exit(mut self) -> Self {
|
||||
self.exit = true;
|
||||
self
|
||||
@ -388,7 +379,7 @@ where
|
||||
if let Some(ref signals) = self.signals {
|
||||
Some(signals.clone())
|
||||
} else {
|
||||
Some(Arbiter::registry().get::<signal::ProcessSignals>())
|
||||
Some(System::current().registry().get::<signal::ProcessSignals>())
|
||||
}
|
||||
} else {
|
||||
None
|
||||
@ -418,7 +409,7 @@ impl<H: IntoHttpHandler> HttpServer<H> {
|
||||
/// .bind("127.0.0.1:0")
|
||||
/// .expect("Can not bind to 127.0.0.1:0")
|
||||
/// .start();
|
||||
/// # actix::Arbiter::system().do_send(actix::msgs::SystemExit(0));
|
||||
/// # actix::System::current().stop();
|
||||
/// });
|
||||
/// }
|
||||
/// ```
|
||||
@ -597,7 +588,7 @@ impl<H: IntoHttpHandler> HttpServer<H> {
|
||||
}
|
||||
|
||||
/// Signals support
|
||||
/// Handle `SIGINT`, `SIGTERM`, `SIGQUIT` signals and send `SystemExit(0)`
|
||||
/// Handle `SIGINT`, `SIGTERM`, `SIGQUIT` signals and stop actix system
|
||||
/// message to `System` actor.
|
||||
impl<H: IntoHttpHandler> Handler<signal::Signal> for HttpServer<H> {
|
||||
type Result = ();
|
||||
@ -753,7 +744,7 @@ impl<H: IntoHttpHandler> Handler<StopServer> for HttpServer<H> {
|
||||
// we need to stop system if server was spawned
|
||||
if slf.exit {
|
||||
ctx.run_later(Duration::from_millis(300), |_, _| {
|
||||
Arbiter::system().do_send(msgs::SystemExit(0))
|
||||
System::current().stop();
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -768,7 +759,7 @@ impl<H: IntoHttpHandler> Handler<StopServer> for HttpServer<H> {
|
||||
// we need to stop system if server was spawned
|
||||
if self.exit {
|
||||
ctx.run_later(Duration::from_millis(300), |_, _| {
|
||||
Arbiter::system().do_send(msgs::SystemExit(0))
|
||||
System::current().stop();
|
||||
});
|
||||
}
|
||||
Response::reply(Ok(()))
|
||||
|
@ -95,14 +95,14 @@ impl<H: HttpHandler + 'static> Worker<H> {
|
||||
let num = slf.settings.num_channels();
|
||||
if num == 0 {
|
||||
let _ = tx.send(true);
|
||||
Arbiter::arbiter().do_send(StopArbiter(0));
|
||||
Arbiter::current().do_send(StopArbiter(0));
|
||||
} else if let Some(d) = dur.checked_sub(time::Duration::new(1, 0)) {
|
||||
slf.shutdown_timeout(ctx, tx, d);
|
||||
} else {
|
||||
info!("Force shutdown http worker, {} connections", num);
|
||||
slf.settings.head().traverse::<TcpStream, H>();
|
||||
let _ = tx.send(false);
|
||||
Arbiter::arbiter().do_send(StopArbiter(0));
|
||||
Arbiter::current().do_send(StopArbiter(0));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
Reference in New Issue
Block a user