/[classpath]/classpath/native/jni/java-net/java_net_PlainSocketImpl.c
ViewVC logotype

Diff of /classpath/native/jni/java-net/java_net_PlainSocketImpl.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.5 by cbj, Sat Feb 15 13:55:08 2003 UTC revision 1.6 by rupp, Tue Jul 15 14:35:02 2003 UTC
# Line 35  this exception to your version of the li Line 35  this exception to your version of the li
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
# Line 70  exception statement from your version. * Line 70  exception statement from your version. *
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  /*************************************************************************/  /*************************************************************************/
# Line 82  Java_java_net_PlainSocketImpl_create(JNI Line 88  Java_java_net_PlainSocketImpl_create(JNI
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  /*************************************************************************/  /*************************************************************************/
# Line 94  JNIEXPORT void JNICALL Line 106  JNIEXPORT void JNICALL
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  /*************************************************************************/  /*************************************************************************/
# Line 108  JNIEXPORT void JNICALL Line 126  JNIEXPORT void JNICALL
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  /*************************************************************************/  /*************************************************************************/
# Line 120  Java_java_net_PlainSocketImpl_bind(JNIEn Line 144  Java_java_net_PlainSocketImpl_bind(JNIEn
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  /*************************************************************************/  /*************************************************************************/
# Line 132  Java_java_net_PlainSocketImpl_listen(JNI Line 162  Java_java_net_PlainSocketImpl_listen(JNI
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  /*************************************************************************/  /*************************************************************************/
# Line 140  Java_java_net_PlainSocketImpl_accept(JNI Line 176  Java_java_net_PlainSocketImpl_accept(JNI
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      {      {
# Line 161  Java_java_net_PlainSocketImpl_available( Line 202  Java_java_net_PlainSocketImpl_available(
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  /*************************************************************************/  /*************************************************************************/
# Line 179  JNIEXPORT void JNICALL Line 223  JNIEXPORT void JNICALL
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  /*************************************************************************/  /*************************************************************************/
# Line 191  JNIEXPORT jobject JNICALL Line 241  JNIEXPORT jobject JNICALL
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  /*************************************************************************/  /*************************************************************************/
# Line 203  JNIEXPORT jint JNICALL Line 259  JNIEXPORT jint JNICALL
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  /*************************************************************************/  /*************************************************************************/
# Line 215  JNIEXPORT void JNICALL Line 277  JNIEXPORT void JNICALL
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 */

Legend:
Removed from v.1.5  
changed lines
  Added in v.1.6

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26