mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-25 00:00:18 +02:00
31 lines
802 B
Rust
31 lines
802 B
Rust
use super::TcpListener;
|
|
use super::TcpStream;
|
|
use futures_core::ready;
|
|
use futures_core::stream::Stream;
|
|
use std::io;
|
|
use std::pin::Pin;
|
|
use std::task::{Context, Poll};
|
|
|
|
/// 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 {
|
|
type Item = io::Result<TcpStream>;
|
|
|
|
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)))
|
|
}
|
|
}
|