rust-embedded / embedded-hal

A Hardware Abstraction Layer (HAL) for embedded systems
Apache License 2.0
1.87k stars 188 forks source link

honor `ErrorKind::Interrupted` in `write_all()`? #611

Open rmja opened 3 days ago

rmja commented 3 days ago

Currently in write_all() (https://github.com/rust-embedded/embedded-hal/blob/master/embedded-io-async/src/lib.rs#L134) we do not retry if the return error has kind() == ErrorKind::Interrupted. This is different than std: https://doc.rust-lang.org/src/std/io/mod.rs.html#1696-1708.

Should ErrorKind::Interrupted lead to a silent retry in write_all()?

eldruin commented 3 days ago

Interesting question. I would ask then how often should it retry. Either we create an endless loop or we define an arbitrary number which will be difficult to agree upon. Given the general character or e-io-async, I think the caller is better positioned to put a loop on the call in this case.

Dirbaio commented 3 days ago

ErrorKind::Interrupted is annoying unix legacy-ish. I don't think anyone uses it intentionally anymore, especially now that async exists? it doesn't really exist on embedded, and i'd say it shouldn't exist.

So perhaps another option is to make embedded_io_adapters::FromStd do the retry on the write() method, so we keep Interrupted errors to the boundary of embedded-io instead of letting them in?

rmja commented 3 days ago

That sounds like a really good idea. Should we then also remove ErrorKind::Interrupted?

Dirbaio commented 3 days ago

probably, yes...