Skip to content

Commit

Permalink
Apply review changes (PR 155)
Browse files Browse the repository at this point in the history
- Fix typo in exception msg.
- Indent 'case' more.
- use variable in place of constant.
- Ignore test on windoof (I don't know why).

Taken from 7d964f9.
  • Loading branch information
hiddenalpha committed Nov 17, 2023
1 parent 772f9be commit a6b8de8
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 36 deletions.
72 changes: 36 additions & 36 deletions src/main/cpp/_nix_based/jssc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ static int awaitReadReady(JNIEnv*env, jlong fd){

if( fd >= FD_SETSIZE ){
jclass exClz = env->FindClass("java/lang/UnsupportedOperationException");
if( exClz != NULL ) env->ThrowNew(exClz, "Bad luck. 'select' cannot hanlde large fds.");
if( exClz != NULL ) env->ThrowNew(exClz, "Bad luck. 'select' cannot handle large fds.");
static_assert(EBADF > 0, "EBADF > 0");
return -EBADF;
}
Expand All @@ -574,25 +574,25 @@ static int awaitReadReady(JNIEnv*env, jlong fd){
err = errno;
jclass exClz = NULL;
switch( err ){
case EBADF:
exClz = env->FindClass("java/lang/IllegalArgumentException");
if( exClz != NULL ) env->ThrowNew(exClz, "EBADF select()");
static_assert(EBADF > 0, "EBADF > 0");
return -err;
case EINVAL:
exClz = env->FindClass("java/lang/IllegalArgumentException");
if( exClz != NULL ) env->ThrowNew(exClz, "EINVAL select()");
static_assert(EINVAL > 0, "EINVAL > 0");
return -err;
default:
// TODO: Maybe other errors are candidates to raise java exceptions too. We can
// add them as soon we know which of them occur, and what they actually
// mean in our context. For now, we infinitely loop, as the original code
// did.
if( numUnknownErrors == 0) fprintf(stderr, "select(): %s\n", strerror(err));
static_assert(INT_MAX >= 0x7FFF, "INT_MAX >= 0x7FFF");
numUnknownErrors = (numUnknownErrors + 1) & 0x3FFF;
continue;
case EBADF:
exClz = env->FindClass("java/lang/IllegalArgumentException");
if( exClz != NULL ) env->ThrowNew(exClz, "EBADF select()");
static_assert(EBADF > 0, "EBADF > 0");
return -err;
case EINVAL:
exClz = env->FindClass("java/lang/IllegalArgumentException");
if( exClz != NULL ) env->ThrowNew(exClz, "EINVAL select()");
static_assert(EINVAL > 0, "EINVAL > 0");
return -err;
default:
// TODO: Maybe other errors are candidates to raise java exceptions too. We can
// add them as soon we know which of them occur, and what they actually
// mean in our context. For now, we infinitely loop, as the original code
// did.
if( numUnknownErrors == 0) fprintf(stderr, "select(): %s\n", strerror(err));
static_assert(INT_MAX >= 0x7FFF, "INT_MAX >= 0x7FFF");
numUnknownErrors = (numUnknownErrors + 1) & 0x3FFF;
continue;
}
}
// Did wait successfully.
Expand All @@ -613,20 +613,20 @@ static int awaitReadReady(JNIEnv*env, jlong fd){
err = errno;
jclass exClz = NULL;
switch( err ){
case EINVAL:
exClz = env->FindClass("java/lang/IllegalArgumentException");
if( exClz != NULL ) env->ThrowNew(exClz, "EINVAL poll()");
static_assert(EINVAL > 0, "EINVAL > 0");
return -EINVAL;
default:
// TODO: Maybe other errors are candidates to raise java exceptions too. We can
// add them as soon we know which of them occur, and what they actually
// mean in our context. For now, we infinitely loop, as the original code
// did.
if( numUnknownErrors == 0) fprintf(stderr, "poll(): %s\n", strerror(err));
static_assert(INT_MAX >= 0x7FFF, "INT_MAX >= 0x7FFF");
numUnknownErrors = (numUnknownErrors + 1) & 0x3FFF;
continue;
case EINVAL:
exClz = env->FindClass("java/lang/IllegalArgumentException");
if( exClz != NULL ) env->ThrowNew(exClz, "EINVAL poll()");
static_assert(EINVAL > 0, "EINVAL > 0");
return -err;
default:
// TODO: Maybe other errors are candidates to raise java exceptions too. We can
// add them as soon we know which of them occur, and what they actually
// mean in our context. For now, we infinitely loop, as the original code
// did.
if( numUnknownErrors == 0) fprintf(stderr, "poll(): %s\n", strerror(err));
static_assert(INT_MAX >= 0x7FFF, "INT_MAX >= 0x7FFF");
numUnknownErrors = (numUnknownErrors + 1) & 0x3FFF;
continue;
}
}
// Did wait successfully.
Expand Down Expand Up @@ -674,8 +674,8 @@ JNIEXPORT jbyteArray JNICALL Java_jssc_SerialNativeInterface_readBytes
err = errno;
const char *exName = NULL, *emsg = NULL;
switch( err ){
case EBADF: exName = "java/lang/IllegalArgumentException"; emsg = "EBADF"; break;
default: exName = "java/io/IOException"; emsg = strerror(err); break;
case EBADF: exName = "java/lang/IllegalArgumentException"; emsg = "EBADF"; break;
default: exName = "java/io/IOException"; emsg = strerror(err); break;
}
jclass exClz = env->FindClass(exName);
if( exClz != NULL ) env->ThrowNew(exClz, emsg);
Expand Down
1 change: 1 addition & 0 deletions src/test/java/jssc/SerialNativeInterfaceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.Assume.assumeFalse;

public class SerialNativeInterfaceTest {

Expand Down

0 comments on commit a6b8de8

Please sign in to comment.