about summary refs log tree commit diff
path: root/src/libstd/rt
diff options
context:
space:
mode:
authorEric Reed <ecreed@cs.washington.edu>2013-09-05 16:49:38 -0700
committerEric Reed <ecreed@cs.washington.edu>2013-09-06 05:30:41 -0700
commit8f0721bcb86c0aa236991118d65639cc4f2f8ea4 (patch)
tree3fb0af4ec5de8c02760d1148a77c67ccac68b16a /src/libstd/rt
parented695d470bf1568b896f2944815f4723905ab66e (diff)
downloadrust-8f0721bcb86c0aa236991118d65639cc4f2f8ea4.tar.gz
rust-8f0721bcb86c0aa236991118d65639cc4f2f8ea4.zip
Fix Acceptor iterator ending early if a connection attempt fails
Diffstat (limited to 'src/libstd/rt')
-rw-r--r--src/libstd/rt/io/mod.rs13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/libstd/rt/io/mod.rs b/src/libstd/rt/io/mod.rs
index 5ceea877453..37c53de09e6 100644
--- a/src/libstd/rt/io/mod.rs
+++ b/src/libstd/rt/io/mod.rs
@@ -493,7 +493,7 @@ pub trait Acceptor<T> {
     /// then `accept` returns `None`.
     fn accept(&mut self) -> Option<T>;
 
-    /// Create an iterator over incoming connections
+    /// Create an iterator over incoming connection attempts
     fn incoming<'r>(&'r mut self) -> IncomingIterator<'r, Self> {
         IncomingIterator { inc: self }
     }
@@ -501,13 +501,18 @@ pub trait Acceptor<T> {
 
 /// An infinite iterator over incoming connection attempts.
 /// Calling `next` will block the task until a connection is attempted.
+///
+/// Since connection attempts can continue forever, this iterator always returns Some.
+/// The Some contains another Option representing whether the connection attempt was succesful.
+/// A successful connection will be wrapped in Some.
+/// A failed connection is represented as a None and raises a condition.
 struct IncomingIterator<'self, A> {
     priv inc: &'self mut A,
 }
 
-impl<'self, T, A: Acceptor<T>> Iterator<T> for IncomingIterator<'self, A> {
-    fn next(&mut self) -> Option<T> {
-        self.inc.accept()
+impl<'self, T, A: Acceptor<T>> Iterator<Option<T>> for IncomingIterator<'self, A> {
+    fn next(&mut self) -> Option<Option<T>> {
+        Some(self.inc.accept())
     }
 }