serialqueue: correctly report EOF errors

If `klippy` loses connection to a device, the next `read()` from the
device file descriptor will result in a zero-byte result, i.e. an `EOF`.
Right now this gives a confusing error message, so this simply handles
the special case of `EOF` and outputs a better log message.

Signed-off-by: Lasse Dalegaard <dalegaard@gmail.com>
This commit is contained in:
Lasse Dalegaard 2021-02-27 10:56:14 +00:00 committed by KevinOConnor
parent 70a1b752c9
commit f8b0ea53dc
1 changed files with 4 additions and 1 deletions

View File

@ -573,7 +573,10 @@ input_event(struct serialqueue *sq, double eventtime)
int ret = read(sq->serial_fd, &sq->input_buf[sq->input_pos] int ret = read(sq->serial_fd, &sq->input_buf[sq->input_pos]
, sizeof(sq->input_buf) - sq->input_pos); , sizeof(sq->input_buf) - sq->input_pos);
if (ret <= 0) { if (ret <= 0) {
report_errno("read", ret); if(ret < 0)
report_errno("read", ret);
else
errorf("Got EOF when reading from device");
pollreactor_do_exit(&sq->pr); pollreactor_do_exit(&sq->pr);
return; return;
} }