author | bpb |
Wed, 06 Feb 2019 12:48:01 -0800 | |
branch | rsocket-branch |
changeset 57156 | 81e4a12fd1a4 |
parent 57132 | fe6629ef9418 |
child 57160 | c502c299d41e |
permissions | -rw-r--r-- |
57115 | 1 |
/* |
57156
81e4a12fd1a4
rsocket-branch: change recent copyright year to 2019 and new files to 2019 only
bpb
parents:
57132
diff
changeset
|
2 |
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. |
57115 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
24 |
*/ |
|
25 |
||
57130
3e1ebe33554c
rsocket-branch: Review comment C from Brian - rename dispatcher
chegar
parents:
57129
diff
changeset
|
26 |
#include "jdk_internal_net_rdma_RdmaSocketDispatcherImpl.h" |
57115 | 27 |
#include "nio.h" |
28 |
#include "nio_util.h" |
|
29 |
#include <Rsocket.h> |
|
30 |
||
31 |
static jfieldID fd_fdID; |
|
32 |
||
33 |
jint |
|
34 |
convertReturnVal(JNIEnv *env, jint n, jboolean reading) { |
|
35 |
if (n > 0) |
|
36 |
return n; |
|
37 |
else if (n == 0) { |
|
38 |
if (reading) { |
|
39 |
return IOS_EOF; |
|
40 |
} else { |
|
41 |
return 0; |
|
42 |
} |
|
43 |
} |
|
44 |
else if (errno == EAGAIN) |
|
45 |
return IOS_UNAVAILABLE; |
|
46 |
else if (errno == EINTR) |
|
47 |
return IOS_INTERRUPTED; |
|
48 |
else { |
|
49 |
const char *msg = reading ? "Read failed" : "Write failed"; |
|
50 |
JNU_ThrowIOExceptionWithLastError(env, msg); |
|
51 |
return IOS_THROWN; |
|
52 |
} |
|
53 |
} |
|
54 |
||
55 |
jlong |
|
56 |
convertLongReturnVal(JNIEnv *env, jlong n, jboolean reading) { |
|
57 |
if (n > 0) |
|
58 |
return n; |
|
59 |
else if (n == 0) { |
|
60 |
if (reading) { |
|
61 |
return IOS_EOF; |
|
62 |
} else { |
|
63 |
return 0; |
|
64 |
} |
|
65 |
} |
|
66 |
else if (errno == EAGAIN) |
|
67 |
return IOS_UNAVAILABLE; |
|
68 |
else if (errno == EINTR) |
|
69 |
return IOS_INTERRUPTED; |
|
70 |
else { |
|
71 |
const char *msg = reading ? "Read failed" : "Write failed"; |
|
72 |
JNU_ThrowIOExceptionWithLastError(env, msg); |
|
73 |
return IOS_THROWN; |
|
74 |
} |
|
75 |
} |
|
76 |
||
77 |
JNIEXPORT void JNICALL |
|
57130
3e1ebe33554c
rsocket-branch: Review comment C from Brian - rename dispatcher
chegar
parents:
57129
diff
changeset
|
78 |
Java_jdk_internal_net_rdma_RdmaSocketDispatcherImpl_init(JNIEnv *env, |
57115 | 79 |
jclass cl) { |
80 |
loadRdmaFuncs(env); |
|
81 |
CHECK_NULL(cl = (*env)->FindClass(env, "java/io/FileDescriptor")); |
|
82 |
CHECK_NULL(fd_fdID = (*env)->GetFieldID(env, cl, "fd", "I")); |
|
83 |
} |
|
84 |
||
85 |
JNIEXPORT jint JNICALL |
|
57130
3e1ebe33554c
rsocket-branch: Review comment C from Brian - rename dispatcher
chegar
parents:
57129
diff
changeset
|
86 |
Java_jdk_internal_net_rdma_RdmaSocketDispatcherImpl_read0(JNIEnv *env, |
57115 | 87 |
jclass clazz, jobject fdo, jlong address, jint len) { |
88 |
jint fd = (*env)->GetIntField(env, fdo, fd_fdID); |
|
89 |
void *buf = (void *)jlong_to_ptr(address); |
|
57129
1e1db86ea836
rsocket-branch: Review comments from Brian, A, B, and D
chegar
parents:
57115
diff
changeset
|
90 |
return convertReturnVal(env, rs_read(fd, buf, len), JNI_TRUE); |
57115 | 91 |
} |
92 |
||
93 |
JNIEXPORT jlong JNICALL |
|
57130
3e1ebe33554c
rsocket-branch: Review comment C from Brian - rename dispatcher
chegar
parents:
57129
diff
changeset
|
94 |
Java_jdk_internal_net_rdma_RdmaSocketDispatcherImpl_readv0(JNIEnv *env, |
57115 | 95 |
jclass clazz, jobject fdo, jlong address, jint len) { |
96 |
jint fd = (*env)->GetIntField(env, fdo, fd_fdID); |
|
97 |
struct iovec *iov = (struct iovec *)jlong_to_ptr(address); |
|
57129
1e1db86ea836
rsocket-branch: Review comments from Brian, A, B, and D
chegar
parents:
57115
diff
changeset
|
98 |
return convertLongReturnVal(env, rs_readv(fd, iov, len), JNI_TRUE); |
57115 | 99 |
} |
100 |
||
101 |
JNIEXPORT jint JNICALL |
|
57130
3e1ebe33554c
rsocket-branch: Review comment C from Brian - rename dispatcher
chegar
parents:
57129
diff
changeset
|
102 |
Java_jdk_internal_net_rdma_RdmaSocketDispatcherImpl_write0(JNIEnv *env, |
57115 | 103 |
jclass clazz, jobject fdo, jlong address, jint len) { |
104 |
jint fd = (*env)->GetIntField(env, fdo, fd_fdID); |
|
105 |
void *buf = (void *)jlong_to_ptr(address); |
|
57129
1e1db86ea836
rsocket-branch: Review comments from Brian, A, B, and D
chegar
parents:
57115
diff
changeset
|
106 |
return convertReturnVal(env, rs_write(fd, buf, len), JNI_FALSE); |
57115 | 107 |
} |
108 |
||
109 |
JNIEXPORT jlong JNICALL |
|
57130
3e1ebe33554c
rsocket-branch: Review comment C from Brian - rename dispatcher
chegar
parents:
57129
diff
changeset
|
110 |
Java_jdk_internal_net_rdma_RdmaSocketDispatcherImpl_writev0(JNIEnv *env, |
57115 | 111 |
jclass clazz, jobject fdo, jlong address, jint len) { |
112 |
jint fd = (*env)->GetIntField(env, fdo, fd_fdID); |
|
113 |
struct iovec *iov = (struct iovec *)jlong_to_ptr(address); |
|
57129
1e1db86ea836
rsocket-branch: Review comments from Brian, A, B, and D
chegar
parents:
57115
diff
changeset
|
114 |
return convertLongReturnVal(env, rs_writev(fd, iov, len), JNI_FALSE); |
57115 | 115 |
} |
116 |
||
117 |
static void closeFileDescriptor(JNIEnv *env, int fd) { |
|
118 |
if (fd != -1) { |
|
119 |
int result = rs_close(fd); |
|
120 |
if (result < 0) |
|
121 |
JNU_ThrowIOExceptionWithLastError(env, "Close failed"); |
|
122 |
} |
|
123 |
} |
|
124 |
||
125 |
JNIEXPORT void JNICALL |
|
57130
3e1ebe33554c
rsocket-branch: Review comment C from Brian - rename dispatcher
chegar
parents:
57129
diff
changeset
|
126 |
Java_jdk_internal_net_rdma_RdmaSocketDispatcherImpl_close0(JNIEnv *env, |
57115 | 127 |
jclass clazz, jobject fdo) { |
128 |
jint fd = (*env)->GetIntField(env, fdo, fd_fdID); |
|
129 |
closeFileDescriptor(env, fd); |
|
130 |
} |