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:
parent
35b4bf02de
commit
e5c7bb64f7
1 changed files with 28 additions and 11 deletions
|
@ -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;
|
||||||
|
|
Loading…
Add table
Reference in a new issue