1
0
Fork 0
mirror of https://github.com/actix/actix-web.git synced 2024-12-16 13:16:34 +00:00

fix examples - disable signal if windows

This commit is contained in:
ami44 2017-12-30 21:05:03 +01:00
parent 87188e1505
commit 76b03851e6
7 changed files with 42 additions and 34 deletions

View file

@ -7,9 +7,9 @@ extern crate env_logger;
extern crate futures; extern crate futures;
use futures::Stream; use futures::Stream;
use actix::*;
use actix_web::*; use actix_web::*;
use actix::Arbiter; #[cfg(target_os = "linux")] use actix::actors::signal::{ProcessSignals, Subscribe};
use actix::actors::signal::{ProcessSignals, Subscribe};
use actix_web::middleware::RequestSession; use actix_web::middleware::RequestSession;
use futures::future::{FutureResult, result}; use futures::future::{FutureResult, result};
@ -96,9 +96,10 @@ fn main() {
.bind("0.0.0.0:8080").unwrap() .bind("0.0.0.0:8080").unwrap()
.start(); .start();
// Subscribe to unix signals if cfg!(target_os = "linux") { // Subscribe to unix signals
let signals = Arbiter::system_registry().get::<ProcessSignals>(); let signals = Arbiter::system_registry().get::<ProcessSignals>();
signals.send(Subscribe(addr.subscriber())); signals.send(Subscribe(addr.subscriber()));
}
println!("Starting http server: 127.0.0.1:8080"); println!("Starting http server: 127.0.0.1:8080");
let _ = sys.run(); let _ = sys.run();

View file

@ -7,15 +7,14 @@ extern crate serde_json;
#[macro_use] extern crate serde_derive; #[macro_use] extern crate serde_derive;
#[macro_use] extern crate json; #[macro_use] extern crate json;
use actix::*;
use actix_web::*; use actix_web::*;
#[cfg(target_os = "linux")] use actix::actors::signal::{ProcessSignals, Subscribe};
use bytes::BytesMut; use bytes::BytesMut;
use futures::{Future, Stream}; use futures::{Future, Stream};
use json::JsonValue; use json::JsonValue;
use actix::Arbiter;
use actix::actors::signal::{ProcessSignals, Subscribe};
#[derive(Debug, Serialize, Deserialize)] #[derive(Debug, Serialize, Deserialize)]
struct MyObj { struct MyObj {
name: String, name: String,
@ -97,8 +96,10 @@ fn main() {
.shutdown_timeout(1) .shutdown_timeout(1)
.start(); .start();
if cfg!(target_os = "linux") { // Subscribe to unix signals
let signals = Arbiter::system_registry().get::<ProcessSignals>(); let signals = Arbiter::system_registry().get::<ProcessSignals>();
signals.send(Subscribe(addr.subscriber())); signals.send(Subscribe(addr.subscriber()));
}
println!("Started http server: 127.0.0.1:8080"); println!("Started http server: 127.0.0.1:8080");
let _ = sys.run(); let _ = sys.run();

View file

@ -6,11 +6,11 @@ extern crate futures;
use actix::*; use actix::*;
use actix_web::*; use actix_web::*;
#[cfg(target_os = "linux")] use actix::actors::signal::{ProcessSignals, Subscribe};
use futures::{Future, Stream}; use futures::{Future, Stream};
use futures::future::{result, Either}; use futures::future::{result, Either};
use actix::Arbiter;
use actix::actors::signal::{ProcessSignals, Subscribe};
fn index(mut req: HttpRequest) -> Box<Future<Item=HttpResponse, Error=Error>> fn index(mut req: HttpRequest) -> Box<Future<Item=HttpResponse, Error=Error>>
{ {
@ -55,8 +55,10 @@ fn main() {
.bind("127.0.0.1:8080").unwrap() .bind("127.0.0.1:8080").unwrap()
.start(); .start();
if cfg!(target_os = "linux") { // Subscribe to unix signals
let signals = Arbiter::system_registry().get::<ProcessSignals>(); let signals = Arbiter::system_registry().get::<ProcessSignals>();
signals.send(Subscribe(addr.subscriber())); signals.send(Subscribe(addr.subscriber()));
}
println!("Starting http server: 127.0.0.1:8080"); println!("Starting http server: 127.0.0.1:8080");
let _ = sys.run(); let _ = sys.run();

View file

@ -5,7 +5,7 @@ extern crate env_logger;
use actix::*; use actix::*;
use actix_web::*; use actix_web::*;
use actix::actors::signal::{ProcessSignals, Subscribe}; #[cfg(target_os = "linux")] use actix::actors::signal::{ProcessSignals, Subscribe};
struct MyWebSocket; struct MyWebSocket;
@ -34,9 +34,10 @@ fn main() {
.bind("127.0.0.1:8080").unwrap() .bind("127.0.0.1:8080").unwrap()
.start(); .start();
// Subscribe to unix signals if cfg!(target_os = "linux") { // Subscribe to unix signals
let signals = Arbiter::system_registry().get::<ProcessSignals>(); let signals = Arbiter::system_registry().get::<ProcessSignals>();
signals.send(Subscribe(addr.subscriber())); signals.send(Subscribe(addr.subscriber()));
}
println!("Started http server: 127.0.0.1:8080"); println!("Started http server: 127.0.0.1:8080");
let _ = sys.run(); let _ = sys.run();

View file

@ -3,9 +3,10 @@ extern crate actix_web;
extern crate env_logger; extern crate env_logger;
#[macro_use] #[macro_use]
extern crate tera; extern crate tera;
use actix::*;
use actix_web::*; use actix_web::*;
use actix::Arbiter; #[cfg(target_os = "linux")] use actix::actors::signal::{ProcessSignals, Subscribe};
use actix::actors::signal::{ProcessSignals, Subscribe};
struct State { struct State {
template: tera::Tera, // <- store tera template in application state template: tera::Tera, // <- store tera template in application state
@ -42,9 +43,10 @@ fn main() {
.bind("127.0.0.1:8080").unwrap() .bind("127.0.0.1:8080").unwrap()
.start(); .start();
// Subscribe to unix signals if cfg!(target_os = "linux") { // Subscribe to unix signals
let signals = Arbiter::system_registry().get::<ProcessSignals>(); let signals = Arbiter::system_registry().get::<ProcessSignals>();
signals.send(Subscribe(addr.subscriber())); signals.send(Subscribe(addr.subscriber()));
}
println!("Started http server: 127.0.0.1:8080"); println!("Started http server: 127.0.0.1:8080");
let _ = sys.run(); let _ = sys.run();

View file

@ -6,9 +6,9 @@ extern crate env_logger;
use std::fs::File; use std::fs::File;
use std::io::Read; use std::io::Read;
use actix::*;
use actix_web::*; use actix_web::*;
use actix::Arbiter; #[cfg(target_os = "linux")] use actix::actors::signal::{ProcessSignals, Subscribe};
use actix::actors::signal::{ProcessSignals, Subscribe};
/// somple handle /// somple handle
fn index(req: HttpRequest) -> Result<HttpResponse> { fn index(req: HttpRequest) -> Result<HttpResponse> {
@ -47,9 +47,10 @@ fn main() {
.bind("127.0.0.1:8443").unwrap() .bind("127.0.0.1:8443").unwrap()
.start_ssl(&pkcs12).unwrap(); .start_ssl(&pkcs12).unwrap();
// Subscribe to unix signals if cfg!(target_os = "linux") { // Subscribe to unix signals
let signals = Arbiter::system_registry().get::<ProcessSignals>(); let signals = Arbiter::system_registry().get::<ProcessSignals>();
signals.send(Subscribe(addr.subscriber())); signals.send(Subscribe(addr.subscriber()));
}
println!("Started http server: 127.0.0.1:8443"); println!("Started http server: 127.0.0.1:8443");
let _ = sys.run(); let _ = sys.run();

View file

@ -17,8 +17,7 @@ use std::time::Instant;
use actix::*; use actix::*;
use actix_web::*; use actix_web::*;
use actix::Arbiter; #[cfg(target_os = "linux")] use actix::actors::signal::{ProcessSignals, Subscribe};
use actix::actors::signal::{ProcessSignals, Subscribe};
mod codec; mod codec;
mod server; mod server;
@ -216,9 +215,10 @@ fn main() {
.bind("127.0.0.1:8080").unwrap() .bind("127.0.0.1:8080").unwrap()
.start(); .start();
// Subscribe to unix signals if cfg!(target_os = "linux") { // Subscribe to unix signals
let signals = Arbiter::system_registry().get::<ProcessSignals>(); let signals = Arbiter::system_registry().get::<ProcessSignals>();
signals.send(Subscribe(addr.subscriber())); signals.send(Subscribe(addr.subscriber()));
}
println!("Started http server: 127.0.0.1:8080"); println!("Started http server: 127.0.0.1:8080");
let _ = sys.run(); let _ = sys.run();