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

Dependency segmentation #54

Merged
merged 4 commits into from
Jan 10, 2022
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
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