diff --git a/neqo-transport/src/cc/cubic.rs b/neqo-transport/src/cc/cubic.rs index a158fe791d..998b7a6ed6 100644 --- a/neqo-transport/src/cc/cubic.rs +++ b/neqo-transport/src/cc/cubic.rs @@ -149,16 +149,12 @@ impl WindowAdjustment for Cubic { } }) .as_secs_f64(); - let target_cubic = self.w_cubic(time_ca); + let target_cubic = self.w_cubic(time_ca); let tcp_cnt = self.estimated_tcp_cwnd / CUBIC_ALPHA; - #[allow(unknown_lints)] - #[allow(clippy::while_float)] - while self.tcp_acked_bytes > tcp_cnt { - self.tcp_acked_bytes -= tcp_cnt; - self.estimated_tcp_cwnd += MAX_DATAGRAM_SIZE_F64; - } - + let incr = self.tcp_acked_bytes / tcp_cnt; + self.tcp_acked_bytes -= incr * tcp_cnt; + self.estimated_tcp_cwnd += incr * MAX_DATAGRAM_SIZE_F64; let target_cwnd = target_cubic.max(self.estimated_tcp_cwnd); // Calculate the number of bytes that would need to be acknowledged for an increase diff --git a/neqo-transport/src/cc/tests/cubic.rs b/neqo-transport/src/cc/tests/cubic.rs index ede1b3fadd..9d03da5bec 100644 --- a/neqo-transport/src/cc/tests/cubic.rs +++ b/neqo-transport/src/cc/tests/cubic.rs @@ -174,9 +174,9 @@ fn tcp_phase() { assert!(num_acks2 < expected_ack_tcp_increase2); // The time needed to increase cwnd by MAX_DATAGRAM_SIZE using the cubic equation will be - // calculates from: W_cubic(elapsed_time + t_to_increase) - W_cubis(elapsed_time) = + // calculates from: W_cubic(elapsed_time + t_to_increase) - W_cubic(elapsed_time) = // MAX_DATAGRAM_SIZE => CUBIC_C * (elapsed_time + t_to_increase)^3 * MAX_DATAGRAM_SIZE + - // CWND_INITIAL - CUBIC_C * elapsed_time^3 * MAX_DATAGRAM_SIZE + CWND_INITIAL = + // CWND_INITIAL - CUBIC_C * elapsed_time^3 * MAX_DATAGRAM_SIZE + CWND_INITIAL = // MAX_DATAGRAM_SIZE => t_to_increase = cbrt((1 + CUBIC_C * elapsed_time^3) / CUBIC_C) - // elapsed_time (t_to_increase is in seconds) // number of ack needed is t_to_increase / time_increase. @@ -186,9 +186,9 @@ fn tcp_phase() { / time_increase.as_secs_f64()) .ceil() as u64; // num_acks is very close to the calculated value. The exact value is hard to calculate - // because the proportional increase(i.e. curr_cwnd_f64 / (target - curr_cwnd_f64) * + // because the proportional increase (i.e. curr_cwnd_f64 / (target - curr_cwnd_f64) * // MAX_DATAGRAM_SIZE_F64) and the byte counting. - assert_eq!(num_acks2, expected_ack_cubic_increase + 2); + assert_eq!(num_acks2, expected_ack_cubic_increase + 3); } #[test]