pub trait ListeningSocket {
type Stream: Debug + AsyncRead + AsyncWrite + Send + Unpin + 'static;
// Required method
fn accept<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = Result<Self::Stream>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
}
Expand description
Type representing a socket that asynchronously returns a list of streams.
This trait is implemented for TCP sockets on all platforms, Unix sockets on Unix platforms (e.g. Linux, macOS) and Named Pipes on Windows.
Objects implementing this trait are passed to the listen
function.
§Examples
The following example starts listening for connections and
processes them with the MyAgent
struct.
use ssh_agent_lib::agent::{listen, Session};
use tokio::net::TcpListener;
#[derive(Default, Clone)]
struct MyAgent;
impl Session for MyAgent {
// implement your agent logic here
}
listen(
TcpListener::bind("127.0.0.1:8080").await?,
MyAgent::default(),
)
.await?;