Keep bytes in case of incomplete read
Currently, cahute_read_from_link
does not report the number of bytes actually received in case of incomplete read due to any error (timeout, gone, etc). However, that means in this case that the medium stream is instantly corrupted and not resumable, since we may have stopped in the middle of a packet and may not be able to re-align ourselves.
Not allowing partial reads was actually a conscious design decision in the project, one that I've kept from libcasio / libtio, as it simplifies protocol implementation with conditional sizes and whatnot. However, maybe in such cases, we could actually keep the incomplete read in the medium read buffer if possible, so that the protocol could attempt at calling cahute_read_from_link
with a smaller buffer size later and still get those bytes so that protocol state can be recovered.
However, that does not work for big reads (incomplete read size > medium read buffer size), and maybe we actually don't wish to do this, as a CAHUTE_ERROR_TIMEOUT
(in-between bytes of a read or before last byte) means that the device is either too slow or disconnected, and that the link may not be useful anymore anyway?