tls_listener/
net.rs

1use super::{AsyncAccept, AsyncListener};
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_attr(docsrs, doc(cfg(feature = "tokio-net")))]
28impl AsyncListener for TcpListener {
29    #[inline]
30    fn local_addr(&self) -> Result<Self::Address, Self::Error> {
31        TcpListener::local_addr(self)
32    }
33}
34
35#[cfg(unix)]
36#[cfg_attr(docsrs, doc(cfg(feature = "tokio-net")))]
37impl AsyncAccept for UnixListener {
38    type Connection = UnixStream;
39    type Error = io::Error;
40    type Address = tokio::net::unix::SocketAddr;
41
42    fn poll_accept(
43        self: Pin<&mut Self>,
44        cx: &mut Context<'_>,
45    ) -> Poll<Result<(Self::Connection, Self::Address), Self::Error>> {
46        match (*self).poll_accept(cx) {
47            Poll::Ready(Ok(conn)) => Poll::Ready(Ok(conn)),
48            Poll::Ready(Err(e)) => Poll::Ready(Err(e)),
49            Poll::Pending => Poll::Pending,
50        }
51    }
52}
53
54#[cfg(unix)]
55#[cfg_attr(docsrs, doc(cfg(feature = "tokio-net")))]
56impl AsyncListener for UnixListener {
57    #[inline]
58    fn local_addr(&self) -> Result<Self::Address, Self::Error> {
59        UnixListener::local_addr(self)
60    }
61}