Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 12 additions & 15 deletions quiche/src/stream/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -816,44 +816,41 @@ impl PartialEq for StreamPriorityKey {
impl Eq for StreamPriorityKey {}

impl PartialOrd for StreamPriorityKey {
// Priority ordering is complex, disable Clippy warning.
#[allow(clippy::non_canonical_partial_ord_impl)]
fn partial_cmp(&self, other: &Self) -> Option<cmp::Ordering> {
Some(self.cmp(other))
}
}

impl Ord for StreamPriorityKey {
fn cmp(&self, other: &Self) -> cmp::Ordering {
// Ignore priority if ID matches.
if self.id == other.id {
return Some(cmp::Ordering::Equal);
return cmp::Ordering::Equal;
}

// First, order by urgency...
if self.urgency != other.urgency {
return self.urgency.partial_cmp(&other.urgency);
return self.urgency.cmp(&other.urgency);
}

// ...when the urgency is the same, and both are not incremental, order
// by stream ID...
if !self.incremental && !other.incremental {
return self.id.partial_cmp(&other.id);
return self.id.cmp(&other.id);
}

// ...non-incremental takes priority over incremental...
if self.incremental && !other.incremental {
return Some(cmp::Ordering::Greater);
return cmp::Ordering::Greater;
}
if !self.incremental && other.incremental {
return Some(cmp::Ordering::Less);
return cmp::Ordering::Less;
}

// ...finally, when both are incremental, `other` takes precedence (so
// `self` is always sorted after other same-urgency incremental
// entries).
Some(cmp::Ordering::Greater)
}
}

impl Ord for StreamPriorityKey {
fn cmp(&self, other: &Self) -> cmp::Ordering {
// `partial_cmp()` never returns `None`, so this should be safe.
self.partial_cmp(other).unwrap()
cmp::Ordering::Greater
}
}

Expand Down
15 changes: 6 additions & 9 deletions quiche/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2928,15 +2928,12 @@ fn stream_shutdown_read(
let frames =
test_utils::decode_pkt(&mut pipe.client, &mut dummy[..len]).unwrap();
// make sure the pkt contains the expected StopSending frame
assert!(frames
.iter()
.find(|f| {
**f == frame::Frame::StopSending {
stream_id: 4,
error_code: 42,
}
})
.is_some(),);
assert!(frames.iter().any(|f| {
*f == frame::Frame::StopSending {
stream_id: 4,
error_code: 42,
}
}));

assert_eq!(pipe.client_recv(&mut buf[..len]), Ok(len));

Expand Down
3 changes: 1 addition & 2 deletions tokio-quiche/src/quic/io/utilization_estimator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,8 @@ impl PartialEq for Estimate {
impl Eq for Estimate {}

impl PartialOrd for Estimate {
#[allow(clippy::non_canonical_partial_ord_impl)]
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
self.bandwidth.partial_cmp(&other.bandwidth)
Some(self.cmp(other))
}
}

Expand Down