Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTorbjörn SVENSSON2019-09-03 11:21:29 -0400
committerTorbjörn SVENSSON2019-09-05 09:02:05 -0400
commit764e42ef505e237923fab176041849b469decabc (patch)
tree78858099b67695614836aeda7fde8d29ab371304
parent1c4271836b484b6926809fe3542448bdd970af3d (diff)
downloadorg.eclipse.cdt-764e42ef505e237923fab176041849b469decabc.tar.gz
org.eclipse.cdt-764e42ef505e237923fab176041849b469decabc.tar.xz
org.eclipse.cdt-764e42ef505e237923fab176041849b469decabc.zip
Bug 482946: Implement InputStream.available()
Change-Id: Iac15816fd4d68206184549c7b47670f9d3137527 Signed-off-by: Torbjörn SVENSSON <torbjorn.svensson@st.com>
-rw-r--r--native/org.eclipse.cdt.native.serial/jni/serial.c27
-rwxr-xr-xnative/org.eclipse.cdt.native.serial/os/linux/x86_64/libserial.sobin13280 -> 13408 bytes
-rwxr-xr-xnative/org.eclipse.cdt.native.serial/os/macosx/x86_64/libserial.jnilibbin13620 -> 13756 bytes
-rwxr-xr-xnative/org.eclipse.cdt.native.serial/os/win32/x86_64/serial.dllbin125772 -> 126038 bytes
-rw-r--r--native/org.eclipse.cdt.native.serial/src/org/eclipse/cdt/serial/SerialPort.java11
5 files changed, 38 insertions, 0 deletions
diff --git a/native/org.eclipse.cdt.native.serial/jni/serial.c b/native/org.eclipse.cdt.native.serial/jni/serial.c
index be6c549b1e..5e783b61c7 100644
--- a/native/org.eclipse.cdt.native.serial/jni/serial.c
+++ b/native/org.eclipse.cdt.native.serial/jni/serial.c
@@ -26,6 +26,7 @@
#include <string.h>
#include <strings.h>
#include <errno.h>
+#include <sys/ioctl.h>
#else
#define WIN32_LEAN_AND_MEAN
#define UNICODE
@@ -251,6 +252,32 @@ JNIEXPORT void JNICALL FUNC(close0)(JNIEnv *env, jobject jobj, jlong handle)
#endif
}
+JNIEXPORT jint JNICALL FUNC(available0)(JNIEnv * env, jobject jobj, jlong jhandle)
+{
+#ifndef __MINGW32__
+ int result = 0;
+ if (ioctl(jhandle, FIONREAD, &result ) < 0) {
+ throwIOException(env, "Error calling ioctl");
+ return 0;
+ }
+ return result;
+#else
+ COMSTAT stat;
+ DWORD errCode;
+#ifdef _WIN64
+ HANDLE handle = (HANDLE)jhandle;
+#else
+ HANDLE handle = (HANDLE)(unsigned)jhandle;
+#endif
+
+ if (ClearCommError(handle, &errCode, &stat) == 0) {
+ throwIOException(env, "Error calling ClearCommError");
+ return -1;
+ }
+ return (int)stat.cbInQue;
+#endif
+}
+
JNIEXPORT jint JNICALL FUNC(read1)(JNIEnv * env, jobject jobj, jlong jhandle, jbyteArray bytes, jint offset, jint size)
{
#ifndef __MINGW32__
diff --git a/native/org.eclipse.cdt.native.serial/os/linux/x86_64/libserial.so b/native/org.eclipse.cdt.native.serial/os/linux/x86_64/libserial.so
index 8d792d5a42..3b73b67c7a 100755
--- a/native/org.eclipse.cdt.native.serial/os/linux/x86_64/libserial.so
+++ b/native/org.eclipse.cdt.native.serial/os/linux/x86_64/libserial.so
Binary files differ
diff --git a/native/org.eclipse.cdt.native.serial/os/macosx/x86_64/libserial.jnilib b/native/org.eclipse.cdt.native.serial/os/macosx/x86_64/libserial.jnilib
index 2c88702add..9904a21906 100755
--- a/native/org.eclipse.cdt.native.serial/os/macosx/x86_64/libserial.jnilib
+++ b/native/org.eclipse.cdt.native.serial/os/macosx/x86_64/libserial.jnilib
Binary files differ
diff --git a/native/org.eclipse.cdt.native.serial/os/win32/x86_64/serial.dll b/native/org.eclipse.cdt.native.serial/os/win32/x86_64/serial.dll
index 849ad95d56..d2f654037b 100755
--- a/native/org.eclipse.cdt.native.serial/os/win32/x86_64/serial.dll
+++ b/native/org.eclipse.cdt.native.serial/os/win32/x86_64/serial.dll
Binary files differ
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 0b8f071b8e..672895179c 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
@@ -131,6 +131,15 @@ public class SerialPort {
public void close() throws IOException {
SerialPort.this.close();
}
+
+ @Override
+ public int available() throws IOException {
+ if (isOpen()) {
+ return available0(handle);
+ } else {
+ return 0;
+ }
+ }
};
private OutputStream outputStream = new OutputStream() {
@@ -208,6 +217,8 @@ public class SerialPort {
private native int read1(long handle, byte[] b, int off, int len) throws IOException;
+ private native int available0(long handle) throws IOException;
+
private native void write0(long handle, int b) throws IOException;
private native void write1(long handle, byte[] b, int off, int len) throws IOException;

Back to the top