pub struct Server { /* private fields */ }
Expand description
Server
Implementations§
source§impl Server
impl Server
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 threads count.
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 system_exit(self) -> Self
pub fn system_exit(self) -> Self
Stop actix system.
SystemExit
message stops currently running system.
sourcepub fn disable_signals(self) -> Self
pub fn disable_signals(self) -> Self
Disable signal handling
sourcepub fn shutdown_timeout(self, sec: u16) -> Self
pub fn shutdown_timeout(self, sec: u16) -> 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<Server>where
F: Fn(&mut ServiceConfig) -> Result<()>,
pub fn configure<F>(self, f: F) -> Result<Server>where
F: Fn(&mut ServiceConfig) -> Result<()>,
Run 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>where
F: StreamServiceFactory,
U: ToSocketAddrs,
pub fn bind<F, U, N: AsRef<str>>(
self,
name: N,
addr: U,
factory: F
) -> Result<Self>where
F: StreamServiceFactory,
U: ToSocketAddrs,
Add new service to server
sourcepub fn listen<F, N: AsRef<str>>(
self,
name: N,
lst: TcpListener,
factory: F
) -> Selfwhere
F: StreamServiceFactory,
pub fn listen<F, N: AsRef<str>>(
self,
name: N,
lst: TcpListener,
factory: F
) -> Selfwhere
F: StreamServiceFactory,
Add new service to server
sourcepub fn listen2<F, N: AsRef<str>>(
self,
name: N,
lst: TcpListener,
factory: F
) -> Selfwhere
F: ServiceFactory,
pub fn listen2<F, N: AsRef<str>>(
self,
name: N,
lst: TcpListener,
factory: F
) -> Selfwhere
F: ServiceFactory,
Add new service to server
sourcepub fn run(self)
pub fn run(self)
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() {
Server::new().
.service(
HttpServer::new(|| App::new().resource("/", |r| r.h(|_| HttpResponse::Ok())))
.bind("127.0.0.1:0")
.expect("Can not bind to 127.0.0.1:0"))
.run();
}
Trait Implementations§
source§impl Actor for Server
impl Actor for Server
source§fn started(&mut self, ctx: &mut Self::Context)
fn started(&mut self, ctx: &mut Self::Context)
source§fn stopping(&mut self, ctx: &mut Self::Context) -> Running
fn stopping(&mut self, ctx: &mut Self::Context) -> Running
Actor::Stopping
state. There
could be several reasons for stopping. Context::stop
get called
by the actor itself. All addresses to current actor get dropped and
no more evented objects left in the context. Read more