Skip to content

Commit 5a14d53

Browse files
committed
Fix: Ensure full write with vectored io
also bump deps
1 parent 05c1c7f commit 5a14d53

3 files changed

Lines changed: 61 additions & 30 deletions

File tree

Cargo.lock

Lines changed: 35 additions & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ serde = { version = "^1", features = ["derive"] }
2020
serde_json = "^1"
2121
supershorty = "^0.2"
2222
thiserror = "^2"
23-
toml = "^0.9"
23+
toml = "^1"
2424
twox-hash = { version = "^2", default-features = false, features = [
2525
"std",
2626
"xxhash3_64",

src/ipc.rs

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::{
22
ffi::OsStr,
33
fs::{self, Permissions},
4-
io::{Error, ErrorKind, IoSlice, Read as _, Result, Write as _},
4+
io::{Error, ErrorKind, IoSlice, Read as _, Result, Write},
55
os::{
66
fd::{AsFd, BorrowedFd},
77
unix::{
@@ -170,13 +170,13 @@ impl Client {
170170
};
171171
let packed_len_buf = packed_len.as_bytes();
172172

173-
let io_slice = &[
173+
let mut io_slice = [
174174
IoSlice::new(&amount_buf),
175175
IoSlice::new(&packed_len_buf),
176176
IoSlice::new(bytes),
177177
];
178178

179-
_ = stream.write_vectored(io_slice)?;
179+
write_all_vectored(&mut stream, &mut io_slice)?;
180180

181181
Ok(Self(stream))
182182
}
@@ -207,6 +207,28 @@ impl Client {
207207
}
208208
}
209209

210+
// FIXME: remove this after `Write::write_all_vectored` stablize
211+
// https://doc.rust-lang.org/1.93.1/src/std/io/mod.rs.html#1937-1952
212+
fn write_all_vectored<W: Write>(write: &mut W, mut bufs: &mut [IoSlice<'_>]) -> Result<()> {
213+
// Guarantee that bufs is empty if it contains no data,
214+
// to avoid calling write_vectored if there is no data to be written.
215+
IoSlice::advance_slices(&mut bufs, 0);
216+
while !bufs.is_empty() {
217+
match write.write_vectored(bufs) {
218+
Ok(0) => {
219+
return Err(Error::new(
220+
ErrorKind::WriteZero,
221+
"failed to write whole buffer",
222+
));
223+
}
224+
Ok(n) => IoSlice::advance_slices(&mut bufs, n),
225+
Err(e) if e.kind() == ErrorKind::Interrupted => {}
226+
Err(e) => return Err(e),
227+
}
228+
}
229+
Ok(())
230+
}
231+
210232
#[cfg(test)]
211233
mod tests {
212234
use std::{

0 commit comments

Comments
 (0)