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:
parent
b407c65f4c
commit
ac0e8b9e53
26
Cargo.toml
26
Cargo.toml
@ -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]
|
[workspace]
|
||||||
members = [
|
members = [
|
||||||
"actix-codec",
|
"actix-codec",
|
||||||
@ -9,3 +24,14 @@ members = [
|
|||||||
"actix-utils",
|
"actix-utils",
|
||||||
"router",
|
"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"
|
||||||
|
@ -5,12 +5,12 @@ use std::sync::{
|
|||||||
atomic::{AtomicUsize, Ordering},
|
atomic::{AtomicUsize, Ordering},
|
||||||
Arc,
|
Arc,
|
||||||
};
|
};
|
||||||
use std::{env, fmt};
|
use std::{env, fmt, io};
|
||||||
|
|
||||||
use actix_codec::{AsyncRead, AsyncWrite};
|
use actix_codec::{AsyncRead, AsyncWrite};
|
||||||
use actix_rt::System;
|
use actix_rt::System;
|
||||||
use actix_server::Server;
|
use actix_server::Server;
|
||||||
use actix_service::{IntoNewService, NewService};
|
use actix_service::{fn_service, NewService};
|
||||||
use futures::{future, Future};
|
use futures::{future, Future};
|
||||||
use openssl::ssl::{SslAcceptor, SslFiletype, SslMethod};
|
use openssl::ssl::{SslAcceptor, SslFiletype, SslMethod};
|
||||||
use tokio_openssl::SslAcceptorExt;
|
use tokio_openssl::SslAcceptorExt;
|
||||||
@ -23,7 +23,7 @@ fn logger<T: AsyncRead + AsyncWrite + fmt::Debug>(
|
|||||||
future::ok(stream)
|
future::ok(stream)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() -> io::Result<()> {
|
||||||
env::set_var("RUST_LOG", "actix_net=trace");
|
env::set_var("RUST_LOG", "actix_net=trace");
|
||||||
env_logger::init();
|
env_logger::init();
|
||||||
|
|
||||||
@ -54,16 +54,14 @@ fn main() {
|
|||||||
let acceptor = acceptor.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| {
|
fn_service(move |stream: tokio_tcp::TcpStream| {
|
||||||
SslAcceptorExt::accept_async(&acceptor, stream)
|
SslAcceptorExt::accept_async(&acceptor, stream)
|
||||||
.map_err(|e| println!("Openssl error: {}", e))
|
.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
|
// .and_then() combinator uses other service to convert incoming `Request` to a
|
||||||
// `Response` and then uses that response as an input for next
|
// `Response` and then uses that response as an input for next
|
||||||
// service. in this case, on success we use `logger` service
|
// service. in this case, on success we use `logger` service
|
||||||
.and_then(logger)
|
.and_then(fn_service(logger))
|
||||||
// Next service counts number of connections
|
// Next service counts number of connections
|
||||||
.and_then(move |_| {
|
.and_then(move |_| {
|
||||||
let num = num.fetch_add(1, Ordering::Relaxed);
|
let num = num.fetch_add(1, Ordering::Relaxed);
|
||||||
@ -75,5 +73,5 @@ fn main() {
|
|||||||
.unwrap()
|
.unwrap()
|
||||||
.start();
|
.start();
|
||||||
|
|
||||||
sys.run();
|
sys.run()
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
|
use std::io;
|
||||||
use std::sync::{
|
use std::sync::{
|
||||||
atomic::{AtomicUsize, Ordering},
|
atomic::{AtomicUsize, Ordering},
|
||||||
Arc,
|
Arc,
|
||||||
};
|
};
|
||||||
|
|
||||||
use actix_codec::{AsyncRead, AsyncWrite};
|
|
||||||
use actix_rt::System;
|
use actix_rt::System;
|
||||||
use actix_server::{ssl, Server};
|
use actix_server::{ssl, Server};
|
||||||
use actix_service::NewService;
|
use actix_service::NewService;
|
||||||
use futures::{future, Future};
|
use futures::future;
|
||||||
use openssl::ssl::{SslAcceptor, SslFiletype, SslMethod};
|
use openssl::ssl::{SslAcceptor, SslFiletype, SslMethod};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@ -15,16 +15,7 @@ struct ServiceState {
|
|||||||
num: Arc<AtomicUsize>,
|
num: Arc<AtomicUsize>,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn service<T: AsyncRead + AsyncWrite>(
|
fn main() -> io::Result<()> {
|
||||||
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() {
|
|
||||||
let sys = System::new("test");
|
let sys = System::new("test");
|
||||||
|
|
||||||
// load ssl keys
|
// load ssl keys
|
||||||
@ -53,9 +44,8 @@ fn main() {
|
|||||||
println!("got ssl connection {:?}", num);
|
println!("got ssl connection {:?}", num);
|
||||||
future::ok(())
|
future::ok(())
|
||||||
})
|
})
|
||||||
})
|
})?
|
||||||
.unwrap()
|
|
||||||
.start();
|
.start();
|
||||||
|
|
||||||
sys.run();
|
sys.run()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user