aboutsummaryrefslogtreecommitdiff
path: root/flow/src/main/native
diff options
context:
space:
mode:
Diffstat (limited to 'flow/src/main/native')
-rw-r--r--flow/src/main/native/posix/flow.c7
-rw-r--r--flow/src/main/native/posix/flow_jni.c29
2 files changed, 31 insertions, 5 deletions
diff --git a/flow/src/main/native/posix/flow.c b/flow/src/main/native/posix/flow.c
index c408670..7f7d54b 100644
--- a/flow/src/main/native/posix/flow.c
+++ b/flow/src/main/native/posix/flow.c
@@ -38,9 +38,10 @@ int serial_open(
int fd = open(port_name, O_RDWR | O_NOCTTY | O_NONBLOCK);
if (fd < 0) {
+ int en = errno;
DEBUG(perror("error obtaining port file descriptor"););
- if (errno == EACCES) return E_ACCESS_DENIED;
- if (errno == ENOENT) return E_NO_PORT;
+ if (en == EACCES) return E_ACCESS_DENIED;
+ if (en == ENOENT) return E_NO_PORT;
return E_IO;
}
@@ -214,7 +215,7 @@ int serial_read(struct serial_config* const serial, char* const buffer, size_t s
//treat 0 bytes read as an error to avoid problems on disconnect
//anyway, after a poll there should be more than 0 bytes available to read
if (r <= 0) {
- DEBUG(perror("read"););
+ DEBUG(perror("error data not available after select"););
return E_IO;
}
return r;
diff --git a/flow/src/main/native/posix/flow_jni.c b/flow/src/main/native/posix/flow_jni.c
index 9e0ec5e..8ec2aed 100644
--- a/flow/src/main/native/posix/flow_jni.c
+++ b/flow/src/main/native/posix/flow_jni.c
@@ -50,7 +50,21 @@ JNIEXPORT jlong JNICALL Java_com_github_jodersky_flow_internal_NativeSerial_open
*/
JNIEXPORT jint JNICALL Java_com_github_jodersky_flow_internal_NativeSerial_readDirect
(JNIEnv *env, jclass clazz, jlong config, jobject buffer) {
- return 0;
+
+ char* local_buffer = (char*) (*env)->GetDirectBufferAddress(env, buffer);
+ if (local_buffer == NULL) {
+ throwException(env, "java/lang/IllegalArgumentException", "ByteBuffer not direct");
+ return -1;
+ }
+ jlong size = (*env)->GetDirectBufferCapacity(env, buffer);
+
+ int r = serial_read((struct serial_config*) config, local_buffer, (size_t) size);
+ if (r < 0) {
+ check(env, r);
+ return -1;
+ }
+ return r;
+
}
/*
@@ -97,7 +111,18 @@ JNIEXPORT void JNICALL Java_com_github_jodersky_flow_internal_NativeSerial_cance
JNIEXPORT jint JNICALL Java_com_github_jodersky_flow_internal_NativeSerial_writeDirect
(JNIEnv *env, jclass clazz, jlong config, jobject buffer, jint size) {
- return 0;
+ char* local_buffer = (char *) (*env)->GetDirectBufferAddress(env, buffer);
+ if (local_buffer == NULL) {
+ throwException(env, "java/lang/IllegalArgumentException", "ByteBuffer not direct");
+ return -1;
+ }
+
+ int r = serial_write((struct serial_config*) config, local_buffer, (size_t) size);
+ if (r < 0) {
+ check(env, r);
+ return -1;
+ }
+ return r;
}