Repository navigation
Conversation
9fbe0a5 to
26cd179
Compare
26cd179 to
da00842
Compare
| while !buf.is_empty() { | ||
| match self.read(buf) { | ||
| Ok(0) => return Err(Error::UnexpectedEof), | ||
| Ok(n) => buf = &mut core::mem::take(&mut buf)[n..], |
There was a problem hiding this comment.
Can't you just do buf = &buf[n..]?
There was a problem hiding this comment.
yes, indeed that's better. thanks
|
|
||
| while !buf.is_empty() { | ||
| match self.write(buf) { | ||
| Ok(0) => return Err(Error::WriteZero), |
There was a problem hiding this comment.
Some data may have been written in the previous call to write. That's a bit confusing. Can we turn this into a WRITE_ALL_EOF so it matches https://doc.rust-lang.org/src/core/io/write.rs.html#214. Eventually we'll use that implementation anyway.
There was a problem hiding this comment.
yes I can do that, but note that WRITE_ALL_EOF in io is still mapped to ErrorKind::WriteZero: https://doc.rust-lang.org/src/core/io/error.rs.html#125
So in our impl From<Error> for io::Error I will have to do something like this:
#[cfg(feature="std")]
impl From<Error> for io::Error {
fn from(err: Error) -> io::Error {
match err {
// ...
Error::WriteAllEof => io::Error::new(ErrorKind::WriteZero, err),
}
}
}| pub fn read_exact(&self, mut buf: &mut [u8]) -> Result<(), Error> { | ||
| while !buf.is_empty() { | ||
| match self.read(buf) { | ||
| Ok(0) => return Err(Error::UnexpectedEof), |
There was a problem hiding this comment.
There's a similar issue with signals. See https://doc.rust-lang.org/src/alloc/io/read.rs.html#1037
There was a problem hiding this comment.
ok, now our read_exact implementation matches that one.
da00842 to
b128d59
Compare
This PR improves read/write functions in the following way:
read_exactfunction, required for theenclave-runner-clientcrate. This function is basically the same asread_allbut it does not return the number of bytes read. This mirrorsread_exactinstd::io.#[cfg(not(feature="std"))]onwrite_allandread_all. In the client, we don't rely onstd::io::Read/Writetraits, but we use these functions for both std and non-std compilation.EINTRerrors by retrying the read/write operationUnexpectedEofandWriteZeroerrors when reading or writing 0 bytes respectively (this also fixed infinite recursion inread_all)