2018-03-15 03:38:59 +11:00
|
|
|
use super::TcpListener;
|
|
|
|
|
use super::TcpStream;
|
2019-07-15 23:13:54 +05:30
|
|
|
use futures_core::ready;
|
2019-06-24 12:34:30 -07:00
|
|
|
use futures_core::stream::Stream;
|
2019-02-21 11:56:15 -08:00
|
|
|
use std::io;
|
2019-06-24 12:34:30 -07:00
|
|
|
use std::pin::Pin;
|
|
|
|
|
use std::task::{Context, Poll};
|
2018-03-05 23:44:09 +03:00
|
|
|
|
|
|
|
|
/// Stream returned by the `TcpListener::incoming` function representing the
|
|
|
|
|
/// stream of sockets received from a listener.
|
|
|
|
|
#[must_use = "streams do nothing unless polled"]
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
|
pub struct Incoming {
|
|
|
|
|
inner: TcpListener,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Incoming {
|
|
|
|
|
pub(crate) fn new(listener: TcpListener) -> Incoming {
|
|
|
|
|
Incoming { inner: listener }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Stream for Incoming {
|
2019-06-24 12:34:30 -07:00
|
|
|
type Item = io::Result<TcpStream>;
|
2018-03-05 23:44:09 +03:00
|
|
|
|
2019-06-24 12:34:30 -07:00
|
|
|
fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
|
|
|
|
|
let (socket, _) = ready!(self.inner.poll_accept(cx))?;
|
|
|
|
|
Poll::Ready(Some(Ok(socket)))
|
2018-03-05 23:44:09 +03:00
|
|
|
}
|
|
|
|
|
}
|