Skip to content

Commit

Permalink
Add else condition for writing as much into buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
KolbyML committed May 24, 2023
1 parent a2b619d commit fe13782
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/conn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -456,12 +456,17 @@ impl<const N: usize, P: ConnectionPeer> Connection<N, P> {

// 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].to_vec()).unwrap();
let _ = tx.send(Ok(available));
self.writable.notify_one();
break;
}
}
Expand Down

0 comments on commit fe13782

Please sign in to comment.