Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 3 additions & 1 deletion .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ name: PR

on:
pull_request:
branches: [ main ]
types:
- opened
- reopened

env:
CARGO_TERM_COLOR: always
Expand Down
25 changes: 17 additions & 8 deletions protosocket-connection/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,18 +378,27 @@ 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 stack_buffers = [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 stack_buffers[filled..]);
if n == 0 {
break;
}
filled += n;
}
let buffers = &stack_buffers[..filled];

#[cfg(feature = "tracing")]
let span = tracing::span!(tracing::Level::INFO, "writing", buffers = buffers.len());
#[cfg(feature = "tracing")]
let span_guard = span.enter();
let poll = pin!(&mut self.stream).poll_write_vectored(context, &buffers);
let poll = pin!(&mut self.stream).poll_write_vectored(context, buffers);
#[cfg(feature = "tracing")]
drop(span_guard);
match poll {
Expand Down Expand Up @@ -423,7 +432,7 @@ impl<
"error while writing to tcp stream: {err:?}, buffers: {}, {}b: {:?}",
buffers.len(),
buffers.iter().map(|b| b.len()).sum::<usize>(),
buffers.into_iter().map(|b| b.len()).collect::<Vec<_>>()
buffers.iter().map(|b| b.len()).collect::<Vec<_>>()
);
Err(err)
}
Expand Down