From c998c75515e410aeada79e24e975d29c0386d28c Mon Sep 17 00:00:00 2001 From: ami44 Date: Sat, 30 Dec 2017 21:08:54 +0100 Subject: [PATCH] move examples/state.rs to examples/state --- README.md | 2 +- examples/state/Cargo.toml | 10 ++++++++++ examples/state/README.md | 15 +++++++++++++++ examples/{state.rs => state/src/main.rs} | 8 +++++++- 4 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 examples/state/Cargo.toml create mode 100644 examples/state/README.md rename examples/{state.rs => state/src/main.rs} (88%) diff --git a/README.md b/README.md index 76306ec67..84ec0cd58 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,7 @@ Some basic benchmarks could be found in this [respository](https://github.com/fa ## Examples * [Basic](https://github.com/actix/actix-web/tree/master/examples/basic/) -* [Stateful](https://github.com/actix/actix-web/tree/master/examples/state.rs) +* [Stateful](https://github.com/actix/actix-web/tree/master/examples/state/) * [Mulitpart streams](https://github.com/actix/actix-web/tree/master/examples/multipart/) * [Simple websocket session](https://github.com/actix/actix-web/tree/master/examples/websocket.rs) * [Tera templates](https://github.com/actix/actix-web/tree/master/examples/template_tera/) diff --git a/examples/state/Cargo.toml b/examples/state/Cargo.toml new file mode 100644 index 000000000..c71fc86f8 --- /dev/null +++ b/examples/state/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "state" +version = "0.1.0" +authors = ["Nikolay Kim "] + +[dependencies] +futures = "*" +env_logger = "0.4" +actix = "^0.3.5" +actix-web = { git = "https://github.com/actix/actix-web", features=["signal"] } diff --git a/examples/state/README.md b/examples/state/README.md new file mode 100644 index 000000000..127ed2a0f --- /dev/null +++ b/examples/state/README.md @@ -0,0 +1,15 @@ +# state + +## Usage + +### server + +```bash +cd actix-web/examples/state +cargo run +# Started http server: 127.0.0.1:8080 +``` + +### web client + +- [http://localhost:8080/](http://localhost:8080/) diff --git a/examples/state.rs b/examples/state/src/main.rs similarity index 88% rename from examples/state.rs rename to examples/state/src/main.rs index dfa201f0c..c713e68ec 100644 --- a/examples/state.rs +++ b/examples/state/src/main.rs @@ -9,6 +9,7 @@ extern crate env_logger; use actix::*; use actix_web::*; +#[cfg(target_os = "linux")] use actix::actors::signal::{ProcessSignals, Subscribe}; use std::cell::Cell; struct AppState { @@ -60,7 +61,7 @@ fn main() { let _ = env_logger::init(); let sys = actix::System::new("ws-example"); - HttpServer::new( + let addr = HttpServer::new( || Application::with_state(AppState{counter: Cell::new(0)}) // enable logger .middleware(middleware::Logger::default()) @@ -73,6 +74,11 @@ fn main() { .bind("127.0.0.1:8080").unwrap() .start(); + if cfg!(target_os = "linux") { // Subscribe to unix signals + let signals = Arbiter::system_registry().get::(); + signals.send(Subscribe(addr.subscriber())); + } + println!("Started http server: 127.0.0.1:8080"); let _ = sys.run(); }