1
0
mirror of https://github.com/actix/examples synced 2025-06-26 09:17:41 +02:00

reenable uds example; cargo fmt

This commit is contained in:
Nikolay Kim
2019-07-18 18:03:19 +06:00
parent 7525903fe6
commit 44053504ad
11 changed files with 216 additions and 146 deletions

View File

@ -2,11 +2,11 @@
name = "unix-socket"
version = "0.1.0"
authors = ["Messense Lv <messense@icloud.com>"]
workspace = "../"
workspace = ".."
edition = "2018"
[dependencies]
env_logger = "0.5"
tokio-uds = "0.2"
actix = "0.7"
actix-web = "0.7"
actix-web = { version = "1.0.5", features = ["uds"] }

View File

@ -7,7 +7,7 @@ Hello world!
Although this will only one thread for handling incoming connections
according to the
[documentation](https://actix.github.io/actix-web/actix_web/struct.HttpServer.html#method.start_incoming).
[documentation](https://actix.github.io/actix-web/actix_web/struct.HttpServer.html#method.bind_uds).
And it does not delete the socket file (`/tmp/actix-uds.socket`) when stopping
the server so it will fail to start next time you run it unless you delete

View File

@ -1,31 +1,22 @@
extern crate actix;
extern crate actix_web;
extern crate env_logger;
extern crate tokio_uds;
use actix_web::{middleware, web, App, HttpRequest, HttpServer};
use actix::*;
use actix_web::{middleware, server, App, HttpRequest};
use tokio_uds::UnixListener;
fn index(_req: &HttpRequest) -> &'static str {
fn index(_req: HttpRequest) -> &'static str {
"Hello world!"
}
fn main() {
::std::env::set_var("RUST_LOG", "actix_web=info");
fn main() -> std::io::Result<()> {
::std::env::set_var("RUST_LOG", "actix_server=info,actix_web=info");
env_logger::init();
let sys = actix::System::new("unix-socket");
let listener = UnixListener::bind("/tmp/actix-uds.socket").expect("bind failed");
server::new(|| {
HttpServer::new(|| {
App::new()
// enable logger
.middleware(middleware::Logger::default())
.resource("/index.html", |r| r.f(|_| "Hello world!"))
.resource("/", |r| r.f(index))
// enable logger - always register actix-web Logger middleware last
.wrap(middleware::Logger::default())
.service(
web::resource("/index.html").route(web::get().to(|| "Hello world!")),
)
.service(web::resource("/").to(index))
})
.start_incoming(listener.incoming(), false);
println!("Started http server: /tmp/actix-uds.socket");
let _ = sys.run();
.bind_uds("/tmp/actix-uds.socket")?
.run()
}