mirror of
https://github.com/fafhrd91/actix-net
synced 2024-11-24 00:01:11 +01:00
fix examples
This commit is contained in:
parent
d97f78afbe
commit
1261ecbce0
@ -61,8 +61,15 @@ fn main() {
|
|||||||
|
|
||||||
let num = Arc::new(AtomicUsize::new(0));
|
let num = Arc::new(AtomicUsize::new(0));
|
||||||
|
|
||||||
|
// bind socket address and start workers. By default server uses number of
|
||||||
|
// available logical cpu as threads count. actix net start separate
|
||||||
|
// instances of service pipeline in each worker.
|
||||||
|
Server::default().bind(
|
||||||
// configure service pipeline
|
// configure service pipeline
|
||||||
let srv =
|
"0.0.0.0:8443", move || {
|
||||||
|
let num = num.clone();
|
||||||
|
let acceptor = acceptor.clone();
|
||||||
|
|
||||||
// service for converting incoming TcpStream to a SslStream<TcpStream>
|
// service for converting incoming TcpStream to a SslStream<TcpStream>
|
||||||
(move |stream| {
|
(move |stream| {
|
||||||
SslAcceptorExt::accept_async(&acceptor, stream)
|
SslAcceptorExt::accept_async(&acceptor, stream)
|
||||||
@ -81,12 +88,8 @@ fn main() {
|
|||||||
// and use `service` function as `Service::call`
|
// and use `service` function as `Service::call`
|
||||||
.and_then((service, move || {
|
.and_then((service, move || {
|
||||||
Ok::<_, io::Error>(ServiceState { num: num.clone() })
|
Ok::<_, io::Error>(ServiceState { num: num.clone() })
|
||||||
}));
|
}))
|
||||||
|
}).unwrap().start();
|
||||||
// bind socket address and start workers. By default server uses number of
|
|
||||||
// available logical cpu as threads count. actix net start separate
|
|
||||||
// instances of service pipeline in each worker.
|
|
||||||
Server::default().bind("0.0.0.0:8443", srv).unwrap().start();
|
|
||||||
|
|
||||||
sys.run();
|
sys.run();
|
||||||
}
|
}
|
||||||
|
@ -43,13 +43,17 @@ fn main() {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let num = Arc::new(AtomicUsize::new(0));
|
let num = Arc::new(AtomicUsize::new(0));
|
||||||
|
let openssl = ssl::OpensslService::new(builder);
|
||||||
|
|
||||||
|
// server start mutiple workers, it runs supplied `Fn` in each worker.
|
||||||
|
Server::default().bind("0.0.0.0:8443", move || {
|
||||||
|
let num = num.clone();
|
||||||
|
|
||||||
// configure service
|
// configure service
|
||||||
let srv = ssl::OpensslService::new(builder).and_then((service, move || {
|
openssl.clone().and_then((service, move || {
|
||||||
Ok::<_, io::Error>(ServiceState { num: num.clone() })
|
Ok::<_, io::Error>(ServiceState { num: num.clone() })
|
||||||
}));
|
}))
|
||||||
|
}).unwrap().start();
|
||||||
Server::default().bind("0.0.0.0:8443", srv).unwrap().start();
|
|
||||||
|
|
||||||
sys.run();
|
sys.run();
|
||||||
}
|
}
|
||||||
|
@ -170,7 +170,7 @@ impl<C: Config> Server<C> {
|
|||||||
/// Add new service to server
|
/// Add new service to server
|
||||||
pub fn bind<F, U, N>(mut self, addr: U, factory: F) -> io::Result<Self>
|
pub fn bind<F, U, N>(mut self, addr: U, factory: F) -> io::Result<Self>
|
||||||
where
|
where
|
||||||
F: Fn() -> N + Copy + Send + 'static,
|
F: Fn() -> N + Clone + Send + 'static,
|
||||||
U: net::ToSocketAddrs,
|
U: net::ToSocketAddrs,
|
||||||
N: NewService<Request = TcpStream, Response = (), Config = C, InitError = io::Error> + 'static,
|
N: NewService<Request = TcpStream, Response = (), Config = C, InitError = io::Error> + 'static,
|
||||||
N::Service: 'static,
|
N::Service: 'static,
|
||||||
@ -188,7 +188,7 @@ impl<C: Config> Server<C> {
|
|||||||
/// Add new service to server
|
/// Add new service to server
|
||||||
pub fn listen<F, N>(mut self, lst: net::TcpListener, factory: F) -> Self
|
pub fn listen<F, N>(mut self, lst: net::TcpListener, factory: F) -> Self
|
||||||
where
|
where
|
||||||
F: Fn() -> N + Copy + Send + 'static,
|
F: Fn() -> N + Clone + Send + 'static,
|
||||||
N: NewService<Request = TcpStream, Response = (), Config = C, InitError = io::Error> + 'static,
|
N: NewService<Request = TcpStream, Response = (), Config = C, InitError = io::Error> + 'static,
|
||||||
N::Service: 'static,
|
N::Service: 'static,
|
||||||
N::Future: 'static,
|
N::Future: 'static,
|
||||||
|
Loading…
Reference in New Issue
Block a user