Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow driving server using user-provided runtime. #19

Merged
merged 1 commit into from
Sep 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions examples/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ extern crate hyperlocal;

use hyper::service::service_fn;
use hyper::{header, Body, Request, Response};
use std::io;
use std::{fs, io};

const PHRASE: &'static str = "It's a Unix system. I know this.";

Expand All @@ -22,17 +22,22 @@ fn hello(
}

fn run() -> io::Result<()> {
let svr = hyperlocal::server::Http::new().bind("test.sock", || service_fn(hello))?;
match fs::remove_file("test.sock") {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. I'm been trying come up with a way to impl drop for servers that cleans up the created file. This has been an annoyance when running the example. Thanks for this!

Ok(()) => (),
Err(ref err) if err.kind() == io::ErrorKind::NotFound => (),
Err(err) => panic!("{}", err),
}

let svr = hyperlocal::server::Server::bind("test.sock", || service_fn(hello))?;

for path in svr.local_addr()
.ok()
.and_then(|addr| addr.as_pathname().map(|pathname| pathname.to_owned()))
{
let path = svr.local_addr().as_pathname().unwrap();
println!(
"Listening on unix://{path} with 1 thread.",
path = path.as_path().to_string_lossy()
path = path.to_string_lossy(),
);
}

svr.run()?;
Ok(())
}
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
//!
//! See the `hyperlocal::UnixConnector` docs for how to configure hyper clients and the `hyperlocal::server::Http` docs
//! for how to configure hyper servers

extern crate futures;
extern crate hex;
extern crate hyper;
Expand Down
Loading