Skip to main content
summaryrefslogtreecommitdiffstats
path: root/native
diff options
context:
space:
mode:
authorWaqas Ilyas2018-05-02 19:37:29 -0400
committerDoug Schaefer2018-05-28 10:36:44 -0400
commite5c7bb64f7ea88b517281d8ed312115c3123f322 (patch)
tree2b383ad0d3a34f575e0906b774c335c527cd8085 /native
parent35b4bf02de354d0ec7d4ae3f96cc3951218a5ffb (diff)
downloadorg.eclipse.cdt-e5c7bb64f7ea88b517281d8ed312115c3123f322.tar.gz
org.eclipse.cdt-e5c7bb64f7ea88b517281d8ed312115c3123f322.tar.xz
org.eclipse.cdt-e5c7bb64f7ea88b517281d8ed312115c3123f322.zip
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>
Diffstat (limited to 'native')
-rw-r--r--native/org.eclipse.cdt.native.serial/src/org/eclipse/cdt/serial/SerialPort.java35
1 files changed, 26 insertions, 9 deletions
diff --git a/native/org.eclipse.cdt.native.serial/src/org/eclipse/cdt/serial/SerialPort.java b/native/org.eclipse.cdt.native.serial/src/org/eclipse/cdt/serial/SerialPort.java
index abbeacb5f9..8b49cf9e67 100644
--- a/native/org.eclipse.cdt.native.serial/src/org/eclipse/cdt/serial/SerialPort.java
+++ b/native/org.eclipse.cdt.native.serial/src/org/eclipse/cdt/serial/SerialPort.java
@@ -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) {
+ 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 {
- pauseMutex.wait();
+ Thread.sleep(500);
} catch (InterruptedException e) {
- return -1;
+ // ignore
}
}
+ } else {
+ return n;
}
- return read1(handle, b, off, len);
- } else {
- return n;
}
+
+ return -1;
}
} else {
return -1;

Back to the top