1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#![cfg(feature = "async-traits")]
use super::{UnixListener, UnixStream};
use futures_core::ready;
use futures_core::stream::Stream;
use std::io;
use std::pin::Pin;
use std::task::{Context, Poll};
#[derive(Debug)]
#[must_use = "streams do nothing unless polled"]
pub struct Incoming {
inner: UnixListener,
}
impl Incoming {
pub(crate) fn new(listener: UnixListener) -> Incoming {
Incoming { inner: listener }
}
}
impl Stream for Incoming {
type Item = io::Result<UnixStream>;
fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
let (socket, _) = ready!(Pin::new(&mut self.inner).poll_accept(cx))?;
Poll::Ready(Some(Ok(socket)))
}
}