mirror of
https://github.com/fafhrd91/actix-net
synced 2024-11-24 01:11:07 +01:00
rename .run to .start()
This commit is contained in:
parent
e21c58930b
commit
1918c8d4f8
@ -1,5 +1,11 @@
|
|||||||
# Changes
|
# Changes
|
||||||
|
|
||||||
|
## [1.0.1] - 2019-12-29
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
* Rename `.start()` method to `.run()`
|
||||||
|
|
||||||
## [1.0.0] - 2019-12-11
|
## [1.0.0] - 2019-12-11
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "actix-server"
|
name = "actix-server"
|
||||||
version = "1.0.0"
|
version = "1.0.1"
|
||||||
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
|
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
|
||||||
description = "Actix server - General purpose tcp server"
|
description = "Actix server - General purpose tcp server"
|
||||||
keywords = ["network", "framework", "async", "futures"]
|
keywords = ["network", "framework", "async", "futures"]
|
||||||
@ -21,10 +21,10 @@ path = "src/lib.rs"
|
|||||||
default = []
|
default = []
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
actix-service = "1.0.0"
|
actix-service = "1.0.1"
|
||||||
actix-rt = "1.0.0"
|
actix-rt = "1.0.0"
|
||||||
actix-codec = "0.2.0"
|
actix-codec = "0.2.0"
|
||||||
actix-utils = "1.0.0"
|
actix-utils = "1.0.4"
|
||||||
|
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
num_cpus = "1.11"
|
num_cpus = "1.11"
|
||||||
@ -38,5 +38,5 @@ mio-uds = { version = "0.6.7" }
|
|||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
bytes = "0.5"
|
bytes = "0.5"
|
||||||
env_logger = "0.6"
|
env_logger = "0.7"
|
||||||
actix-testing = "1.0.0"
|
actix-testing = "1.0.0"
|
@ -31,7 +31,7 @@ pub struct ServerBuilder {
|
|||||||
backlog: i32,
|
backlog: i32,
|
||||||
workers: Vec<(usize, WorkerClient)>,
|
workers: Vec<(usize, WorkerClient)>,
|
||||||
services: Vec<Box<dyn InternalServiceFactory>>,
|
services: Vec<Box<dyn InternalServiceFactory>>,
|
||||||
sockets: Vec<(Token, StdListener)>,
|
sockets: Vec<(Token, String, StdListener)>,
|
||||||
accept: AcceptLoop,
|
accept: AcceptLoop,
|
||||||
exit: bool,
|
exit: bool,
|
||||||
shutdown_timeout: Duration,
|
shutdown_timeout: Duration,
|
||||||
@ -146,8 +146,8 @@ impl ServerBuilder {
|
|||||||
let mut srv = ConfiguredService::new(apply);
|
let mut srv = ConfiguredService::new(apply);
|
||||||
for (name, lst) in cfg.services {
|
for (name, lst) in cfg.services {
|
||||||
let token = self.token.next();
|
let token = self.token.next();
|
||||||
srv.stream(token, name, lst.local_addr()?);
|
srv.stream(token, name.clone(), lst.local_addr()?);
|
||||||
self.sockets.push((token, StdListener::Tcp(lst)));
|
self.sockets.push((token, name, StdListener::Tcp(lst)));
|
||||||
}
|
}
|
||||||
self.services.push(Box::new(srv));
|
self.services.push(Box::new(srv));
|
||||||
}
|
}
|
||||||
@ -172,7 +172,8 @@ impl ServerBuilder {
|
|||||||
factory.clone(),
|
factory.clone(),
|
||||||
lst.local_addr()?,
|
lst.local_addr()?,
|
||||||
));
|
));
|
||||||
self.sockets.push((token, StdListener::Tcp(lst)));
|
self.sockets
|
||||||
|
.push((token, name.as_ref().to_string(), StdListener::Tcp(lst)));
|
||||||
}
|
}
|
||||||
Ok(self)
|
Ok(self)
|
||||||
}
|
}
|
||||||
@ -222,7 +223,8 @@ impl ServerBuilder {
|
|||||||
factory.clone(),
|
factory.clone(),
|
||||||
addr,
|
addr,
|
||||||
));
|
));
|
||||||
self.sockets.push((token, StdListener::Uds(lst)));
|
self.sockets
|
||||||
|
.push((token, name.as_ref().to_string(), StdListener::Uds(lst)));
|
||||||
Ok(self)
|
Ok(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -243,36 +245,18 @@ impl ServerBuilder {
|
|||||||
factory,
|
factory,
|
||||||
lst.local_addr()?,
|
lst.local_addr()?,
|
||||||
));
|
));
|
||||||
self.sockets.push((token, StdListener::Tcp(lst)));
|
self.sockets
|
||||||
|
.push((token, name.as_ref().to_string(), StdListener::Tcp(lst)));
|
||||||
Ok(self)
|
Ok(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Spawn new thread and start listening for incoming connections.
|
#[doc(hidden)]
|
||||||
///
|
pub fn start(self) -> Server {
|
||||||
/// This method spawns new thread and starts new actix system. Other than
|
self.run()
|
||||||
/// that it is similar to `start()` method. This method blocks.
|
|
||||||
///
|
|
||||||
/// This methods panics if no socket addresses get bound.
|
|
||||||
///
|
|
||||||
/// ```rust,ignore
|
|
||||||
/// 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()
|
|
||||||
/// }
|
|
||||||
/// ```
|
|
||||||
pub fn run(self) -> io::Result<()> {
|
|
||||||
let sys = System::new("http-server");
|
|
||||||
self.start();
|
|
||||||
sys.run()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Starts processing incoming connections and return server controller.
|
/// Starts processing incoming connections and return server controller.
|
||||||
pub fn start(mut self) -> Server {
|
pub fn run(mut self) -> Server {
|
||||||
if self.sockets.is_empty() {
|
if self.sockets.is_empty() {
|
||||||
panic!("Server should have at least one bound socket");
|
panic!("Server should have at least one bound socket");
|
||||||
} else {
|
} else {
|
||||||
@ -288,10 +272,15 @@ impl ServerBuilder {
|
|||||||
|
|
||||||
// start accept thread
|
// start accept thread
|
||||||
for sock in &self.sockets {
|
for sock in &self.sockets {
|
||||||
info!("Starting server on {}", sock.1);
|
info!("Starting \"{}\" service on {}", sock.1, sock.2);
|
||||||
}
|
}
|
||||||
self.accept
|
self.accept.start(
|
||||||
.start(mem::replace(&mut self.sockets, Vec::new()), workers);
|
mem::replace(&mut self.sockets, Vec::new())
|
||||||
|
.into_iter()
|
||||||
|
.map(|t| (t.0, t.2))
|
||||||
|
.collect(),
|
||||||
|
workers,
|
||||||
|
);
|
||||||
|
|
||||||
// handle signals
|
// handle signals
|
||||||
if !self.no_signals {
|
if !self.no_signals {
|
||||||
|
Loading…
Reference in New Issue
Block a user