Trait ListeningSocket

Source
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?;

Required Associated Types§

Source

type Stream: Debug + AsyncRead + AsyncWrite + Send + Unpin + 'static

Stream type that represents an accepted socket.

Required Methods§

Source

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,

Waits until a client connects and returns connected stream.

Implementations on Foreign Types§

Source§

impl ListeningSocket for TcpListener

Source§

type Stream = TcpStream

Source§

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,

Source§

impl ListeningSocket for UnixListener

Source§

type Stream = UnixStream

Source§

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,

Implementors§