tls_listener/
net.rs

1use super::AsyncAccept;
2use std::io;
3use std::pin::Pin;
4use std::task::{Context, Poll};
5use tokio::net::{TcpListener, TcpStream};
6#[cfg(unix)]
7use tokio::net::{UnixListener, UnixStream};
8
9#[cfg_attr(docsrs, doc(cfg(feature = "tokio-net")))]
10impl AsyncAccept for TcpListener {
11    type Connection = TcpStream;
12    type Error = io::Error;
13    type Address = std::net::SocketAddr;
14
15    fn poll_accept(
16        self: Pin<&mut Self>,
17        cx: &mut Context<'_>,
18    ) -> Poll<Result<(Self::Connection, Self::Address), Self::Error>> {
19        match (*self).poll_accept(cx) {
20            Poll::Ready(Ok(conn)) => Poll::Ready(Ok(conn)),
21            Poll::Ready(Err(e)) => Poll::Ready(Err(e)),
22            Poll::Pending => Poll::Pending,
23        }
24    }
25}
26
27#[cfg(unix)]
28#[cfg_attr(docsrs, doc(cfg(feature = "tokio-net")))]
29impl AsyncAccept for UnixListener {
30    type Connection = UnixStream;
31    type Error = io::Error;
32    type Address = tokio::net::unix::SocketAddr;
33
34    fn poll_accept(
35        self: Pin<&mut Self>,
36        cx: &mut Context<'_>,
37    ) -> Poll<Result<(Self::Connection, Self::Address), Self::Error>> {
38        match (*self).poll_accept(cx) {
39            Poll::Ready(Ok(conn)) => Poll::Ready(Ok(conn)),
40            Poll::Ready(Err(e)) => Poll::Ready(Err(e)),
41            Poll::Pending => Poll::Pending,
42        }
43    }
44}