57115
|
1 |
/*
|
57160
|
2 |
* Copyright (c) 2018, 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 |
|
|
26 |
#include <Rsocket.h>
|
|
27 |
#include <dlfcn.h>
|
|
28 |
#include "jni_util.h"
|
|
29 |
|
|
30 |
static const char* nativeRdmaLib = "librdmacm.so.1";
|
|
31 |
static jboolean funcs_loaded = JNI_FALSE;
|
|
32 |
|
|
33 |
jboolean loadRdmaFuncs(JNIEnv* env) {
|
|
34 |
if (funcs_loaded)
|
|
35 |
return JNI_TRUE;
|
|
36 |
|
|
37 |
if (dlopen(nativeRdmaLib, RTLD_GLOBAL | RTLD_LAZY) == NULL) {
|
|
38 |
JNU_ThrowByName(env, "java/lang/UnsupportedOperationException",
|
|
39 |
dlerror());
|
|
40 |
return JNI_FALSE;
|
|
41 |
}
|
|
42 |
|
|
43 |
if ((rs_socket = (rs_rsocket_func*)
|
|
44 |
dlsym(RTLD_DEFAULT, "rsocket")) == NULL) {
|
|
45 |
JNU_ThrowByName(env, "java/lang/UnsupportedOperationException",
|
|
46 |
dlerror());
|
|
47 |
return JNI_FALSE;
|
|
48 |
}
|
|
49 |
|
|
50 |
if ((rs_fcntl = (rs_rfcntl_func*)
|
|
51 |
dlsym(RTLD_DEFAULT, "rfcntl")) == NULL) {
|
|
52 |
JNU_ThrowByName(env, "java/lang/UnsupportedOperationException",
|
|
53 |
dlerror());
|
|
54 |
return JNI_FALSE;
|
|
55 |
}
|
|
56 |
|
|
57 |
if ((rs_listen = (rs_rlisten_func*)
|
|
58 |
dlsym(RTLD_DEFAULT, "rlisten")) == NULL) {
|
|
59 |
JNU_ThrowByName(env, "java/lang/UnsupportedOperationException",
|
|
60 |
dlerror());
|
|
61 |
return JNI_FALSE;
|
|
62 |
}
|
|
63 |
|
|
64 |
if ((rs_bind = (rs_rbind_func*)
|
|
65 |
dlsym(RTLD_DEFAULT, "rbind")) == NULL) {
|
|
66 |
JNU_ThrowByName(env, "java/lang/UnsupportedOperationException",
|
|
67 |
dlerror());
|
|
68 |
return JNI_FALSE;
|
|
69 |
}
|
|
70 |
|
|
71 |
if ((rs_connect = (rs_rconnect_func*)
|
|
72 |
dlsym(RTLD_DEFAULT, "rconnect")) == NULL) {
|
|
73 |
JNU_ThrowByName(env, "java/lang/UnsupportedOperationException",
|
|
74 |
dlerror());
|
|
75 |
return JNI_FALSE;
|
|
76 |
}
|
|
77 |
|
|
78 |
if ((rs_getsockname = (rs_rgetsockname_func*)
|
|
79 |
dlsym(RTLD_DEFAULT, "rgetsockname")) == NULL) {
|
|
80 |
JNU_ThrowByName(env, "java/lang/UnsupportedOperationException",
|
|
81 |
dlerror());
|
|
82 |
return JNI_FALSE;
|
|
83 |
}
|
|
84 |
|
|
85 |
if ((rs_getsockopt = (rs_rgetsockopt_func*)
|
|
86 |
dlsym(RTLD_DEFAULT, "rgetsockopt")) == NULL) {
|
|
87 |
JNU_ThrowByName(env, "java/lang/UnsupportedOperationException",
|
|
88 |
dlerror());
|
|
89 |
return JNI_FALSE;
|
|
90 |
}
|
|
91 |
|
|
92 |
if ((rs_setsockopt = (rs_rsetsockopt_func*)
|
|
93 |
dlsym(RTLD_DEFAULT, "rsetsockopt")) == NULL) {
|
|
94 |
JNU_ThrowByName(env, "java/lang/UnsupportedOperationException",
|
|
95 |
dlerror());
|
|
96 |
return JNI_FALSE;
|
|
97 |
}
|
|
98 |
|
|
99 |
if ((rs_shutdown = (rs_rshutdown_func*)
|
|
100 |
dlsym(RTLD_DEFAULT, "rshutdown")) == NULL) {
|
|
101 |
JNU_ThrowByName(env, "java/lang/UnsupportedOperationException",
|
|
102 |
dlerror());
|
|
103 |
return JNI_FALSE;
|
|
104 |
}
|
|
105 |
|
|
106 |
if ((rs_poll = (rs_rpoll_func*)
|
|
107 |
dlsym(RTLD_DEFAULT, "rpoll")) == NULL) {
|
|
108 |
JNU_ThrowByName(env, "java/lang/UnsupportedOperationException",
|
|
109 |
dlerror());
|
|
110 |
return JNI_FALSE;
|
|
111 |
}
|
|
112 |
|
|
113 |
if ((rs_send = (rs_rsend_func*)
|
|
114 |
dlsym(RTLD_DEFAULT, "rsend")) == NULL) {
|
|
115 |
JNU_ThrowByName(env, "java/lang/UnsupportedOperationException",
|
|
116 |
dlerror());
|
|
117 |
return JNI_FALSE;
|
|
118 |
}
|
|
119 |
|
|
120 |
if ((rs_accept = (rs_raccept_func*)
|
|
121 |
dlsym(RTLD_DEFAULT, "raccept")) == NULL) {
|
|
122 |
JNU_ThrowByName(env, "java/lang/UnsupportedOperationException",
|
|
123 |
dlerror());
|
|
124 |
return JNI_FALSE;
|
|
125 |
}
|
|
126 |
|
|
127 |
if ((rs_close = (rs_rclose_func*)
|
|
128 |
dlsym(RTLD_DEFAULT, "rclose")) == NULL) {
|
|
129 |
JNU_ThrowByName(env, "java/lang/UnsupportedOperationException",
|
|
130 |
dlerror());
|
|
131 |
return JNI_FALSE;
|
|
132 |
}
|
|
133 |
|
|
134 |
if ((rs_read = (rs_rread_func*)
|
|
135 |
dlsym(RTLD_DEFAULT, "rread")) == NULL) {
|
|
136 |
JNU_ThrowByName(env, "java/lang/UnsupportedOperationException",
|
|
137 |
dlerror());
|
|
138 |
return JNI_FALSE;
|
|
139 |
}
|
|
140 |
|
|
141 |
if ((rs_readv = (rs_rreadv_func*)
|
|
142 |
dlsym(RTLD_DEFAULT, "rreadv")) == NULL) {
|
|
143 |
JNU_ThrowByName(env, "java/lang/UnsupportedOperationException",
|
|
144 |
dlerror());
|
|
145 |
return JNI_FALSE;
|
|
146 |
}
|
|
147 |
|
|
148 |
if ((rs_write = (rs_rwrite_func*)
|
|
149 |
dlsym(RTLD_DEFAULT, "rwrite")) == NULL) {
|
|
150 |
JNU_ThrowByName(env, "java/lang/UnsupportedOperationException",
|
|
151 |
dlerror());
|
|
152 |
return JNI_FALSE;
|
|
153 |
}
|
|
154 |
|
|
155 |
if ((rs_writev = (rs_rwritev_func*)
|
|
156 |
dlsym(RTLD_DEFAULT, "rwritev")) == NULL) {
|
|
157 |
JNU_ThrowByName(env, "java/lang/UnsupportedOperationException",
|
|
158 |
dlerror());
|
|
159 |
return JNI_FALSE;
|
|
160 |
}
|
|
161 |
|
|
162 |
if ((rs_recv = (rs_rrecv_func*)
|
|
163 |
dlsym(RTLD_DEFAULT, "rrecv")) == NULL) {
|
|
164 |
JNU_ThrowByName(env, "java/lang/UnsupportedOperationException",
|
|
165 |
dlerror());
|
|
166 |
return JNI_FALSE;
|
|
167 |
}
|
|
168 |
|
|
169 |
if ((rs_recvfrom = (rs_rrecvfrom_func*)
|
|
170 |
dlsym(RTLD_DEFAULT, "rrecvfrom")) == NULL) {
|
|
171 |
JNU_ThrowByName(env, "java/lang/UnsupportedOperationException",
|
|
172 |
dlerror());
|
|
173 |
return JNI_FALSE;
|
|
174 |
}
|
|
175 |
|
|
176 |
if ((rs_sendto = (rs_rsendto_func*)
|
|
177 |
dlsym(RTLD_DEFAULT, "rsendto")) == NULL) {
|
|
178 |
JNU_ThrowByName(env, "java/lang/UnsupportedOperationException",
|
|
179 |
dlerror());
|
|
180 |
return JNI_FALSE;
|
|
181 |
}
|
|
182 |
|
|
183 |
funcs_loaded = JNI_TRUE;
|
|
184 |
return JNI_TRUE;
|
|
185 |
}
|