diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
commit | 2aa4a82499d4becd2284cdb482213d541b8804dd (patch) | |
tree | b80bf8bf13c3766139fbacc530efd0dd9d54394c /third_party/rust/tokio-tcp/src/incoming.rs | |
parent | Initial commit. (diff) | |
download | firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.tar.xz firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.zip |
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/rust/tokio-tcp/src/incoming.rs')
-rw-r--r-- | third_party/rust/tokio-tcp/src/incoming.rs | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/third_party/rust/tokio-tcp/src/incoming.rs b/third_party/rust/tokio-tcp/src/incoming.rs new file mode 100644 index 0000000000..6726224b82 --- /dev/null +++ b/third_party/rust/tokio-tcp/src/incoming.rs @@ -0,0 +1,45 @@ +use super::TcpListener; +use super::TcpStream; + +use std::io; +use futures::stream::Stream; +use futures::{Poll, Async}; + +#[cfg(feature = "unstable-futures")] +use futures2; + +/// 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 = 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))) + } +} + +#[cfg(feature = "unstable-futures")] +impl futures2::Stream for Incoming { + type Item = TcpStream; + type Error = io::Error; + + fn poll_next(&mut self, cx: &mut futures2::task::Context) + -> futures2::Poll<Option<Self::Item>, io::Error> + { + Ok(self.inner.poll_accept2(cx)?.map(|(sock, _)| Some(sock))) + } +} |