Skip to content

Commit

Permalink
Fix Acceptor iterator ending early if a connection attempt fails
Browse files Browse the repository at this point in the history
  • Loading branch information
anasazi committed Sep 6, 2013
1 parent ed695d4 commit 8f0721b
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/libstd/rt/io/mod.rs
Expand Up @@ -493,21 +493,26 @@ 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 }
}
}

/// 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())
}
}

Expand Down

5 comments on commit 8f0721b

@bors
Copy link
Contributor

@bors bors commented on 8f0721b Sep 9, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from cmr
at anasazi@8f0721b

@bors
Copy link
Contributor

@bors bors commented on 8f0721b Sep 9, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging anasazi/rust/fix-acceptor-iterator = 8f0721b into auto

@bors
Copy link
Contributor

@bors bors commented on 8f0721b Sep 9, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

anasazi/rust/fix-acceptor-iterator = 8f0721b merged ok, testing candidate = d41b558

@bors
Copy link
Contributor

@bors bors commented on 8f0721b Sep 10, 2013

@bors
Copy link
Contributor

@bors bors commented on 8f0721b Sep 10, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = d41b558

Please sign in to comment.