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

Rename NamedPipeListener::new to bind for consistency #29

Merged
merged 1 commit into from
Apr 5, 2024
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
18 changes: 7 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ On Unix it uses `ssh-agent.sock` Unix domain socket while on Windows it uses a n

```rust,no_run
#[cfg(not(windows))]
use tokio::net::UnixListener;
use tokio::net::UnixListener as Listener;
#[cfg(windows)]
use ssh_agent_lib::agent::NamedPipeListener;
use ssh_agent_lib::agent::NamedPipeListener as Listener;
use ssh_agent_lib::agent::{Session, Agent};
use ssh_agent_lib::proto::message::Message;
Expand All @@ -43,19 +43,15 @@ impl Session for MyAgent {
}
#[tokio::main]
#[cfg(not(windows))]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
#[cfg(not(windows))]
let socket = "ssh-agent.sock";
let _ = std::fs::remove_file(socket); // remove the socket if exists
#[cfg(windows)]
let socket = r"\\.\pipe\agent";
MyAgent.listen(UnixListener::bind(socket)?).await?;
Ok(())
}
let _ = std::fs::remove_file(socket); // remove the socket if exists
#[tokio::main]
#[cfg(windows)]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
MyAgent.listen(NamedPipeListener::new(r"\\.\pipe\agent".into())?).await?;
MyAgent.listen(Listener::bind(socket)?).await?;
Ok(())
}
```
Expand Down
24 changes: 10 additions & 14 deletions examples/key_storage.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use async_trait::async_trait;
use log::info;
#[cfg(windows)]
use ssh_agent_lib::agent::NamedPipeListener;
use ssh_agent_lib::agent::NamedPipeListener as Listener;
use ssh_agent_lib::proto::extension::SessionBind;
#[cfg(not(windows))]
use tokio::net::UnixListener;
use tokio::net::UnixListener as Listener;

use ssh_agent_lib::agent::{Agent, Session};
use ssh_agent_lib::proto::message::{self, Message, SignRequest};
Expand Down Expand Up @@ -221,26 +221,22 @@ impl Agent for KeyStorageAgent {
}

#[tokio::main]
#[cfg(not(windows))]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
env_logger::init();

#[cfg(not(windows))]
let socket = "ssh-agent.sock";
let _ = std::fs::remove_file(socket); // remove the socket if exists
#[cfg(windows)]
let socket = r"\\.\pipe\agent";

KeyStorageAgent::new()
.listen(UnixListener::bind(socket)?)
.await?;
Ok(())
}
let _ = std::fs::remove_file(socket); // remove the socket if exists

#[tokio::main]
#[cfg(windows)]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// This is only used for integration tests on Windows:
#[cfg(windows)]
std::fs::File::create("server-started")?;
// ^ You can remove this line

KeyStorageAgent::new()
.listen(NamedPipeListener::new(r"\\.\pipe\agent".into())?)
.listen(Listener::bind(socket)?)
.await?;
Ok(())
}
5 changes: 3 additions & 2 deletions src/agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ pub struct NamedPipeListener(NamedPipeServer, std::ffi::OsString);

#[cfg(windows)]
impl NamedPipeListener {
pub fn new(pipe: std::ffi::OsString) -> std::io::Result<Self> {
pub fn bind(pipe: impl Into<std::ffi::OsString>) -> std::io::Result<Self> {
let pipe = pipe.into();
Ok(NamedPipeListener(
ServerOptions::new()
.first_pipe_instance(true)
Expand Down Expand Up @@ -185,7 +186,7 @@ pub trait Agent: 'static + Sync + Send + Sized {
}
#[cfg(windows)]
service_binding::Listener::NamedPipe(pipe) => {
self.listen(NamedPipeListener::new(pipe)?).await
self.listen(NamedPipeListener::bind(pipe)?).await
}
#[cfg(not(windows))]
service_binding::Listener::NamedPipe(_) => Err(AgentError::IO(std::io::Error::other(
Expand Down
Loading