35 |
obligated to do so. If you do not wish to do so, delete this |
obligated to do so. If you do not wish to do so, delete this |
36 |
exception statement from your version. */ |
exception statement from your version. */ |
37 |
|
|
38 |
|
/* do not move; needed here because of some macro definitions */ |
39 |
#include <config.h> |
#include <config.h> |
|
#include <errno.h> |
|
|
|
|
|
#ifdef HAVE_SYS_IOCTL_H |
|
|
#include <sys/ioctl.h> |
|
|
#endif |
|
|
|
|
|
#ifdef HAVE_ASM_IOCTLS_H |
|
|
#include <asm/ioctls.h> |
|
|
#endif |
|
40 |
|
|
41 |
|
#include <stdlib.h> |
42 |
|
#include <stdio.h> |
43 |
#include <string.h> |
#include <string.h> |
44 |
|
#include <assert.h> |
45 |
|
|
46 |
#include <jni.h> |
#include <jni.h> |
47 |
#include <jcl.h> |
#include <jcl.h> |
48 |
|
|
|
#include "java_net_PlainSocketImpl.h" |
|
|
|
|
49 |
#include "javanet.h" |
#include "javanet.h" |
50 |
|
|
51 |
|
#include "target_native.h" |
52 |
|
#ifndef WITHOUT_NETWORK |
53 |
|
#include "target_native_network.h" |
54 |
|
#endif /* WITHOUT_NETWORK */ |
55 |
|
|
56 |
|
#include "java_net_PlainSocketImpl.h" |
57 |
|
|
58 |
/* |
/* |
59 |
* Note that the functions in this module simply redirect to another |
* Note that the functions in this module simply redirect to another |
60 |
* internal function. Why? Because many of these functions are shared |
* internal function. Why? Because many of these functions are shared |
70 |
JNIEXPORT void JNICALL |
JNIEXPORT void JNICALL |
71 |
Java_java_net_PlainSocketImpl_create(JNIEnv *env, jobject this, jboolean stream) |
Java_java_net_PlainSocketImpl_create(JNIEnv *env, jobject this, jboolean stream) |
72 |
{ |
{ |
73 |
|
#ifndef WITHOUT_NETWORK |
74 |
|
assert(env!=NULL); |
75 |
|
assert((*env)!=NULL); |
76 |
|
|
77 |
_javanet_create(env, this, stream); |
_javanet_create(env, this, stream); |
78 |
|
#else /* not WITHOUT_NETWORK */ |
79 |
|
#endif /* not WITHOUT_NETWORK */ |
80 |
} |
} |
81 |
|
|
82 |
/*************************************************************************/ |
/*************************************************************************/ |
88 |
JNIEXPORT void JNICALL |
JNIEXPORT void JNICALL |
89 |
Java_java_net_PlainSocketImpl_close(JNIEnv *env, jobject this) |
Java_java_net_PlainSocketImpl_close(JNIEnv *env, jobject this) |
90 |
{ |
{ |
91 |
|
#ifndef WITHOUT_NETWORK |
92 |
|
assert(env!=NULL); |
93 |
|
assert((*env)!=NULL); |
94 |
|
|
95 |
_javanet_close(env, this, 1); |
_javanet_close(env, this, 1); |
96 |
|
#else /* not WITHOUT_NETWORK */ |
97 |
|
#endif /* not WITHOUT_NETWORK */ |
98 |
} |
} |
99 |
|
|
100 |
/*************************************************************************/ |
/*************************************************************************/ |
106 |
Java_java_net_PlainSocketImpl_connect(JNIEnv *env, jobject this, |
Java_java_net_PlainSocketImpl_connect(JNIEnv *env, jobject this, |
107 |
jobject addr, jint port) |
jobject addr, jint port) |
108 |
{ |
{ |
109 |
|
#ifndef WITHOUT_NETWORK |
110 |
|
assert(env!=NULL); |
111 |
|
assert((*env)!=NULL); |
112 |
|
|
113 |
_javanet_connect(env, this, addr, port); |
_javanet_connect(env, this, addr, port); |
114 |
|
#else /* not WITHOUT_NETWORK */ |
115 |
|
#endif /* not WITHOUT_NETWORK */ |
116 |
} |
} |
117 |
|
|
118 |
/*************************************************************************/ |
/*************************************************************************/ |
126 |
Java_java_net_PlainSocketImpl_bind(JNIEnv *env, jobject this, jobject addr, |
Java_java_net_PlainSocketImpl_bind(JNIEnv *env, jobject this, jobject addr, |
127 |
jint port) |
jint port) |
128 |
{ |
{ |
129 |
|
#ifndef WITHOUT_NETWORK |
130 |
|
assert(env!=NULL); |
131 |
|
assert((*env)!=NULL); |
132 |
|
|
133 |
_javanet_bind(env, this, addr, port, 1); |
_javanet_bind(env, this, addr, port, 1); |
134 |
|
#else /* not WITHOUT_NETWORK */ |
135 |
|
#endif /* not WITHOUT_NETWORK */ |
136 |
} |
} |
137 |
|
|
138 |
/*************************************************************************/ |
/*************************************************************************/ |
144 |
JNIEXPORT void JNICALL |
JNIEXPORT void JNICALL |
145 |
Java_java_net_PlainSocketImpl_listen(JNIEnv *env, jobject this, jint queuelen) |
Java_java_net_PlainSocketImpl_listen(JNIEnv *env, jobject this, jint queuelen) |
146 |
{ |
{ |
147 |
|
#ifndef WITHOUT_NETWORK |
148 |
|
assert(env!=NULL); |
149 |
|
assert((*env)!=NULL); |
150 |
|
|
151 |
_javanet_listen(env, this, queuelen); |
_javanet_listen(env, this, queuelen); |
152 |
|
#else /* not WITHOUT_NETWORK */ |
153 |
|
#endif /* not WITHOUT_NETWORK */ |
154 |
} |
} |
155 |
|
|
156 |
/*************************************************************************/ |
/*************************************************************************/ |
162 |
JNIEXPORT void JNICALL |
JNIEXPORT void JNICALL |
163 |
Java_java_net_PlainSocketImpl_accept(JNIEnv *env, jobject this, jobject impl) |
Java_java_net_PlainSocketImpl_accept(JNIEnv *env, jobject this, jobject impl) |
164 |
{ |
{ |
165 |
|
#ifndef WITHOUT_NETWORK |
166 |
|
assert(env!=NULL); |
167 |
|
assert((*env)!=NULL); |
168 |
|
|
169 |
_javanet_accept(env, this, impl); |
_javanet_accept(env, this, impl); |
170 |
|
#else /* not WITHOUT_NETWORK */ |
171 |
|
#endif /* not WITHOUT_NETWORK */ |
172 |
} |
} |
173 |
|
|
174 |
/*************************************************************************/ |
/*************************************************************************/ |
176 |
JNIEXPORT jint JNICALL |
JNIEXPORT jint JNICALL |
177 |
Java_java_net_PlainSocketImpl_available(JNIEnv *env, jobject this) |
Java_java_net_PlainSocketImpl_available(JNIEnv *env, jobject this) |
178 |
{ |
{ |
179 |
int fd; |
#ifndef WITHOUT_NETWORK |
180 |
int count = 0; |
jclass cls; |
|
jclass cls; |
|
181 |
jfieldID fid; |
jfieldID fid; |
182 |
|
int fd; |
183 |
|
int bytesAvailable; |
184 |
|
int result; |
185 |
|
|
186 |
|
assert(env!=NULL); |
187 |
|
assert((*env)!=NULL); |
188 |
|
|
189 |
cls = (*env)->GetObjectClass(env, this); |
cls = (*env)->GetObjectClass(env, this); |
190 |
if (cls == 0) |
if (cls == 0) |
191 |
{ |
{ |
202 |
|
|
203 |
fd = (*env)->GetIntField(env, this, fid); |
fd = (*env)->GetIntField(env, this, fid); |
204 |
|
|
205 |
if (ioctl(fd, FIONREAD, &count) == -1) |
TARGET_NATIVE_NETWORK_SOCKET_RECEIVE_AVAILABLE(fd,bytesAvailable,result); |
206 |
|
if (result != TARGET_NATIVE_OK) |
207 |
{ |
{ |
208 |
JCL_ThrowException(env, IO_EXCEPTION, strerror(errno)); |
JCL_ThrowException(env, IO_EXCEPTION, TARGET_NATIVE_LAST_ERROR_STRING()); |
209 |
return 0; |
return 0; |
210 |
} |
} |
211 |
else |
|
212 |
return count; |
return bytesAvailable; |
213 |
|
#else /* not WITHOUT_NETWORK */ |
214 |
|
#endif /* not WITHOUT_NETWORK */ |
215 |
} |
} |
216 |
|
|
217 |
/*************************************************************************/ |
/*************************************************************************/ |
223 |
Java_java_net_PlainSocketImpl_setOption(JNIEnv *env, jobject this, |
Java_java_net_PlainSocketImpl_setOption(JNIEnv *env, jobject this, |
224 |
jint option_id, jobject val) |
jint option_id, jobject val) |
225 |
{ |
{ |
226 |
|
#ifndef WITHOUT_NETWORK |
227 |
|
assert(env!=NULL); |
228 |
|
assert((*env)!=NULL); |
229 |
|
|
230 |
_javanet_set_option(env, this, option_id, val); |
_javanet_set_option(env, this, option_id, val); |
231 |
|
#else /* not WITHOUT_NETWORK */ |
232 |
|
#endif /* not WITHOUT_NETWORK */ |
233 |
} |
} |
234 |
|
|
235 |
/*************************************************************************/ |
/*************************************************************************/ |
241 |
Java_java_net_PlainSocketImpl_getOption(JNIEnv *env, jobject this, |
Java_java_net_PlainSocketImpl_getOption(JNIEnv *env, jobject this, |
242 |
jint option_id) |
jint option_id) |
243 |
{ |
{ |
244 |
|
#ifndef WITHOUT_NETWORK |
245 |
|
assert(env!=NULL); |
246 |
|
assert((*env)!=NULL); |
247 |
|
|
248 |
return(_javanet_get_option(env, this, option_id)); |
return(_javanet_get_option(env, this, option_id)); |
249 |
|
#else /* not WITHOUT_NETWORK */ |
250 |
|
#endif /* not WITHOUT_NETWORK */ |
251 |
} |
} |
252 |
|
|
253 |
/*************************************************************************/ |
/*************************************************************************/ |
259 |
Java_java_net_PlainSocketImpl_read(JNIEnv *env, jobject this, jarray buf, |
Java_java_net_PlainSocketImpl_read(JNIEnv *env, jobject this, jarray buf, |
260 |
jint offset, jint len) |
jint offset, jint len) |
261 |
{ |
{ |
262 |
|
#ifndef WITHOUT_NETWORK |
263 |
|
assert(env!=NULL); |
264 |
|
assert((*env)!=NULL); |
265 |
|
|
266 |
return(_javanet_recvfrom(env, this, buf, offset, len, 0, 0)); |
return(_javanet_recvfrom(env, this, buf, offset, len, 0, 0)); |
267 |
|
#else /* not WITHOUT_NETWORK */ |
268 |
|
#endif /* not WITHOUT_NETWORK */ |
269 |
} |
} |
270 |
|
|
271 |
/*************************************************************************/ |
/*************************************************************************/ |
277 |
Java_java_net_PlainSocketImpl_write(JNIEnv *env, jobject this, jarray buf, |
Java_java_net_PlainSocketImpl_write(JNIEnv *env, jobject this, jarray buf, |
278 |
jint offset, jint len) |
jint offset, jint len) |
279 |
{ |
{ |
280 |
|
#ifndef WITHOUT_NETWORK |
281 |
|
assert(env!=NULL); |
282 |
|
assert((*env)!=NULL); |
283 |
|
|
284 |
_javanet_sendto(env, this, buf, offset, len, 0, 0); |
_javanet_sendto(env, this, buf, offset, len, 0, 0); |
285 |
|
#else /* not WITHOUT_NETWORK */ |
286 |
|
#endif /* not WITHOUT_NETWORK */ |
287 |
} |
} |
288 |
|
|
289 |
|
/* end of file */ |