mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-25 00:00:18 +02:00
tokio: update code according to new MSRV (#6764)
This commit is contained in:
@@ -1049,28 +1049,13 @@ impl Builder {
|
||||
}
|
||||
|
||||
fn adjust_max_frame_len(&mut self) {
|
||||
// This function is basically `std::u64::saturating_add_signed`. Since it
|
||||
// requires MSRV 1.66, its implementation is copied here.
|
||||
//
|
||||
// TODO: use the method from std when MSRV becomes >= 1.66
|
||||
fn saturating_add_signed(num: u64, rhs: i64) -> u64 {
|
||||
let (res, overflow) = num.overflowing_add(rhs as u64);
|
||||
if overflow == (rhs < 0) {
|
||||
res
|
||||
} else if overflow {
|
||||
u64::MAX
|
||||
} else {
|
||||
0
|
||||
}
|
||||
}
|
||||
|
||||
// Calculate the maximum number that can be represented using `length_field_len` bytes.
|
||||
let max_number = match 1u64.checked_shl((8 * self.length_field_len) as u32) {
|
||||
Some(shl) => shl - 1,
|
||||
None => u64::MAX,
|
||||
};
|
||||
|
||||
let max_allowed_len = saturating_add_signed(max_number, self.length_adjustment as i64);
|
||||
let max_allowed_len = max_number.saturating_add_signed(self.length_adjustment as i64);
|
||||
|
||||
if self.max_frame_len as u64 > max_allowed_len {
|
||||
self.max_frame_len = usize::try_from(max_allowed_len).unwrap_or(usize::MAX);
|
||||
|
||||
Reference in New Issue
Block a user