From 8850c95155196a9941bd27b920bad24be0f43d01 Mon Sep 17 00:00:00 2001 From: Astro Date: Wed, 19 Jul 2017 01:32:53 +0200 Subject: [PATCH] happy_eyeballs: don't retain errored connects --- src/happy_eyeballs.rs | 30 ++++++++++++++++++++++-------- src/stream_start.rs | 2 +- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/happy_eyeballs.rs b/src/happy_eyeballs.rs index f529a87..3cd42f4 100644 --- a/src/happy_eyeballs.rs +++ b/src/happy_eyeballs.rs @@ -80,15 +80,29 @@ impl Future for Connecter { return Err(format!("{}", e)), } - for mut connect in self.connects.values_mut() { - match connect.poll() { - Ok(Async::NotReady) => (), - Ok(Async::Ready(tcp_stream)) => - // Success! - return Ok(Async::Ready(tcp_stream)), - Err(e) => - println!("{}", e), + let mut connected_stream = None; + self.connects.retain(|_, connect| { + if connected_stream.is_some() { + return false; } + + match connect.poll() { + Ok(Async::NotReady) => true, + Ok(Async::Ready(tcp_stream)) => { + // Success! + connected_stream = Some(tcp_stream); + false + }, + Err(e) => { + println!("{}", e); + false + }, + } + }); + match connected_stream { + Some(tcp_stream) => + return Ok(Async::Ready(tcp_stream)), + None => (), } if self.lookup.is_none() && diff --git a/src/stream_start.rs b/src/stream_start.rs index b194b5b..4d79d4d 100644 --- a/src/stream_start.rs +++ b/src/stream_start.rs @@ -89,7 +89,7 @@ impl Future for StreamStart { } else { (StreamStartState::RecvFeatures(stream, stream_ns), Ok(Async::NotReady)) }, - Ok(Async::Ready(item)) => + Ok(Async::Ready(_)) => (StreamStartState::RecvFeatures(stream, stream_ns), Ok(Async::NotReady)), Ok(Async::NotReady) => (StreamStartState::RecvFeatures(stream, stream_ns), Ok(Async::NotReady)),