pico_usb_serial: Handle errors of serial.write()

Fixes: #194
This commit is contained in:
Jan Niehusmann 2021-11-26 20:43:02 +00:00 committed by 9names
parent 05e072025d
commit de53600199

View file

@ -116,9 +116,13 @@ fn main() -> ! {
// Send back to the host
let mut wr_ptr = &buf[..count];
while !wr_ptr.is_empty() {
let _ = serial.write(wr_ptr).map(|len| {
wr_ptr = &wr_ptr[len..];
});
match serial.write(wr_ptr) {
Ok(len) => wr_ptr = &wr_ptr[len..],
// On error, just drop unwritten data.
// One possible error is Err(WouldBlock), meaning the USB
// write buffer is full.
Err(_) => break,
};
}
}
}