diff options
author | Waqas Ilyas | 2018-05-02 23:37:29 +0000 |
---|---|---|
committer | Doug Schaefer | 2018-05-28 14:36:44 +0000 |
commit | e5c7bb64f7ea88b517281d8ed312115c3123f322 (patch) | |
tree | 2b383ad0d3a34f575e0906b774c335c527cd8085 | |
parent | 35b4bf02de354d0ec7d4ae3f96cc3951218a5ffb (diff) | |
download | org.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>
-rw-r--r-- | native/org.eclipse.cdt.native.serial/src/org/eclipse/cdt/serial/SerialPort.java | 35 |
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 abbeacb5f9b..8b49cf9e676 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; |