Skip to content

Commit

Permalink
rename Server => ServerHandler (#407)
Browse files Browse the repository at this point in the history
  • Loading branch information
robjtede committed Nov 1, 2021
1 parent 1c8fcae commit 581e599
Show file tree
Hide file tree
Showing 10 changed files with 96 additions and 81 deletions.
3 changes: 2 additions & 1 deletion .cargo/config.toml
@@ -1,5 +1,6 @@
[alias]
lint = "clippy --workspace --all-features --tests --examples --bins -- -Dclippy::todo"
lint = "clippy --workspace --tests --examples --bins -- -Dclippy::todo"
lint-all = "clippy --workspace --all-features --tests --examples --bins -- -Dclippy::todo"

ci-doctest = "test --workspace --all-features --doc --no-fail-fast -- --nocapture"

Expand Down
4 changes: 4 additions & 0 deletions actix-server/CHANGES.md
@@ -1,8 +1,12 @@
# Changes

## Unreleased - 2021-xx-xx
* Rename `Server` to `ServerHandle`. [#407]
* Rename `ServerBuilder::{maxconn => max_concurrent_connections}`. [#407]
* Minimum supported Rust version (MSRV) is now 1.52.

[#407]: https://github.com/actix/actix-net/pull/407


## 2.0.0-beta.6 - 2021-10-11
* Add experimental (semver-exempt) `io-uring` feature for enabling async file I/O on linux. [#374]
Expand Down
12 changes: 6 additions & 6 deletions actix-server/src/accept.rs
Expand Up @@ -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};
Expand All @@ -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));
Expand Down Expand Up @@ -74,7 +74,7 @@ struct Accept {
poll: Poll,
waker: WakerQueue,
handles: Vec<WorkerHandleAccept>,
srv: Server,
srv: ServerHandle,
next: usize,
avail: Availability,
paused: bool,
Expand Down Expand Up @@ -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
Expand All @@ -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()
Expand Down
35 changes: 20 additions & 15 deletions actix-server/src/builder.rs
Expand Up @@ -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};
Expand All @@ -35,7 +35,7 @@ pub struct ServerBuilder {
exit: bool,
no_signals: bool,
cmd: UnboundedReceiver<ServerCommand>,
server: Server,
server: ServerHandle,
notify: Vec<oneshot::Sender<()>>,
worker_config: ServerWorkerConfig,
}
Expand All @@ -50,7 +50,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(),
Expand All @@ -71,8 +71,8 @@ impl ServerBuilder {

/// Set number of workers to start.
///
/// By default server uses number of available logical cpu as workers
/// count. Workers must be greater than 0.
/// By default server uses number of available logical CPU as workers count. Workers must be
/// greater than 0.
pub fn workers(mut self, num: usize) -> Self {
assert_ne!(num, 0, "workers must be greater than 0");
self.threads = num;
Expand All @@ -99,10 +99,9 @@ impl ServerBuilder {

/// Set the maximum number of pending connections.
///
/// This refers to the number of clients that can be waiting to be served.
/// Exceeding this number results in the client getting an error when
/// attempting to connect. It should only affect servers under significant
/// load.
/// This refers to the number of clients that can be waiting to be served. Exceeding this number
/// results in the client getting an error when attempting to connect. It should only affect
/// servers under significant load.
///
/// Generally set in the 64-2048 range. Default value is 2048.
///
Expand All @@ -114,15 +113,21 @@ impl ServerBuilder {

/// Sets the maximum per-worker number of concurrent connections.
///
/// All socket listeners will stop accepting connections when this limit is
/// reached for each worker.
/// All socket listeners will stop accepting connections when this limit is reached for
/// each worker.
///
/// By default max connections is set to a 25k per worker.
pub fn maxconn(mut self, num: usize) -> Self {
pub fn max_concurrent_connections(mut self, num: usize) -> Self {
self.worker_config.max_concurrent_connections(num);
self
}

#[doc(hidden)]
#[deprecated(since = "2.0.0", note = "Renamed to `max_concurrent_connections`.")]
pub fn maxconn(self, num: usize) -> Self {
self.max_concurrent_connections(num)
}

/// Stop Actix system.
pub fn system_exit(mut self) -> Self {
self.exit = true;
Expand Down Expand Up @@ -191,8 +196,8 @@ impl ServerBuilder {
}

/// Add new unix domain service to the server.
/// Useful when running as a systemd service and
/// a socket FD can be acquired using the systemd crate.
///
/// Useful when running as a systemd service and a socket FD is acquired externally.
#[cfg(unix)]
pub fn listen_uds<F, N: AsRef<str>>(
mut self,
Expand Down Expand Up @@ -246,7 +251,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 {
Expand Down
2 changes: 1 addition & 1 deletion actix-server/src/lib.rs
Expand Up @@ -15,7 +15,7 @@ mod waker_queue;
mod worker;

pub use self::builder::ServerBuilder;
pub use self::server::Server;
pub use self::server::{Server, ServerHandle};
pub use self::service::ServiceFactory;
pub use self::test_server::TestServer;

Expand Down
26 changes: 16 additions & 10 deletions actix-server/src/server.rs
Expand Up @@ -24,6 +24,17 @@ pub(crate) enum ServerCommand {
Notify(oneshot::Sender<()>),
}

#[derive(Debug)]
#[non_exhaustive]
pub struct Server;

impl Server {
/// Start server building process.
pub fn build() -> ServerBuilder {
ServerBuilder::default()
}
}

/// Server handle.
///
/// # Shutdown Signals
Expand All @@ -32,19 +43,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) {
Expand Down Expand Up @@ -91,13 +97,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> {
Expand Down
6 changes: 3 additions & 3 deletions actix-server/src/signals.rs
Expand Up @@ -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)]
Expand All @@ -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<()>>,
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion actix-server/tests/test_server.rs
Expand Up @@ -170,7 +170,7 @@ async fn test_max_concurrent_connections() {
// Set a relative higher backlog.
.backlog(12)
// max connection for a worker is 3.
.maxconn(max_conn)
.max_concurrent_connections(max_conn)
.workers(1)
.disable_signals()
.bind("test", addr, move || {
Expand Down

0 comments on commit 581e599

Please sign in to comment.