1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-25 18:05:33 +02:00

Bug 534286. Made read(byte[],int,int) blocking

Added a loop in read(byte[], int, int) to block until any input is
available. Or until the port is closed, or an exception occurs.

Change-Id: I1ead6f465571274e77e74de685b8185c8cdde108
Signed-off-by: Waqas Ilyas <waqas.ilyas@gmail.com>
This commit is contained in:
Waqas Ilyas 2018-05-02 18:37:29 -05:00 committed by Doug Schaefer
parent 35b4bf02de
commit e5c7bb64f7

View file

@ -103,21 +103,38 @@ public class SerialPort {
rpos += n;
return n;
} else {
n = read1(handle, b, off, len);
if (n <= 0 && isPaused) {
synchronized (pauseMutex) {
while (isPaused) {
try {
pauseMutex.wait();
} catch (InterruptedException e) {
return -1;
while (isOpen()) {
n = read1(handle, b, off, len);
if (n <= 0 ) {
if (isPaused) {
synchronized (pauseMutex) {
while (isPaused) {
try {
pauseMutex.wait();
} catch (InterruptedException e) {
return -1;
}
}
}
}
else if (n < 0) {
// End of stream, connection closed?
return n;
}
else {
// Nothing available yet, keep blocking
try {
Thread.sleep(500);
} catch (InterruptedException e) {
// ignore
}
}
} else {
return n;
}
return read1(handle, b, off, len);
} else {
return n;
}
return -1;
}
} else {
return -1;