From 9881c67680c1785f7701043b23bac83f359a139e Mon Sep 17 00:00:00 2001 From: Emilia Hane Date: Sun, 28 May 2023 17:15:29 +0200 Subject: [PATCH 1/3] Remove redundant call in same thread --- src/conn.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/conn.rs b/src/conn.rs index a90fd8e..5ae9314 100644 --- a/src/conn.rs +++ b/src/conn.rs @@ -454,18 +454,23 @@ impl Connection { window -= n; } + let mut wrote_data = false; // Write as much data as possible into send buffer. while let Some((data, ..)) = self.pending_writes.front() { if data.len() <= send_buf.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(); + wrote_data = true; } else { break; } } + if wrote_data { + self.writable.notify_one(); + } + // Transmit data packets. // TODO: Helper for construction of DATA packet. let mut seq_num = sent_packets.next_seq_num(); From 637e8ccc7f016248c2104653e13df063d421b183 Mon Sep 17 00:00:00 2001 From: Emilia Hane Date: Sun, 28 May 2023 17:22:48 +0200 Subject: [PATCH 2/3] fixup! Remove redundant call in same thread --- src/conn.rs | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/conn.rs b/src/conn.rs index 5ae9314..89f169d 100644 --- a/src/conn.rs +++ b/src/conn.rs @@ -471,6 +471,29 @@ impl Connection { self.writable.notify_one(); } + let mut wrote_data = false; + // Write as much data as possible into send buffer. + while send_buf.available() > 0 { + let Some((data, tx)) = self.pending_writes.pop_front() else { + break; + }; + let written = send_buf.write(&data).unwrap(); + if written < data.len() { + // not all data fit in the send buffer, chunk data + let mut data = data; + let remaining = data.split_off(send_buf.available()); + tracing::trace!("remaining len {}", remaining.len()); + self.pending_writes.push_front((remaining, tx)); + } else { + let _ = tx.send(Ok(data.len())); + } + wrote_data = true; + } + + if wrote_data { + self.writable.notify_one(); + } + // Transmit data packets. // TODO: Helper for construction of DATA packet. let mut seq_num = sent_packets.next_seq_num(); @@ -530,8 +553,6 @@ impl Connection { } self.process_writes(Instant::now()); - - self.writable.notify_waiters(); } fn process_reads(&mut self) { From 6a163d750f37762c1fe678ac4fcd37173b3bba93 Mon Sep 17 00:00:00 2001 From: Emilia Hane Date: Sun, 28 May 2023 17:29:03 +0200 Subject: [PATCH 3/3] Remove code from experimental branch --- src/conn.rs | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/src/conn.rs b/src/conn.rs index 89f169d..52cf5e1 100644 --- a/src/conn.rs +++ b/src/conn.rs @@ -471,29 +471,6 @@ impl Connection { self.writable.notify_one(); } - let mut wrote_data = false; - // Write as much data as possible into send buffer. - while send_buf.available() > 0 { - let Some((data, tx)) = self.pending_writes.pop_front() else { - break; - }; - let written = send_buf.write(&data).unwrap(); - if written < data.len() { - // not all data fit in the send buffer, chunk data - let mut data = data; - let remaining = data.split_off(send_buf.available()); - tracing::trace!("remaining len {}", remaining.len()); - self.pending_writes.push_front((remaining, tx)); - } else { - let _ = tx.send(Ok(data.len())); - } - wrote_data = true; - } - - if wrote_data { - self.writable.notify_one(); - } - // Transmit data packets. // TODO: Helper for construction of DATA packet. let mut seq_num = sent_packets.next_seq_num();