Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions protosocket-connection/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,12 +378,21 @@ impl<
// 16 is the lowest I've seen mention of, and I've seen 1024 more commonly.
const UIO_MAXIOV: usize = 256;

let buffers: Vec<IoSlice> = self
.send_buffer
.iter()
.take(UIO_MAXIOV)
.map(|v| IoSlice::new(v.chunk()))
.collect();
// Use chunks_vectored rather than chunk() to correctly handle
// Buf implementations that aren't backed by a single contiguous slice.
let mut buffers = vec![IoSlice::new(&[]); UIO_MAXIOV];
let mut filled = 0;
for buf in self.send_buffer.iter() {
if UIO_MAXIOV <= filled {
break;
}
let n = buf.chunks_vectored(&mut buffers[filled..]);
if n == 0 {
break;
}
filled += n;
}
buffers.truncate(filled);

#[cfg(feature = "tracing")]
let span = tracing::span!(tracing::Level::INFO, "writing", buffers = buffers.len());
Expand Down