esp-rs / esp-mbedtls

mbedtls for ESP32 bare-metal
Apache License 2.0
21 stars 10 forks source link

`read()` returns `Ok(0)` if there's no data #16

Closed AnthonyGrondin closed 1 year ago

AnthonyGrondin commented 1 year ago

This is an issue similar as https://github.com/esp-rs/esp-wifi/pull/216 where Ok(0) is returned from read() if there's no data.

This causes issues when trying to use the read() impl from inside other crates, since it might interpret Ok(0) as an EOF. This is what happens initially during a request handshake.

This forces the use of something like:

loop {
    match tls.read(&mut temp_buffer).await {
        Ok(0) => continue,
        Ok(_) => break,
        Err(TlsError::Eof) => {
            log::error!("EOF");
            break;
        }
        Err(e) => {
            log::error!("Read Error {:?}", e);
            break;
        }
    };
}

and then use this temporary buffer for the other crates.

For example, trying to use the current read() impl inside https://github.com/drogue-iot/reqwless/blob/f23567d8d178dd837332b503fe983ba4931d8b40/src/response.rs#L47-L58 will result in no data being read.

bjoernQ commented 1 year ago

True, both the blocking and the async embedded-io read should only return Ok(0) on EOF. We need to change that