mirror of https://github.com/fafhrd91/actix-net
doc tweaks
This commit is contained in:
parent
a61290f564
commit
2be5acf24e
|
@ -82,7 +82,7 @@ async fn run() -> io::Result<()> {
|
||||||
ok(size)
|
ok(size)
|
||||||
})
|
})
|
||||||
})?
|
})?
|
||||||
.workers(1)
|
.workers(2)
|
||||||
.run()
|
.run()
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,7 +46,7 @@ impl ServerHandle {
|
||||||
let _ = self.cmd_tx.send(ServerCommand::Stop {
|
let _ = self.cmd_tx.send(ServerCommand::Stop {
|
||||||
graceful,
|
graceful,
|
||||||
completion: Some(tx),
|
completion: Some(tx),
|
||||||
force_exit: false,
|
force_system_stop: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
async {
|
async {
|
||||||
|
|
|
@ -8,7 +8,7 @@ use std::{
|
||||||
|
|
||||||
use actix_rt::{time::sleep, System};
|
use actix_rt::{time::sleep, System};
|
||||||
use futures_core::{future::BoxFuture, Stream};
|
use futures_core::{future::BoxFuture, Stream};
|
||||||
use futures_util::stream::StreamExt;
|
use futures_util::stream::StreamExt as _;
|
||||||
use log::{error, info};
|
use log::{error, info};
|
||||||
use tokio::sync::{mpsc::UnboundedReceiver, oneshot};
|
use tokio::sync::{mpsc::UnboundedReceiver, oneshot};
|
||||||
|
|
||||||
|
@ -48,8 +48,8 @@ pub(crate) enum ServerCommand {
|
||||||
/// Return channel to notify caller that shutdown is complete.
|
/// Return channel to notify caller that shutdown is complete.
|
||||||
completion: Option<oneshot::Sender<()>>,
|
completion: Option<oneshot::Sender<()>>,
|
||||||
|
|
||||||
/// Force system exit, overriding `ServerBuilder::system_exit()`.
|
/// Force System exit when true, overriding `ServerBuilder::system_exit()` if it is false.
|
||||||
force_exit: bool,
|
force_system_stop: bool,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,8 +61,8 @@ pub(crate) enum ServerCommand {
|
||||||
/// Creates a worker per CPU core (or the number specified in [`ServerBuilder::workers`]) and
|
/// Creates a worker per CPU core (or the number specified in [`ServerBuilder::workers`]) and
|
||||||
/// distributes connections with a round-robin strategy.
|
/// distributes connections with a round-robin strategy.
|
||||||
///
|
///
|
||||||
/// The [Server] must be awaited in order to run.
|
/// The [Server] must be awaited or polled in order to start running. It will resolve when the
|
||||||
/// It will resolve when the server has fully shut down.
|
/// server has fully shut down.
|
||||||
///
|
///
|
||||||
/// # Shutdown Signals
|
/// # Shutdown Signals
|
||||||
/// On UNIX systems, `SIGQUIT` will start a graceful shutdown and `SIGTERM` or `SIGINT` will start a
|
/// On UNIX systems, `SIGQUIT` will start a graceful shutdown and `SIGTERM` or `SIGINT` will start a
|
||||||
|
@ -120,7 +120,7 @@ pub(crate) enum ServerCommand {
|
||||||
/// .await
|
/// .await
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
#[must_use = "futures do nothing unless you `.await` or poll them"]
|
#[must_use = "Server does nothing unless you `.await` or poll it"]
|
||||||
pub struct Server {
|
pub struct Server {
|
||||||
handle: ServerHandle,
|
handle: ServerHandle,
|
||||||
fut: BoxFuture<'static, io::Result<()>>,
|
fut: BoxFuture<'static, io::Result<()>>,
|
||||||
|
@ -139,7 +139,7 @@ impl Server {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get a handle for ServerFuture that can be used to change state of actix server.
|
/// Get a `Server` handle that can be used issue commands and change it's state.
|
||||||
///
|
///
|
||||||
/// See [ServerHandle](ServerHandle) for usage.
|
/// See [ServerHandle](ServerHandle) for usage.
|
||||||
pub fn handle(&self) -> ServerHandle {
|
pub fn handle(&self) -> ServerHandle {
|
||||||
|
@ -160,9 +160,9 @@ pub struct ServerInner {
|
||||||
worker_handles: Vec<WorkerHandleServer>,
|
worker_handles: Vec<WorkerHandleServer>,
|
||||||
worker_config: ServerWorkerConfig,
|
worker_config: ServerWorkerConfig,
|
||||||
services: Vec<Box<dyn InternalServiceFactory>>,
|
services: Vec<Box<dyn InternalServiceFactory>>,
|
||||||
exit: bool,
|
|
||||||
waker_queue: WakerQueue,
|
waker_queue: WakerQueue,
|
||||||
stopped: bool,
|
system_stop: bool,
|
||||||
|
stopping: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ServerInner {
|
impl ServerInner {
|
||||||
|
@ -171,7 +171,8 @@ impl ServerInner {
|
||||||
|
|
||||||
while let Some(cmd) = mux.next().await {
|
while let Some(cmd) = mux.next().await {
|
||||||
this.handle_cmd(cmd).await;
|
this.handle_cmd(cmd).await;
|
||||||
if this.stopped {
|
|
||||||
|
if this.stopping {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -216,8 +217,8 @@ impl ServerInner {
|
||||||
worker_handles,
|
worker_handles,
|
||||||
worker_config: builder.worker_config,
|
worker_config: builder.worker_config,
|
||||||
services: builder.factories,
|
services: builder.factories,
|
||||||
exit: builder.exit,
|
system_stop: builder.exit,
|
||||||
stopped: false,
|
stopping: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok((server, mux))
|
Ok((server, mux))
|
||||||
|
@ -238,9 +239,9 @@ impl ServerInner {
|
||||||
ServerCommand::Stop {
|
ServerCommand::Stop {
|
||||||
graceful,
|
graceful,
|
||||||
completion,
|
completion,
|
||||||
force_exit,
|
force_system_stop,
|
||||||
} => {
|
} => {
|
||||||
self.stopped = true;
|
self.stopping = true;
|
||||||
|
|
||||||
// stop accept thread
|
// stop accept thread
|
||||||
self.waker_queue.wake(WakerInterest::Stop);
|
self.waker_queue.wake(WakerInterest::Stop);
|
||||||
|
@ -261,7 +262,7 @@ impl ServerInner {
|
||||||
let _ = tx.send(());
|
let _ = tx.send(());
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.exit || force_exit {
|
if self.system_stop || force_system_stop {
|
||||||
sleep(Duration::from_millis(300)).await;
|
sleep(Duration::from_millis(300)).await;
|
||||||
System::try_current().as_ref().map(System::stop);
|
System::try_current().as_ref().map(System::stop);
|
||||||
}
|
}
|
||||||
|
@ -308,7 +309,7 @@ impl ServerInner {
|
||||||
ServerCommand::Stop {
|
ServerCommand::Stop {
|
||||||
graceful: false,
|
graceful: false,
|
||||||
completion: None,
|
completion: None,
|
||||||
force_exit: true,
|
force_system_stop: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -317,7 +318,7 @@ impl ServerInner {
|
||||||
ServerCommand::Stop {
|
ServerCommand::Stop {
|
||||||
graceful: true,
|
graceful: true,
|
||||||
completion: None,
|
completion: None,
|
||||||
force_exit: true,
|
force_system_stop: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -326,7 +327,7 @@ impl ServerInner {
|
||||||
ServerCommand::Stop {
|
ServerCommand::Stop {
|
||||||
graceful: false,
|
graceful: false,
|
||||||
completion: None,
|
completion: None,
|
||||||
force_exit: true,
|
force_system_stop: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue