1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-02 13:55:39 +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; rpos += n;
return n; return n;
} else { } else {
n = read1(handle, b, off, len); while (isOpen()) {
if (n <= 0 && isPaused) { n = read1(handle, b, off, len);
synchronized (pauseMutex) { if (n <= 0 ) {
while (isPaused) { if (isPaused) {
try { synchronized (pauseMutex) {
pauseMutex.wait(); while (isPaused) {
} catch (InterruptedException e) { try {
return -1; 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 { } else {
return -1; return -1;