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
use super::TcpListener;
use super::TcpStream;
use futures::stream::Stream;
use futures::{Async, Poll};
use std::io;
#[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 = TcpStream;
type Error = io::Error;
fn poll(&mut self) -> Poll<Option<Self::Item>, io::Error> {
let (socket, _) = try_ready!(self.inner.poll_accept());
Ok(Async::Ready(Some(socket)))
}
}