diff --git a/Cargo.toml b/Cargo.toml index 665b0400..88a87427 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,3 +1,18 @@ +[package] +name = "actix-net" +version = "0.3.0" +authors = ["Nikolay Kim "] +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" diff --git a/examples/basic.rs b/examples/basic.rs index 6647f30a..d2f90901 100644 --- a/examples/basic.rs +++ b/examples/basic.rs @@ -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( 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 - (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() } diff --git a/examples/ssl.rs b/examples/ssl.rs index 0c0738ad..b7b70f1d 100644 --- a/examples/ssl.rs +++ b/examples/ssl.rs @@ -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, } -fn service( - st: &mut ServiceState, - _: T, -) -> impl Future { - 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() }