Skip to content

Commit

Permalink
Merge pull request #54 from onalante-msft/main
Browse files Browse the repository at this point in the history
  • Loading branch information
softprops authored Jan 10, 2022
2 parents c2480c1 + c95ce37 commit 7a2cbb8
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 25 deletions.
33 changes: 25 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,32 @@ edition = "2018"

[dependencies]
hex = "0.4"
hyper = { version = "0.14", features = ["server", "client", "http1", "runtime"] }
tokio = { version = "1.0", features = ["rt-multi-thread", "net"] }
pin-project = "1.0"
futures-util = "0.3"
hyper = "0.14"
tokio = { version = "1.0", features = ["net"] }
pin-project-lite = "0.2"

[dev-dependencies]
tokio = { version = "1.0", features = ["rt-multi-thread", "net", "macros", "io-std", "io-util"] }
tokio = { version = "1.0", features = ["io-std", "io-util", "macros", "rt-multi-thread"] }

[features]
client = []
server = []
default = ["client", "server"]
default = []
client = [
"hyper/client",
"hyper/http1",
]
server = [
"hyper/http1",
"hyper/server"
]

[[example]]
name = "client"
required-features = ["client", "hyper/runtime"]

[[example]]
name = "server"
required-features = ["server", "hyper/runtime"]

[[test]]
name = "server_client"
required-features = ["client", "server", "hyper/runtime"]
17 changes: 9 additions & 8 deletions src/client.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
use futures_util::future::BoxFuture;
use hex::FromHex;
use hyper::{
client::connect::{Connected, Connection},
service::Service,
Body, Client, Uri,
};
use pin_project::pin_project;
use pin_project_lite::pin_project;
use std::{
io,
future::Future,
path::{Path, PathBuf},
pin::Pin,
task::{Context, Poll},
};
use tokio::io::ReadBuf;

#[pin_project]
#[derive(Debug)]
pub struct UnixStream {
#[pin]
unix_stream: tokio::net::UnixStream,
pin_project! {
#[derive(Debug)]
pub struct UnixStream {
#[pin]
unix_stream: tokio::net::UnixStream,
}
}

impl UnixStream {
Expand Down Expand Up @@ -80,7 +81,7 @@ impl Unpin for UnixConnector {}
impl Service<Uri> for UnixConnector {
type Response = UnixStream;
type Error = std::io::Error;
type Future = BoxFuture<'static, Result<Self::Response, Self::Error>>;
type Future = Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>> + Send + 'static>>;
fn call(&mut self, req: Uri) -> Self::Future {
let fut = async move {
let path = parse_socket_path(req)?;
Expand Down
18 changes: 9 additions & 9 deletions src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ use hyper::server::{Builder, Server};
use conn::SocketIncoming;

pub(crate) mod conn {
use futures_util::ready;
use hyper::server::accept::Accept;
use pin_project::pin_project;
use pin_project_lite::pin_project;
use std::{
io,
path::Path,
Expand All @@ -16,11 +15,12 @@ pub(crate) mod conn {
};
use tokio::net::{UnixListener, UnixStream};

/// A stream of connections from binding to a socket.
#[pin_project]
#[derive(Debug)]
pub struct SocketIncoming {
listener: UnixListener,
pin_project! {
/// A stream of connections from binding to a socket.
#[derive(Debug)]
pub struct SocketIncoming {
listener: UnixListener,
}
}

impl SocketIncoming {
Expand Down Expand Up @@ -50,8 +50,8 @@ pub(crate) mod conn {
self: Pin<&mut Self>,
cx: &mut Context<'_>,
) -> Poll<Option<Result<Self::Conn, Self::Error>>> {
let conn = ready!(self.listener.poll_accept(cx))?.0;
Poll::Ready(Some(Ok(conn)))
self.listener.poll_accept(cx)?
.map(|(conn, _)| Some(Ok(conn)))
}
}

Expand Down

0 comments on commit 7a2cbb8

Please sign in to comment.