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