1
0
mirror of https://github.com/fafhrd91/actix-net synced 2024-11-27 16:52:58 +01:00

re-enable examples

This commit is contained in:
Nikolay Kim 2019-03-06 23:33:35 -08:00
parent b407c65f4c
commit ac0e8b9e53
3 changed files with 37 additions and 23 deletions

View File

@ -1,3 +1,18 @@
[package]
name = "actix-net"
version = "0.3.0"
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
description = "Actix net - framework for the compisible network services for Rust"
readme = "README.md"
keywords = ["network", "framework", "async", "futures"]
homepage = "https://actix.rs"
repository = "https://github.com/actix/actix-net.git"
documentation = "https://docs.rs/actix-net/"
categories = ["network-programming", "asynchronous"]
license = "MIT/Apache-2.0"
exclude = [".gitignore", ".travis.yml", ".cargo/config", "appveyor.yml"]
edition = "2018"
[workspace]
members = [
"actix-codec",
@ -9,3 +24,14 @@ members = [
"actix-utils",
"router",
]
[dev-dependencies]
actix-service = { path="actix-service" }
actix-codec = "0.1.1"
actix-rt = "0.2.0"
actix-server = { path="actix-server", features=["ssl"] }
env_logger = "0.6"
futures = "0.1.25"
openssl = "0.10"
tokio-tcp = "0.1"
tokio-openssl = "0.3"

View File

@ -5,12 +5,12 @@ use std::sync::{
atomic::{AtomicUsize, Ordering},
Arc,
};
use std::{env, fmt};
use std::{env, fmt, io};
use actix_codec::{AsyncRead, AsyncWrite};
use actix_rt::System;
use actix_server::Server;
use actix_service::{IntoNewService, NewService};
use actix_service::{fn_service, NewService};
use futures::{future, Future};
use openssl::ssl::{SslAcceptor, SslFiletype, SslMethod};
use tokio_openssl::SslAcceptorExt;
@ -23,7 +23,7 @@ fn logger<T: AsyncRead + AsyncWrite + fmt::Debug>(
future::ok(stream)
}
fn main() {
fn main() -> io::Result<()> {
env::set_var("RUST_LOG", "actix_net=trace");
env_logger::init();
@ -54,16 +54,14 @@ fn main() {
let acceptor = acceptor.clone();
// service for converting incoming TcpStream to a SslStream<TcpStream>
(move |stream| {
fn_service(move |stream: tokio_tcp::TcpStream| {
SslAcceptorExt::accept_async(&acceptor, stream)
.map_err(|e| println!("Openssl error: {}", e))
})
// convert closure to a `NewService`
.into_new_service()
// .and_then() combinator uses other service to convert incoming `Request` to a
// `Response` and then uses that response as an input for next
// service. in this case, on success we use `logger` service
.and_then(logger)
.and_then(fn_service(logger))
// Next service counts number of connections
.and_then(move |_| {
let num = num.fetch_add(1, Ordering::Relaxed);
@ -75,5 +73,5 @@ fn main() {
.unwrap()
.start();
sys.run();
sys.run()
}

View File

@ -1,13 +1,13 @@
use std::io;
use std::sync::{
atomic::{AtomicUsize, Ordering},
Arc,
};
use actix_codec::{AsyncRead, AsyncWrite};
use actix_rt::System;
use actix_server::{ssl, Server};
use actix_service::NewService;
use futures::{future, Future};
use futures::future;
use openssl::ssl::{SslAcceptor, SslFiletype, SslMethod};
#[derive(Debug)]
@ -15,16 +15,7 @@ struct ServiceState {
num: Arc<AtomicUsize>,
}
fn service<T: AsyncRead + AsyncWrite>(
st: &mut ServiceState,
_: T,
) -> impl Future<Item = (), Error = ()> {
let num = st.num.fetch_add(1, Ordering::Relaxed);
println!("got ssl connection {:?}", num);
future::ok(())
}
fn main() {
fn main() -> io::Result<()> {
let sys = System::new("test");
// load ssl keys
@ -53,9 +44,8 @@ fn main() {
println!("got ssl connection {:?}", num);
future::ok(())
})
})
.unwrap()
})?
.start();
sys.run();
sys.run()
}