mirror of
https://github.com/vsergeev/c-periphery.git
synced 2026-09-24 05:54:03 +08:00
serial: return error on unexpected empty read
fixes vsergeev/lua-periphery#20.
This commit is contained in:
@@ -263,6 +263,10 @@ int serial_read(serial_t *serial, uint8_t *buf, size_t len, int timeout_ms) {
|
||||
if ((ret = read(serial->fd, buf + bytes_read, bytes_left)) < 0)
|
||||
return _serial_error(serial, SERIAL_ERROR_IO, errno, "Reading serial port");
|
||||
|
||||
/* Empty read */
|
||||
if (ret == 0 && len != 0)
|
||||
return _serial_error(serial, SERIAL_ERROR_IO, 0, "Reading serial port: unexpected empty read");
|
||||
|
||||
bytes_read += ret;
|
||||
bytes_left -= ret;
|
||||
} while (bytes_left > 0);
|
||||
|
||||
Reference in New Issue
Block a user