From 78810d06a289b91e51f100868ff37c359627f99f Mon Sep 17 00:00:00 2001 From: folex <0xdxdy@gmail.com> Date: Mon, 30 Mar 2020 20:31:56 +0300 Subject: [PATCH] Revert "[libp2p-swarm] Correct returned connections from notify_all. (#1513)" This reverts commit 28ea62d1 --- swarm/src/lib.rs | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/swarm/src/lib.rs b/swarm/src/lib.rs index 6e92aab793ba..2af0ca5d2151 100644 --- a/swarm/src/lib.rs +++ b/swarm/src/lib.rs @@ -681,9 +681,9 @@ where /// Notify all of the given connections of a peer of an event. /// /// Returns `Some` with the given event and a new list of connections if -/// at least one of the given connections is currently not able to receive -/// the event, in which case the current task is scheduled to be woken up and -/// the returned connections are those which still need to receive the event. +/// at least one of the given connections is not currently able to receive the event +/// but is not closing, in which case the current task is scheduled to be woken up. +/// The returned connections are those which are not closing. /// /// Returns `None` if all connections are either closing or the event /// was successfully sent to all handlers whose connections are not closing, @@ -707,23 +707,26 @@ where } } - let mut pending = SmallVec::new(); - for id in ids.into_iter() { - if let Some(mut conn) = peer.connection(id) { - match conn.poll_ready_notify_handler(cx) { - Poll::Pending => pending.push(id), - Poll::Ready(Ok(())) => { - // Can now only fail due to the connection suddenly closing, - // which we ignore. - let _ = conn.notify_handler(event.clone()); - }, - Poll::Ready(Err(())) => {} // connection is closing + { + let mut pending = SmallVec::new(); + for id in ids.iter() { + if let Some(mut conn) = peer.connection(*id) { // (*) + if conn.poll_ready_notify_handler(cx).is_pending() { + pending.push(*id) + } } } + if !pending.is_empty() { + return Some((event, pending)) + } } - if !pending.is_empty() { - return Some((event, pending)) + for id in ids.into_iter() { + if let Some(mut conn) = peer.connection(id) { + // All connections were ready. Can now only fail due + // to a connection suddenly closing, which we ignore. + let _ = conn.notify_handler(event.clone()); + } } None