--- old/src/jdk.net/linux/native/libextnet/LinuxRdmaSocketDispatcherImpl.c 2018-12-14 14:58:06.474024361 +0000 +++ new/src/jdk.net/linux/native/libextnet/LinuxRdmaSocketDispatcherImpl.c 2018-12-14 14:58:06.154024361 +0000 @@ -86,11 +86,10 @@ Java_jdk_internal_net_rdma_LinuxRdmaSocketDispatcherImpl_read0(JNIEnv *env, jclass clazz, jobject fdo, jlong address, jint len) { jint fd = (*env)->GetIntField(env, fdo, fd_fdID); - jint flags = rs_fcntl(fd, F_GETFL, 0); - jint non_blocking = (flags & O_NONBLOCK); void *buf = (void *)jlong_to_ptr(address); jint result = convertReturnVal(env, rs_read(fd, buf, len), JNI_TRUE); - if (non_blocking == 0 && result == IOS_UNAVAILABLE) { + if (result == IOS_UNAVAILABLE + && (rs_fcntl(fd, F_GETFL, 0) & O_NONBLOCK) == 0) { // blocking struct pollfd pfd[1]; pfd[0].fd = fd; pfd[0].events = POLLIN; @@ -98,8 +97,7 @@ if (pfd[0].revents & POLLIN) result = convertReturnVal(env, rs_read(fd, buf, len), JNI_TRUE); else { - const char *msg = "Read failed"; - JNU_ThrowIOExceptionWithLastError(env, msg); + JNU_ThrowIOExceptionWithLastError(env, "Read failed"); return IOS_THROWN; } } @@ -110,21 +108,18 @@ Java_jdk_internal_net_rdma_LinuxRdmaSocketDispatcherImpl_readv0(JNIEnv *env, jclass clazz, jobject fdo, jlong address, jint len) { jint fd = (*env)->GetIntField(env, fdo, fd_fdID); - jint flags = rs_fcntl(fd, F_GETFL, 0); - jint non_blocking = (flags & O_NONBLOCK); struct iovec *iov = (struct iovec *)jlong_to_ptr(address); jlong result = convertLongReturnVal(env, rs_readv(fd, iov, len), JNI_TRUE); - if (non_blocking == 0 && result == IOS_UNAVAILABLE) { + if (result == IOS_UNAVAILABLE + && (rs_fcntl(fd, F_GETFL, 0) & O_NONBLOCK) == 0) { // blocking struct pollfd pfd[1]; pfd[0].fd = fd; pfd[0].events = POLLIN; rs_poll(pfd, 1, -1); if (pfd[0].revents & POLLIN) - result = convertLongReturnVal(env, rs_readv(fd, iov, len), - JNI_TRUE); + result = convertLongReturnVal(env, rs_readv(fd, iov, len), JNI_TRUE); else { - const char *msg = "Read failed"; - JNU_ThrowIOExceptionWithLastError(env, msg); + JNU_ThrowIOExceptionWithLastError(env, "Read failed"); return IOS_THROWN; } } @@ -135,11 +130,10 @@ Java_jdk_internal_net_rdma_LinuxRdmaSocketDispatcherImpl_write0(JNIEnv *env, jclass clazz, jobject fdo, jlong address, jint len) { jint fd = (*env)->GetIntField(env, fdo, fd_fdID); - jint flags = rs_fcntl(fd, F_GETFL, 0); - jint non_blocking = (flags & O_NONBLOCK); void *buf = (void *)jlong_to_ptr(address); jint result = convertReturnVal(env, rs_write(fd, buf, len), JNI_FALSE); - if (non_blocking == 0 && result == IOS_UNAVAILABLE) { + if (result == IOS_UNAVAILABLE + && (rs_fcntl(fd, F_GETFL, 0) & O_NONBLOCK) == 0) { // blocking struct pollfd pfd[1]; pfd[0].fd = fd; pfd[0].events = POLLOUT; @@ -147,8 +141,7 @@ if (pfd[0].revents & POLLOUT) result = convertReturnVal(env, rs_write(fd, buf, len), JNI_FALSE); else { - const char *msg = "Write failed"; - JNU_ThrowIOExceptionWithLastError(env, msg); + JNU_ThrowIOExceptionWithLastError(env, "Write failed"); return IOS_THROWN; } } @@ -159,22 +152,19 @@ Java_jdk_internal_net_rdma_LinuxRdmaSocketDispatcherImpl_writev0(JNIEnv *env, jclass clazz, jobject fdo, jlong address, jint len) { jint fd = (*env)->GetIntField(env, fdo, fd_fdID); - jint flags = rs_fcntl(fd, F_GETFL, 0); - jint non_blocking = (flags & O_NONBLOCK); struct iovec *iov = (struct iovec *)jlong_to_ptr(address); jlong result = convertLongReturnVal(env, rs_writev(fd, iov, len), JNI_FALSE); - if (non_blocking == 0 && result == IOS_UNAVAILABLE) { + if (result == IOS_UNAVAILABLE + && (rs_fcntl(fd, F_GETFL, 0) & O_NONBLOCK) == 0) { // blocking struct pollfd pfd[1]; pfd[0].fd = fd; pfd[0].events = POLLOUT; rs_poll(pfd, 1, -1); if (pfd[0].revents & POLLOUT) - result = convertLongReturnVal(env, rs_writev(fd, iov, len), - JNI_FALSE); + result = convertLongReturnVal(env, rs_writev(fd, iov, len), JNI_FALSE); else { - const char *msg = "Write failed"; - JNU_ThrowIOExceptionWithLastError(env, msg); + JNU_ThrowIOExceptionWithLastError(env, "Write failed"); return IOS_THROWN; } }