mirror of
https://github.com/fafhrd91/actix-net
synced 2024-11-27 16:52:58 +01:00
rename server to serverhandle
This commit is contained in:
parent
1c8fcaebbc
commit
305d0e9d8a
@ -1,8 +1,11 @@
|
||||
# Changes
|
||||
|
||||
## Unreleased - 2021-xx-xx
|
||||
* Rename `Server` to `ServerHandle`. [#???]
|
||||
* Minimum supported Rust version (MSRV) is now 1.52.
|
||||
|
||||
[#???]: https://github.com/actix/actix-net/pull/???
|
||||
|
||||
|
||||
## 2.0.0-beta.6 - 2021-10-11
|
||||
* Add experimental (semver-exempt) `io-uring` feature for enabling async file I/O on linux. [#374]
|
||||
|
@ -8,7 +8,7 @@ use actix_rt::{
|
||||
use log::{debug, error, info};
|
||||
use mio::{Interest, Poll, Token as MioToken};
|
||||
|
||||
use crate::server::Server;
|
||||
use crate::server::ServerHandle;
|
||||
use crate::socket::MioListener;
|
||||
use crate::waker_queue::{WakerInterest, WakerQueue, WAKER_TOKEN};
|
||||
use crate::worker::{Conn, WorkerHandleAccept};
|
||||
@ -30,13 +30,13 @@ struct ServerSocketInfo {
|
||||
///
|
||||
/// It would also listen to `ServerCommand` and push interests to `WakerQueue`.
|
||||
pub(crate) struct AcceptLoop {
|
||||
srv: Option<Server>,
|
||||
srv: Option<ServerHandle>,
|
||||
poll: Option<Poll>,
|
||||
waker: WakerQueue,
|
||||
}
|
||||
|
||||
impl AcceptLoop {
|
||||
pub fn new(srv: Server) -> Self {
|
||||
pub fn new(srv: ServerHandle) -> Self {
|
||||
let poll = Poll::new().unwrap_or_else(|e| panic!("Can not create `mio::Poll`: {}", e));
|
||||
let waker = WakerQueue::new(poll.registry())
|
||||
.unwrap_or_else(|e| panic!("Can not create `mio::Waker`: {}", e));
|
||||
@ -74,7 +74,7 @@ struct Accept {
|
||||
poll: Poll,
|
||||
waker: WakerQueue,
|
||||
handles: Vec<WorkerHandleAccept>,
|
||||
srv: Server,
|
||||
srv: ServerHandle,
|
||||
next: usize,
|
||||
avail: Availability,
|
||||
paused: bool,
|
||||
@ -153,7 +153,7 @@ impl Accept {
|
||||
poll: Poll,
|
||||
waker: WakerQueue,
|
||||
socks: Vec<(usize, MioListener)>,
|
||||
srv: Server,
|
||||
srv: ServerHandle,
|
||||
handles: Vec<WorkerHandleAccept>,
|
||||
) {
|
||||
// Accept runs in its own thread and would want to spawn additional futures to current
|
||||
@ -176,7 +176,7 @@ impl Accept {
|
||||
waker: WakerQueue,
|
||||
socks: Vec<(usize, MioListener)>,
|
||||
handles: Vec<WorkerHandleAccept>,
|
||||
srv: Server,
|
||||
srv: ServerHandle,
|
||||
) -> (Accept, Vec<ServerSocketInfo>) {
|
||||
let sockets = socks
|
||||
.into_iter()
|
||||
|
@ -15,7 +15,7 @@ use tokio::sync::{
|
||||
|
||||
use crate::accept::AcceptLoop;
|
||||
use crate::join_all;
|
||||
use crate::server::{Server, ServerCommand};
|
||||
use crate::server::{ServerCommand, ServerHandle};
|
||||
use crate::service::{InternalServiceFactory, ServiceFactory, StreamNewService};
|
||||
use crate::signals::{Signal, Signals};
|
||||
use crate::socket::{MioListener, StdSocketAddr, StdTcpListener, ToSocketAddrs};
|
||||
@ -23,6 +23,17 @@ use crate::socket::{MioTcpListener, MioTcpSocket};
|
||||
use crate::waker_queue::{WakerInterest, WakerQueue};
|
||||
use crate::worker::{ServerWorker, ServerWorkerConfig, WorkerHandleAccept, WorkerHandleServer};
|
||||
|
||||
#[derive(Debug)]
|
||||
#[non_exhaustive]
|
||||
pub struct Server;
|
||||
|
||||
impl Server {
|
||||
/// Start server building process.
|
||||
pub fn build() -> ServerBuilder {
|
||||
ServerBuilder::default()
|
||||
}
|
||||
}
|
||||
|
||||
/// Server builder
|
||||
pub struct ServerBuilder {
|
||||
threads: usize,
|
||||
@ -35,7 +46,7 @@ pub struct ServerBuilder {
|
||||
exit: bool,
|
||||
no_signals: bool,
|
||||
cmd: UnboundedReceiver<ServerCommand>,
|
||||
server: Server,
|
||||
server: ServerHandle,
|
||||
notify: Vec<oneshot::Sender<()>>,
|
||||
worker_config: ServerWorkerConfig,
|
||||
}
|
||||
@ -50,7 +61,7 @@ impl ServerBuilder {
|
||||
/// Create new Server builder instance
|
||||
pub fn new() -> ServerBuilder {
|
||||
let (tx, rx) = unbounded_channel();
|
||||
let server = Server::new(tx);
|
||||
let server = ServerHandle::new(tx);
|
||||
|
||||
ServerBuilder {
|
||||
threads: num_cpus::get(),
|
||||
@ -246,7 +257,7 @@ impl ServerBuilder {
|
||||
}
|
||||
|
||||
/// Starts processing incoming connections and return server controller.
|
||||
pub fn run(mut self) -> Server {
|
||||
pub fn run(mut self) -> ServerHandle {
|
||||
if self.sockets.is_empty() {
|
||||
panic!("Server should have at least one bound socket");
|
||||
} else {
|
||||
|
@ -14,8 +14,8 @@ mod test_server;
|
||||
mod waker_queue;
|
||||
mod worker;
|
||||
|
||||
pub use self::builder::ServerBuilder;
|
||||
pub use self::server::Server;
|
||||
pub use self::builder::{Server, ServerBuilder};
|
||||
pub use self::server::{ServerHandle};
|
||||
pub use self::service::ServiceFactory;
|
||||
pub use self::test_server::TestServer;
|
||||
|
||||
|
@ -6,7 +6,6 @@ use std::task::{Context, Poll};
|
||||
use tokio::sync::mpsc::UnboundedSender;
|
||||
use tokio::sync::oneshot;
|
||||
|
||||
use crate::builder::ServerBuilder;
|
||||
use crate::signals::Signal;
|
||||
|
||||
#[derive(Debug)]
|
||||
@ -32,19 +31,14 @@ pub(crate) enum ServerCommand {
|
||||
///
|
||||
/// A graceful shutdown will wait for all workers to stop first.
|
||||
#[derive(Debug)]
|
||||
pub struct Server(
|
||||
pub struct ServerHandle(
|
||||
UnboundedSender<ServerCommand>,
|
||||
Option<oneshot::Receiver<()>>,
|
||||
);
|
||||
|
||||
impl Server {
|
||||
impl ServerHandle {
|
||||
pub(crate) fn new(tx: UnboundedSender<ServerCommand>) -> Self {
|
||||
Server(tx, None)
|
||||
}
|
||||
|
||||
/// Start server building process
|
||||
pub fn build() -> ServerBuilder {
|
||||
ServerBuilder::default()
|
||||
ServerHandle(tx, None)
|
||||
}
|
||||
|
||||
pub(crate) fn signal(&self, sig: Signal) {
|
||||
@ -91,13 +85,13 @@ impl Server {
|
||||
}
|
||||
}
|
||||
|
||||
impl Clone for Server {
|
||||
impl Clone for ServerHandle {
|
||||
fn clone(&self) -> Self {
|
||||
Self(self.0.clone(), None)
|
||||
}
|
||||
}
|
||||
|
||||
impl Future for Server {
|
||||
impl Future for ServerHandle {
|
||||
type Output = io::Result<()>;
|
||||
|
||||
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
||||
|
@ -2,7 +2,7 @@ use std::future::Future;
|
||||
use std::pin::Pin;
|
||||
use std::task::{Context, Poll};
|
||||
|
||||
use crate::server::Server;
|
||||
use crate::server::ServerHandle;
|
||||
|
||||
/// Types of process signals.
|
||||
#[allow(dead_code)]
|
||||
@ -20,7 +20,7 @@ pub(crate) enum Signal {
|
||||
|
||||
/// Process signal listener.
|
||||
pub(crate) struct Signals {
|
||||
srv: Server,
|
||||
srv: ServerHandle,
|
||||
|
||||
#[cfg(not(unix))]
|
||||
signals: futures_core::future::LocalBoxFuture<'static, std::io::Result<()>>,
|
||||
@ -31,7 +31,7 @@ pub(crate) struct Signals {
|
||||
|
||||
impl Signals {
|
||||
/// Spawns a signal listening future that is able to send commands to the `Server`.
|
||||
pub(crate) fn start(srv: Server) {
|
||||
pub(crate) fn start(srv: ServerHandle) {
|
||||
#[cfg(not(unix))]
|
||||
{
|
||||
actix_rt::spawn(Signals {
|
||||
|
@ -30,7 +30,7 @@ use std::{
|
||||
};
|
||||
|
||||
use actix_rt::net::TcpStream;
|
||||
use actix_server::Server;
|
||||
use actix_server::ServerHandle;
|
||||
use actix_service::ServiceFactoryExt as _;
|
||||
use actix_tls::accept::rustls::{Acceptor as RustlsAcceptor, TlsStream};
|
||||
use futures_util::future::ok;
|
||||
@ -67,7 +67,7 @@ async fn main() -> io::Result<()> {
|
||||
let addr = ("127.0.0.1", 8443);
|
||||
info!("starting server on port: {}", &addr.0);
|
||||
|
||||
Server::build()
|
||||
ServerHandle::build()
|
||||
.bind("tls-example", addr, move || {
|
||||
let count = Arc::clone(&count);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user