-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Re-constituting splitstreams now works
- Loading branch information
1 parent
da5422e
commit 77c0d4b
Showing
4 changed files
with
134 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,39 @@ | ||
use std::os::fd::{ | ||
AsFd, | ||
AsRawFd, | ||
use std::{ | ||
io::Read, | ||
os::fd::{ | ||
AsFd, | ||
AsRawFd, | ||
}, | ||
}; | ||
|
||
use anyhow::Result; | ||
|
||
pub fn proc_self_fd<A: AsFd>(fd: &A) -> String { | ||
format!("/proc/self/fd/{}", fd.as_fd().as_raw_fd()) | ||
} | ||
|
||
// we can't use Read::read_exact() because we need to be able to detect EOF | ||
pub fn read_exactish<R: Read>(reader: &mut R, buf: &mut [u8]) -> Result<bool> { | ||
let buflen = buf.len(); | ||
let mut todo: &mut [u8] = buf; | ||
|
||
while !todo.is_empty() { | ||
match reader.read(todo) { | ||
Ok(0) => match todo.len() { | ||
s if s == buflen => return Ok(false), // clean EOF | ||
_ => Err(std::io::Error::from(std::io::ErrorKind::UnexpectedEof))? | ||
}, | ||
Ok(n) => { | ||
todo = &mut todo[n..]; | ||
} | ||
Err(e) if e.kind() == std::io::ErrorKind::Interrupted => { | ||
continue; | ||
} | ||
Err(e) => { | ||
Err(e)?; | ||
} | ||
} | ||
} | ||
|
||
Ok(true) | ||
} |