1
0
mirror of https://github.com/fafhrd91/actix-net synced 2024-11-27 16:52:58 +01:00
framework for composable networking services
Go to file
2018-09-14 00:07:50 -07:00
examples remove wrong doc example 2018-09-11 11:28:13 -07:00
src fix switching to unavailable state for worker 2018-09-14 00:07:50 -07:00
.appveyor.yml cleanups 2018-08-21 21:11:16 -07:00
.gitignore initial import 2018-08-19 10:47:04 -07:00
.travis.yml move server impl to sub module 2018-09-11 08:43:23 -07:00
Cargo.toml refactor worker availibility management 2018-09-13 23:46:18 -07:00
CODE_OF_CONDUCT.md initial import 2018-08-19 10:47:04 -07:00
LICENSE-APACHE initial import 2018-08-19 10:47:04 -07:00
LICENSE-MIT initial import 2018-08-19 10:47:04 -07:00
README.md fix api doc link 2018-09-11 14:01:51 -07:00
rustfmt.toml initial import 2018-08-19 10:47:04 -07:00

Actix net Build Status codecov crates.io Join the chat at https://gitter.im/actix/actix

Actix net - framework for compossible network services

Documentation & community resources

Example

fn main() {
    let sys = actix::System::new("test");

    // load ssl keys
    let mut builder = SslAcceptor::mozilla_intermediate(SslMethod::tls()).unwrap();
    builder.set_private_key_file("./examples/key.pem", SslFiletype::PEM).unwrap();
    builder.set_certificate_chain_file("./examples/cert.pem").unwrap();
    let acceptor = builder.build();

    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
            "0.0.0.0:8443",
            move || {
                let num = num.clone();
                let acceptor = acceptor.clone();

                // service for converting incoming TcpStream to a SslStream<TcpStream>
                (move |stream| {
                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)

            // next service uses two components, service state and service function
            // actix-net generates `NewService` impl that creates `ServiceState` instance for each new service
            // and use `service` function as `Service::call`
            .and_then((service, move || {
                Ok(ServiceState { num: num.clone() })
            }))
            },
        ).unwrap()
        .start();

    sys.run();
}

License

This project is licensed under either of

at your option.

Code of Conduct

Contribution to the actix-net crate is organized under the terms of the Contributor Covenant, the maintainer of actix-net, @fafhrd91, promises to intervene to uphold that code of conduct.