fix(PISerial): break infinite loop when readDevice returns <= 0
In the blocking read path (timeout_ms <= 0), the while loop had no exit condition for readDevice() returning 0 (EOF) or -1 (error). This caused an infinite busy-loop at 100% CPU. Added 'else break' to exit the loop on read failure, matching the timeout branch which already handles this case.
This commit is contained in:
@@ -513,7 +513,10 @@ bool PISerial::read(void * data, int size, double timeout_ms) {
|
|||||||
all = readDevice(data, 1);
|
all = readDevice(data, 1);
|
||||||
while (all < size) {
|
while (all < size) {
|
||||||
ret = readDevice(&((uchar *)data)[all], size - all);
|
ret = readDevice(&((uchar *)data)[all], size - all);
|
||||||
if (ret > 0) all += ret;
|
if (ret > 0)
|
||||||
|
all += ret;
|
||||||
|
else
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
setOption(BlockingRead, br);
|
setOption(BlockingRead, br);
|
||||||
received(data, all);
|
received(data, all);
|
||||||
|
|||||||
Reference in New Issue
Block a user