Skip to content

Commit

Permalink
Merge pull request RustCrypto#4 from wiktor-k/add-listen
Browse files Browse the repository at this point in the history
Add universal `listen` function
  • Loading branch information
wiktor-k authored Apr 22, 2022
2 parents 4007199 + a69ca5d commit 185eef2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ssh-agent-lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ edition = "2021"
[dependencies]
byteorder = "1.2.7"
serde = {version = "1.0.87", features = ["derive"]}

service-binding = "0.1.1"
bytes = { version = "0.4.11", optional = true }
futures = { version = "0.1.25", optional = true }
log = { version = "0.4.6", optional = true }
Expand Down
18 changes: 18 additions & 0 deletions ssh-agent-lib/src/agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,22 @@ pub trait Agent: 'static + Sync + Send + Sized {
let socket = TcpListener::bind(&addr.parse::<SocketAddr>()?)?;
Ok(tokio::run(handle_clients!(self, socket)))
}

#[allow(clippy::unit_arg)]
fn listen<T>(self, socket: T) -> Result<(), Box<dyn Error + Send + Sync>>
where
T: Into<service_binding::Listener>,
{
let socket = socket.into();
match socket {
service_binding::Listener::Unix(listener) => {
let listener = UnixListener::from_std(listener, &Default::default())?;
Ok(tokio::run(handle_clients!(self, listener)))
}
service_binding::Listener::Tcp(listener) => {
let listener = TcpListener::from_std(listener, &Default::default())?;
Ok(tokio::run(handle_clients!(self, listener)))
}
}
}
}

0 comments on commit 185eef2

Please sign in to comment.