Struct actix_server::ServerBuilder
source · pub struct ServerBuilder { /* private fields */ }
Expand description
Server builder
Implementations§
source§impl ServerBuilder
impl ServerBuilder
sourcepub fn new() -> ServerBuilder
pub fn new() -> ServerBuilder
Create new Server builder instance
sourcepub fn workers(self, num: usize) -> Self
pub fn workers(self, num: usize) -> Self
Set number of workers to start.
By default server uses number of available logical cpu as workers count.
sourcepub fn backlog(self, num: i32) -> Self
pub fn backlog(self, num: i32) -> Self
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.
Generally set in the 64-2048 range. Default value is 2048.
This method should be called before bind()
method call.
sourcepub fn maxconn(self, num: usize) -> Self
pub fn maxconn(self, num: usize) -> Self
Sets the maximum per-worker number of concurrent connections.
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.
sourcepub fn maxconnrate(self, num: usize) -> Self
pub fn maxconnrate(self, num: usize) -> Self
Sets the maximum per-worker concurrent connection establish process.
All listeners will stop accepting connections when this limit is reached. It can be used to limit the global SSL CPU usage.
By default max connections is set to a 256.
sourcepub fn system_exit(self) -> Self
pub fn system_exit(self) -> Self
Stop actix system.
sourcepub fn disable_signals(self) -> Self
pub fn disable_signals(self) -> Self
Disable signal handling
sourcepub fn shutdown_timeout(self, sec: u64) -> Self
pub fn shutdown_timeout(self, sec: u64) -> Self
Timeout for graceful workers shutdown in seconds.
After receiving a stop signal, workers have this much time to finish serving requests. Workers still alive after the timeout are force dropped.
By default shutdown timeout sets to 30 seconds.
sourcepub fn configure<F>(self, f: F) -> Result<ServerBuilder>
pub fn configure<F>(self, f: F) -> Result<ServerBuilder>
Execute external configuration as part of the server building process.
This function is useful for moving parts of configuration to a different module or even library.
sourcepub fn bind<F, U, N: AsRef<str>>(
self,
name: N,
addr: U,
factory: F,
) -> Result<Self>
pub fn bind<F, U, N: AsRef<str>>( self, name: N, addr: U, factory: F, ) -> Result<Self>
Add new service to the server.
sourcepub fn bind_uds<F, U, N>(self, name: N, addr: U, factory: F) -> Result<Self>
pub fn bind_uds<F, U, N>(self, name: N, addr: U, factory: F) -> Result<Self>
Add new unix domain service to the server.
sourcepub fn listen_uds<F, N: AsRef<str>>(
self,
name: N,
lst: UnixListener,
factory: F,
) -> Result<Self>where
F: ServiceFactory<UnixStream>,
pub fn listen_uds<F, N: AsRef<str>>(
self,
name: N,
lst: UnixListener,
factory: F,
) -> Result<Self>where
F: ServiceFactory<UnixStream>,
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.
sourcepub fn listen<F, N: AsRef<str>>(
self,
name: N,
lst: TcpListener,
factory: F,
) -> Result<Self>where
F: ServiceFactory<TcpStream>,
pub fn listen<F, N: AsRef<str>>(
self,
name: N,
lst: TcpListener,
factory: F,
) -> Result<Self>where
F: ServiceFactory<TcpStream>,
Add new service to the server.
sourcepub fn run(self) -> Result<()>
pub fn run(self) -> Result<()>
Spawn new thread and start listening for incoming connections.
This method spawns new thread and starts new actix system. Other than
that it is similar to start()
method. This method blocks.
This methods panics if no socket addresses get bound.
use actix_web::*;
fn main() -> std::io::Result<()> {
Server::new().
.service(
HttpServer::new(|| App::new().service(web::service("/").to(|| HttpResponse::Ok())))
.bind("127.0.0.1:0")
.run()
}
Trait Implementations§
source§impl Default for ServerBuilder
impl Default for ServerBuilder
source§impl Future for ServerBuilder
impl Future for ServerBuilder
§type Error = ()
type Error = ()
source§fn poll(&mut self) -> Poll<Self::Item, Self::Error>
fn poll(&mut self) -> Poll<Self::Item, Self::Error>
source§fn wait(self) -> Result<Self::Item, Self::Error>where
Self: Sized,
fn wait(self) -> Result<Self::Item, Self::Error>where
Self: Sized,
source§fn map<F, U>(self, f: F) -> Map<Self, F>
fn map<F, U>(self, f: F) -> Map<Self, F>
source§fn map_err<F, E>(self, f: F) -> MapErr<Self, F>
fn map_err<F, E>(self, f: F) -> MapErr<Self, F>
source§fn from_err<E>(self) -> FromErr<Self, E>
fn from_err<E>(self) -> FromErr<Self, E>
From
for
this future’s Error
, returning a new future. Read moresource§fn then<F, B>(self, f: F) -> Then<Self, B, F>
fn then<F, B>(self, f: F) -> Then<Self, B, F>
f
. Read moresource§fn and_then<F, B>(self, f: F) -> AndThen<Self, B, F>
fn and_then<F, B>(self, f: F) -> AndThen<Self, B, F>
source§fn or_else<F, B>(self, f: F) -> OrElse<Self, B, F>
fn or_else<F, B>(self, f: F) -> OrElse<Self, B, F>
source§fn select<B>(self, other: B) -> Select<Self, <B as IntoFuture>::Future>
fn select<B>(self, other: B) -> Select<Self, <B as IntoFuture>::Future>
source§fn select2<B>(self, other: B) -> Select2<Self, <B as IntoFuture>::Future>where
B: IntoFuture,
Self: Sized,
fn select2<B>(self, other: B) -> Select2<Self, <B as IntoFuture>::Future>where
B: IntoFuture,
Self: Sized,
source§fn join<B>(self, other: B) -> Join<Self, <B as IntoFuture>::Future>
fn join<B>(self, other: B) -> Join<Self, <B as IntoFuture>::Future>
source§fn join3<B, C>(
self,
b: B,
c: C,
) -> Join3<Self, <B as IntoFuture>::Future, <C as IntoFuture>::Future>
fn join3<B, C>( self, b: B, c: C, ) -> Join3<Self, <B as IntoFuture>::Future, <C as IntoFuture>::Future>
join
, but with more futures.source§fn join4<B, C, D>(
self,
b: B,
c: C,
d: D,
) -> Join4<Self, <B as IntoFuture>::Future, <C as IntoFuture>::Future, <D as IntoFuture>::Future>where
B: IntoFuture<Error = Self::Error>,
C: IntoFuture<Error = Self::Error>,
D: IntoFuture<Error = Self::Error>,
Self: Sized,
fn join4<B, C, D>(
self,
b: B,
c: C,
d: D,
) -> Join4<Self, <B as IntoFuture>::Future, <C as IntoFuture>::Future, <D as IntoFuture>::Future>where
B: IntoFuture<Error = Self::Error>,
C: IntoFuture<Error = Self::Error>,
D: IntoFuture<Error = Self::Error>,
Self: Sized,
join
, but with more futures.source§fn join5<B, C, D, E>(
self,
b: B,
c: C,
d: D,
e: E,
) -> Join5<Self, <B as IntoFuture>::Future, <C as IntoFuture>::Future, <D as IntoFuture>::Future, <E as IntoFuture>::Future>where
B: IntoFuture<Error = Self::Error>,
C: IntoFuture<Error = Self::Error>,
D: IntoFuture<Error = Self::Error>,
E: IntoFuture<Error = Self::Error>,
Self: Sized,
fn join5<B, C, D, E>(
self,
b: B,
c: C,
d: D,
e: E,
) -> Join5<Self, <B as IntoFuture>::Future, <C as IntoFuture>::Future, <D as IntoFuture>::Future, <E as IntoFuture>::Future>where
B: IntoFuture<Error = Self::Error>,
C: IntoFuture<Error = Self::Error>,
D: IntoFuture<Error = Self::Error>,
E: IntoFuture<Error = Self::Error>,
Self: Sized,
join
, but with more futures.source§fn into_stream(self) -> IntoStream<Self>where
Self: Sized,
fn into_stream(self) -> IntoStream<Self>where
Self: Sized,
source§fn fuse(self) -> Fuse<Self>where
Self: Sized,
fn fuse(self) -> Fuse<Self>where
Self: Sized,
poll
will never again be called once it has
completed. Read more