From f4cd46b4065be839db11487295ac0b9db9f721b1 Mon Sep 17 00:00:00 2001 From: Kolby Moroz Liebl <31669092+KolbyML@users.noreply.github.com> Date: Wed, 24 May 2023 11:24:57 -0600 Subject: [PATCH] Add else condition for writing as much into buffer --- src/conn.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/conn.rs b/src/conn.rs index a90fd8e..99af28c 100644 --- a/src/conn.rs +++ b/src/conn.rs @@ -456,12 +456,17 @@ impl Connection { // Write as much data as possible into send buffer. while let Some((data, ..)) = self.pending_writes.front() { - if data.len() <= send_buf.available() { + let available = send_buf.available(); + if data.len() <= available { let (data, tx) = self.pending_writes.pop_front().unwrap(); send_buf.write(&data).unwrap(); let _ = tx.send(Ok(data.len())); self.writable.notify_one(); } else { + let (data, tx) = self.pending_writes.pop_front().unwrap(); + send_buf.write(&data[..available]).unwrap(); + let _ = tx.send(Ok(available)); + self.writable.notify_one(); break; } }