diff options
Diffstat (limited to 'libjava/classpath/native/jni/java-net')
-rw-r--r-- | libjava/classpath/native/jni/java-net/Makefile.am | 4 | ||||
-rw-r--r-- | libjava/classpath/native/jni/java-net/Makefile.in | 22 | ||||
-rw-r--r-- | libjava/classpath/native/jni/java-net/gnu_java_net_PlainDatagramSocketImpl.c | 452 | ||||
-rw-r--r-- | libjava/classpath/native/jni/java-net/gnu_java_net_VMPlainDatagramSocketImpl.c | 399 | ||||
-rw-r--r-- | libjava/classpath/native/jni/java-net/gnu_java_net_VMPlainSocketImpl.c (renamed from libjava/classpath/native/jni/java-net/gnu_java_net_PlainSocketImpl.c) | 169 | ||||
-rw-r--r-- | libjava/classpath/native/jni/java-net/java_net_VMInetAddress.c | 15 | ||||
-rw-r--r-- | libjava/classpath/native/jni/java-net/java_net_VMNetworkInterface.c | 3 | ||||
-rw-r--r-- | libjava/classpath/native/jni/java-net/javanet.c | 149 | ||||
-rw-r--r-- | libjava/classpath/native/jni/java-net/javanet.h | 2 |
9 files changed, 544 insertions, 671 deletions
diff --git a/libjava/classpath/native/jni/java-net/Makefile.am b/libjava/classpath/native/jni/java-net/Makefile.am index bf7a92bbf00..4bca9511e07 100644 --- a/libjava/classpath/native/jni/java-net/Makefile.am +++ b/libjava/classpath/native/jni/java-net/Makefile.am @@ -4,8 +4,8 @@ libjavanet_la_SOURCES = javanet.c \ javanet.h \ java_net_VMInetAddress.c \ java_net_VMNetworkInterface.c \ - gnu_java_net_PlainDatagramSocketImpl.c \ - gnu_java_net_PlainSocketImpl.c + gnu_java_net_VMPlainDatagramSocketImpl.c \ + gnu_java_net_VMPlainSocketImpl.c libjavanet_la_LIBADD = $(top_builddir)/native/jni/classpath/jcl.lo diff --git a/libjava/classpath/native/jni/java-net/Makefile.in b/libjava/classpath/native/jni/java-net/Makefile.in index d1d678ebded..bf64c9daba4 100644 --- a/libjava/classpath/native/jni/java-net/Makefile.in +++ b/libjava/classpath/native/jni/java-net/Makefile.in @@ -44,10 +44,11 @@ DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = $(top_srcdir)/../../libtool.m4 \ $(top_srcdir)/m4/acattribute.m4 $(top_srcdir)/m4/accross.m4 \ - $(top_srcdir)/m4/acinclude.m4 $(top_srcdir)/m4/iconv.m4 \ - $(top_srcdir)/m4/lib-ld.m4 $(top_srcdir)/m4/lib-link.m4 \ - $(top_srcdir)/m4/lib-prefix.m4 $(top_srcdir)/m4/pkg.m4 \ - $(top_srcdir)/configure.ac + $(top_srcdir)/m4/acinclude.m4 \ + $(top_srcdir)/m4/ax_create_stdint_h.m4 \ + $(top_srcdir)/m4/iconv.m4 $(top_srcdir)/m4/lib-ld.m4 \ + $(top_srcdir)/m4/lib-link.m4 $(top_srcdir)/m4/lib-prefix.m4 \ + $(top_srcdir)/m4/pkg.m4 $(top_srcdir)/configure.ac am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ $(ACLOCAL_M4) mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs @@ -66,8 +67,8 @@ libjavanet_la_DEPENDENCIES = \ $(top_builddir)/native/jni/classpath/jcl.lo am_libjavanet_la_OBJECTS = javanet.lo java_net_VMInetAddress.lo \ java_net_VMNetworkInterface.lo \ - gnu_java_net_PlainDatagramSocketImpl.lo \ - gnu_java_net_PlainSocketImpl.lo + gnu_java_net_VMPlainDatagramSocketImpl.lo \ + gnu_java_net_VMPlainSocketImpl.lo libjavanet_la_OBJECTS = $(am_libjavanet_la_OBJECTS) DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir)/include depcomp = $(SHELL) $(top_srcdir)/depcomp @@ -172,6 +173,7 @@ JAY = @JAY@ JAY_SKELETON = @JAY_SKELETON@ JIKES = @JIKES@ JIKESENCODING = @JIKESENCODING@ +JIKESWARNINGS = @JIKESWARNINGS@ KJC = @KJC@ LDFLAGS = @LDFLAGS@ LIBDEBUG = @LIBDEBUG@ @@ -281,8 +283,8 @@ libjavanet_la_SOURCES = javanet.c \ javanet.h \ java_net_VMInetAddress.c \ java_net_VMNetworkInterface.c \ - gnu_java_net_PlainDatagramSocketImpl.c \ - gnu_java_net_PlainSocketImpl.c + gnu_java_net_VMPlainDatagramSocketImpl.c \ + gnu_java_net_VMPlainSocketImpl.c libjavanet_la_LIBADD = $(top_builddir)/native/jni/classpath/jcl.lo AM_LDFLAGS = @CLASSPATH_MODULE@ @@ -357,8 +359,8 @@ mostlyclean-compile: distclean-compile: -rm -f *.tab.c -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gnu_java_net_PlainDatagramSocketImpl.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gnu_java_net_PlainSocketImpl.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gnu_java_net_VMPlainDatagramSocketImpl.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gnu_java_net_VMPlainSocketImpl.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/java_net_VMInetAddress.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/java_net_VMNetworkInterface.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/javanet.Plo@am__quote@ diff --git a/libjava/classpath/native/jni/java-net/gnu_java_net_PlainDatagramSocketImpl.c b/libjava/classpath/native/jni/java-net/gnu_java_net_PlainDatagramSocketImpl.c deleted file mode 100644 index 5bc284f6426..00000000000 --- a/libjava/classpath/native/jni/java-net/gnu_java_net_PlainDatagramSocketImpl.c +++ /dev/null @@ -1,452 +0,0 @@ -/* PlainDatagramSocketImpl.c - Native methods for PlainDatagramSocketImpl class - Copyright (C) 1998 Free Software Foundation, Inc. - -This file is part of GNU Classpath. - -GNU Classpath is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Classpath is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with GNU Classpath; see the file COPYING. If not, write to the -Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301 USA. - -Linking this library statically or dynamically with other modules is -making a combined work based on this library. Thus, the terms and -conditions of the GNU General Public License cover the whole -combination. - -As a special exception, the copyright holders of this library give you -permission to link this library with independent modules to produce an -executable, regardless of the license terms of these independent -modules, and to copy and distribute the resulting executable under -terms of your choice, provided that you also meet, for each linked -independent module, the terms and conditions of the license of that -module. An independent module is a module which is not derived from -or based on this library. If you modify this library, you may extend -this exception to your version of the library, but you are not -obligated to do so. If you do not wish to do so, delete this -exception statement from your version. */ - -/* do not move; needed here because of some macro definitions */ -#include <config.h> - -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <assert.h> - -#include <jni.h> -#include <jcl.h> - -#include "javanet.h" - -#include "target_native.h" -#ifndef WITHOUT_NETWORK -#include "target_native_network.h" -#endif /* WITHOUT_NETWORK */ - -#include "gnu_java_net_PlainDatagramSocketImpl.h" - -/* - * Note that most of the functions in this module simply redirect to another - * internal function. Why? Because many of these functions are shared - * with PlainSocketImpl. - */ - -/*************************************************************************/ - -/* - * Creates a new datagram socket - */ -JNIEXPORT void JNICALL -Java_gnu_java_net_PlainDatagramSocketImpl_create (JNIEnv * env, jobject obj) -{ - assert (env != NULL); - assert ((*env) != NULL); - -#ifndef WITHOUT_NETWORK - _javanet_create (env, obj, 0); -#else /* not WITHOUT_NETWORK */ -#endif /* not WITHOUT_NETWORK */ -} - -/*************************************************************************/ - -/* - * Close the socket. - */ -JNIEXPORT void JNICALL -Java_gnu_java_net_PlainDatagramSocketImpl_close (JNIEnv * env, jobject obj) -{ - assert (env != NULL); - assert ((*env) != NULL); - -#ifndef WITHOUT_NETWORK - _javanet_close (env, obj, 0); -#else /* not WITHOUT_NETWORK */ -#endif /* not WITHOUT_NETWORK */ -} - -/*************************************************************************/ - -/* - * This method binds the specified address to the specified local port. - * Note that we have to set the local address and local port public instance - * variables. - */ -JNIEXPORT void JNICALL -Java_gnu_java_net_PlainDatagramSocketImpl_bind (JNIEnv * env, jobject obj, - jint port, jobject addr) -{ - assert (env != NULL); - assert ((*env) != NULL); - -#ifndef WITHOUT_NETWORK - _javanet_bind (env, obj, addr, port, 0); -#else /* not WITHOUT_NETWORK */ -#endif /* not WITHOUT_NETWORK */ -} - -/*************************************************************************/ - -/* - * This method sets the specified option for a socket - */ -JNIEXPORT void JNICALL -Java_gnu_java_net_PlainDatagramSocketImpl_setOption (JNIEnv * env, - jobject obj, - jint option_id, - jobject val) -{ - assert (env != NULL); - assert ((*env) != NULL); - -#ifndef WITHOUT_NETWORK - _javanet_set_option (env, obj, option_id, val); -#else /* not WITHOUT_NETWORK */ -#endif /* not WITHOUT_NETWORK */ -} - -/*************************************************************************/ - -/* - * This method sets the specified option for a socket - */ -JNIEXPORT jobject JNICALL -Java_gnu_java_net_PlainDatagramSocketImpl_getOption (JNIEnv * env, - jobject obj, - jint option_id) -{ - assert (env != NULL); - assert ((*env) != NULL); - -#ifndef WITHOUT_NETWORK - return (_javanet_get_option (env, obj, option_id)); -#else /* not WITHOUT_NETWORK */ - return NULL; -#endif /* not WITHOUT_NETWORK */ -} - -/*************************************************************************/ - -/* - * Reads a buffer from a remote host - */ -JNIEXPORT void JNICALL -Java_gnu_java_net_PlainDatagramSocketImpl_receive0 (JNIEnv * env, jobject obj, - jobject packet) -{ -#ifndef WITHOUT_NETWORK - int addr, port, bytes_read; - unsigned int maxlen, offset; - jclass cls, addr_cls; - jfieldID fid; - jmethodID mid; - jarray arr; - unsigned char octets[4]; - char ip_str[16]; - jobject ip_str_obj, addr_obj; - - assert (env != NULL); - assert ((*env) != NULL); - - addr = 0; - port = 0; - maxlen = 0; - offset = 0; - bytes_read = 0; - - if (packet == NULL) - { - JCL_ThrowException (env, "java/lang/NullPointerException", - "Null datagram packet"); - return; - } - - /* Get the buffer from the packet */ - cls = (*env)->GetObjectClass (env, packet); - if (cls == NULL) - { - JCL_ThrowException (env, IO_EXCEPTION, "Internal error"); - return; - } - - mid = (*env)->GetMethodID (env, cls, "getData", "()[B"); - if (mid == NULL) - { - JCL_ThrowException (env, IO_EXCEPTION, "Internal error: getData"); - return; - } - - arr = (*env)->CallObjectMethod (env, packet, mid); - if ((*env)->ExceptionOccurred (env)) - return; - if (arr == NULL) - { - JCL_ThrowException (env, IO_EXCEPTION, "Internal error: call getData"); - return; - } - - /* Now get the offset from the packet */ - mid = (*env)->GetMethodID (env, cls, "getOffset", "()I"); - if (mid == NULL) - { - JCL_ThrowException (env, IO_EXCEPTION, "Internal error: getOffset"); - return; - } - - offset = (*env)->CallIntMethod (env, packet, mid); - if ((*env)->ExceptionOccurred (env)) - return; - - DBG ("PlainDatagramSocketImpl.receive(): Got the offset\n"); - - /* Now get the maximal available length from the packet */ - fid = (*env)->GetFieldID (env, cls, "maxlen", "I"); - if (fid == NULL) - { - JCL_ThrowException (env, IO_EXCEPTION, "Internal error: maxlen"); - return; - } - - maxlen = (*env)->GetIntField (env, packet, fid); - if ((*env)->ExceptionOccurred (env)) - return; - - /* Receive the packet */ - /* should we try some sort of validation on the length? */ - bytes_read = - _javanet_recvfrom (env, obj, arr, offset, maxlen, &addr, &port); - if ((*env)->ExceptionOccurred (env)) - return; - if (bytes_read == -1) - { - JCL_ThrowException (env, IO_EXCEPTION, "Internal error: receive"); - return; - } - - DBG ("PlainDatagramSocketImpl.receive(): Received packet\n"); - - /* Store the address */ - TARGET_NATIVE_NETWORK_INT_TO_IPADDRESS_BYTES (addr, - octets[0], - octets[1], - octets[2], octets[3]); - sprintf (ip_str, "%d.%d.%d.%d", octets[0], octets[1], octets[2], octets[3]); - ip_str_obj = (*env)->NewStringUTF (env, ip_str); - if (ip_str_obj == NULL) - { - JCL_ThrowException (env, IO_EXCEPTION, "Internal error: new string"); - return; - } - - addr_cls = (*env)->FindClass (env, "java/net/InetAddress"); - if (addr_cls == NULL) - { - JCL_ThrowException (env, IO_EXCEPTION, - "Internal error: InetAddress class"); - return; - } - DBG ("PlainDatagramSocketImpl.receive(): Found InetAddress class\n"); - - mid = (*env)->GetStaticMethodID (env, addr_cls, "getByName", - "(Ljava/lang/String;)Ljava/net/InetAddress;"); - if (mid == NULL) - { - JCL_ThrowException (env, IO_EXCEPTION, "Internal Error"); - return; - } - DBG - ("PlainDatagramSocketImpl.receive(): Found InetAddress.getByName method\n"); - - addr_obj = (*env)->CallStaticObjectMethod (env, addr_cls, mid, ip_str_obj); - if ((*env)->ExceptionOccurred (env)) - return; - - mid = (*env)->GetMethodID (env, cls, "setAddress", - "(Ljava/net/InetAddress;)V"); - if (mid == NULL) - { - JCL_ThrowException (env, IO_EXCEPTION, "Internal error: setAddress"); - return; - } - - (*env)->CallVoidMethod (env, packet, mid, addr_obj); - if ((*env)->ExceptionOccurred (env)) - return; - - DBG ("PlainDatagramSocketImpl.receive(): Stored the address\n"); - - /* Store the port */ - mid = (*env)->GetMethodID (env, cls, "setPort", "(I)V"); - if (mid == NULL) - { - JCL_ThrowException (env, IO_EXCEPTION, "Internal error: setPort"); - return; - } - - (*env)->CallVoidMethod (env, packet, mid, port); - if ((*env)->ExceptionOccurred (env)) - return; - - DBG ("PlainDatagramSocketImpl.receive(): Stored the port\n"); - - /* Store back the length */ - fid = (*env)->GetFieldID (env, cls, "length", "I"); - if (fid == NULL) - { - JCL_ThrowException (env, IO_EXCEPTION, "Internal error: length"); - return; - } - - (*env)->SetIntField (env, packet, fid, bytes_read); - if ((*env)->ExceptionOccurred (env)) - return; - - DBG ("PlainDatagramSocketImpl.receive(): Stored the length\n"); -#else /* not WITHOUT_NETWORK */ -#endif /* not WITHOUT_NETWORK */ -} - -/*************************************************************************/ - -/* - * Writes a buffer to the remote host - */ -JNIEXPORT void JNICALL -Java_gnu_java_net_PlainDatagramSocketImpl_sendto (JNIEnv * env, jobject obj, - jobject addr, jint port, - jarray buf, jint offset, - jint len) -{ -#ifndef WITHOUT_NETWORK - jint netAddress; - - assert (env != NULL); - assert ((*env) != NULL); - - netAddress = _javanet_get_netaddr (env, addr); - if ((*env)->ExceptionOccurred (env)) - return; - - DBG ("PlainDatagramSocketImpl.sendto(): have addr\n"); - - _javanet_sendto (env, obj, buf, offset, len, netAddress, port); - if ((*env)->ExceptionOccurred (env)) - return; - - DBG ("PlainDatagramSocketImpl.sendto(): finished\n"); -#else /* not WITHOUT_NETWORK */ -#endif /* not WITHOUT_NETWORK */ -} - -/*************************************************************************/ - -/* - * Joins a multicast group - */ -JNIEXPORT void JNICALL -Java_gnu_java_net_PlainDatagramSocketImpl_join (JNIEnv * env, jobject obj, - jobject addr) -{ -#ifndef WITHOUT_NETWORK - jint netAddress; - int fd; - int result; - - assert (env != NULL); - assert ((*env) != NULL); - - netAddress = _javanet_get_netaddr (env, addr); - if ((*env)->ExceptionOccurred (env)) - return; - - fd = _javanet_get_int_field (env, obj, "native_fd"); - if ((*env)->ExceptionOccurred (env)) - return; - - DBG ("PlainDatagramSocketImpl.join(): have native fd\n"); - - TARGET_NATIVE_NETWORK_SOCKET_SET_OPTION_ADD_MEMBERSHIP (fd, netAddress, - result); - - if (result != TARGET_NATIVE_OK) - { - JCL_ThrowException (env, IO_EXCEPTION, - TARGET_NATIVE_LAST_ERROR_STRING ()); - return; - } - - DBG ("PlainDatagramSocketImpl.join(): finished\n"); -#else /* not WITHOUT_NETWORK */ -#endif /* not WITHOUT_NETWORK */ -} - -/*************************************************************************/ - -/* - * Leaves a multicast group - */ -JNIEXPORT void JNICALL -Java_gnu_java_net_PlainDatagramSocketImpl_leave (JNIEnv * env, jobject obj, - jobject addr) -{ -#ifndef WITHOUT_NETWORK - jint netAddress; - int fd; - int result; - - assert (env != NULL); - assert ((*env) != NULL); - - netAddress = _javanet_get_netaddr (env, addr); - if ((*env)->ExceptionOccurred (env)) - return; - - fd = _javanet_get_int_field (env, obj, "native_fd"); - if ((*env)->ExceptionOccurred (env)) - return; - - DBG ("PlainDatagramSocketImpl.leave(): have native fd\n"); - - TARGET_NATIVE_NETWORK_SOCKET_SET_OPTION_DROP_MEMBERSHIP (fd, netAddress, - result); - if (result != TARGET_NATIVE_OK) - { - JCL_ThrowException (env, IO_EXCEPTION, - TARGET_NATIVE_LAST_ERROR_STRING ()); - return; - } - - DBG ("PlainDatagramSocketImpl.leave(): finished\n"); -#else /* not WITHOUT_NETWORK */ -#endif /* not WITHOUT_NETWORK */ -} diff --git a/libjava/classpath/native/jni/java-net/gnu_java_net_VMPlainDatagramSocketImpl.c b/libjava/classpath/native/jni/java-net/gnu_java_net_VMPlainDatagramSocketImpl.c new file mode 100644 index 00000000000..1b3cb97e0d0 --- /dev/null +++ b/libjava/classpath/native/jni/java-net/gnu_java_net_VMPlainDatagramSocketImpl.c @@ -0,0 +1,399 @@ +/* VMPlainDatagramSocketImpl.c - Native methods for PlainDatagramSocketImpl + Copyright (C) 2005, 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +/* do not move; needed here because of some macro definitions */ +#include <config.h> + +#include <stdlib.h> +#include <stdio.h> +#include <string.h> + +#include <jni.h> +#include <jcl.h> + +#include "javanet.h" + +#include "target_native.h" +#ifndef WITHOUT_NETWORK + #include "target_native_network.h" +#endif /* WITHOUT_NETWORK */ + + +#include "gnu_java_net_VMPlainDatagramSocketImpl.h" + +/* + * Note that most of the functions in this module simply redirect to another + * internal function. Why? Because many of these functions are shared + * with PlainSocketImpl. + */ + +/*************************************************************************/ + +/* + * Creates a new datagram socket + */ +JNIEXPORT void JNICALL +Java_gnu_java_net_VMPlainDatagramSocketImpl_create(JNIEnv *env, + jclass klass __attribute__ ((__unused__)) + , jobject obj) +{ + +#ifndef WITHOUT_NETWORK + _javanet_create(env, obj, 0); +#else /* not WITHOUT_NETWORK */ +#endif /* not WITHOUT_NETWORK */ +} + +/*************************************************************************/ + +/* + * Close the socket. + */ +JNIEXPORT void JNICALL +Java_gnu_java_net_VMPlainDatagramSocketImpl_close(JNIEnv *env, + jclass klass __attribute__ ((__unused__)), + jobject obj) +{ + +#ifndef WITHOUT_NETWORK + _javanet_close(env, obj, 0); +#else /* not WITHOUT_NETWORK */ +#endif /* not WITHOUT_NETWORK */ +} + +/*************************************************************************/ + +/* + * Connects to the specified destination. + */ +JNIEXPORT void JNICALL +Java_gnu_java_net_VMPlainDatagramSocketImpl_connect(JNIEnv *env, + jclass klass __attribute__ ((__unused__)), + jobject obj, + jobject addr, jint port) +{ +#ifndef WITHOUT_NETWORK + + _javanet_connect(env, obj, addr, port, 0); +#else /* not WITHOUT_NETWORK */ +#endif /* not WITHOUT_NETWORK */ +} + +/*************************************************************************/ + +/* + * This method binds the specified address to the specified local port. + * Note that we have to set the local address and local port public instance + * variables. + */ +JNIEXPORT void JNICALL +Java_gnu_java_net_VMPlainDatagramSocketImpl_bind(JNIEnv *env, + jclass klass __attribute__ ((__unused__)), + jobject obj, + jint port, jobject addr) +{ + +#ifndef WITHOUT_NETWORK + _javanet_bind(env, obj, addr, port, 0); +#else /* not WITHOUT_NETWORK */ +#endif /* not WITHOUT_NETWORK */ +} + +/*************************************************************************/ + +/* + * This method sets the specified option for a socket + */ +JNIEXPORT void JNICALL +Java_gnu_java_net_VMPlainDatagramSocketImpl_setOption(JNIEnv *env, + jclass klass __attribute__ ((__unused__)), + jobject obj, + jint option_id, + jobject val) +{ + +#ifndef WITHOUT_NETWORK + _javanet_set_option(env, obj, option_id, val); +#else /* not WITHOUT_NETWORK */ +#endif /* not WITHOUT_NETWORK */ +} + +/*************************************************************************/ + +/* + * This method sets the specified option for a socket + */ +JNIEXPORT jobject JNICALL +Java_gnu_java_net_VMPlainDatagramSocketImpl_getOption(JNIEnv *env, + jclass klass __attribute__ ((__unused__)), + jobject obj, + jint option_id) +{ + +#ifndef WITHOUT_NETWORK + return(_javanet_get_option(env, obj, option_id)); +#else /* not WITHOUT_NETWORK */ + return NULL; +#endif /* not WITHOUT_NETWORK */ +} + +/*************************************************************************/ + +/* + * Reads a buffer from a remote host + */ +JNIEXPORT void JNICALL +Java_gnu_java_net_VMPlainDatagramSocketImpl_nativeReceive(JNIEnv *env, + jclass klass __attribute__ ((__unused__)), + jobject obj, + jbyteArray arr, + jint offset, + jint length, + jbyteArray receivedFromAddress, + jintArray receivedFromPort, + jintArray receivedLength) +{ +#ifndef WITHOUT_NETWORK + int addr, *port, *bytes_read; + char *addressBytes; + + addr = 0; + + port = (int*)(*env)->GetIntArrayElements(env, receivedFromPort, NULL); + if (port == NULL) + { + JCL_ThrowException(env, IO_EXCEPTION, "Internal error: could not access receivedFromPort array"); + return; + } + + bytes_read = (int*)(*env)->GetIntArrayElements(env, receivedLength, NULL); + if (bytes_read == NULL) + { + (*env)->ReleaseIntArrayElements(env, receivedFromPort, (jint*)port, 0); + JCL_ThrowException(env, IO_EXCEPTION, "Internal error: could not access receivedLength array"); + return; + } + + /* Receive the packet */ + /* should we try some sort of validation on the length? */ + (*bytes_read) = _javanet_recvfrom(env, obj, arr, offset, length, &addr, port); + + /* Special case the strange situation where the receiver didn't want any + bytes. */ + if (length == 0 && (*bytes_read) == -1) + *bytes_read = 0; + + if ((*bytes_read) == -1) + { + (*env)->ReleaseIntArrayElements(env, receivedFromPort, (jint*)port, 0); + (*env)->ReleaseIntArrayElements(env, receivedLength, (jint*)bytes_read, 0); + JCL_ThrowException(env, IO_EXCEPTION, "Internal error: receive"); + return; + } + + (*env)->ReleaseIntArrayElements(env, receivedFromPort, (jint*)port, 0); + (*env)->ReleaseIntArrayElements(env, receivedLength, (jint*)bytes_read, 0); + + if ((*env)->ExceptionOccurred(env)) + { + return; + } + + DBG("PlainDatagramSocketImpl.receive(): Received packet\n"); + + + /* Store the address */ + addressBytes = (char*)(*env)->GetPrimitiveArrayCritical(env, receivedFromAddress, NULL); + TARGET_NATIVE_NETWORK_INT_TO_IPADDRESS_BYTES(addr, + addressBytes[0], + addressBytes[1], + addressBytes[2], + addressBytes[3] + ); + (*env)->ReleasePrimitiveArrayCritical(env, receivedFromAddress, addressBytes, 0); + +#else /* not WITHOUT_NETWORK */ +#endif /* not WITHOUT_NETWORK */ +} + +/*************************************************************************/ + +/* + * Writes a buffer to the remote host + */ +JNIEXPORT void JNICALL +Java_gnu_java_net_VMPlainDatagramSocketImpl_nativeSendTo(JNIEnv *env, + jclass klass __attribute__ ((__unused__)), + jobject obj, + jobject addr, + jint port, + jarray buf, + jint offset, + jint len) +{ +#ifndef WITHOUT_NETWORK + jint netAddress; + + /* check if address given, tr 7.3.2005 */ + if (addr != NULL) + { + netAddress = _javanet_get_netaddr(env, addr); + if ((*env)->ExceptionOccurred(env)) + { + return; + } + } + else + { + netAddress = 0; + } + + DBG("PlainDatagramSocketImpl.sendto(): have addr\n"); + + _javanet_sendto(env, obj, buf, offset, len, netAddress, port); + if ((*env)->ExceptionOccurred(env)) + { + return; + } + + DBG("PlainDatagramSocketImpl.sendto(): finished\n"); +#else /* not WITHOUT_NETWORK */ +#endif /* not WITHOUT_NETWORK */ +} + +/*************************************************************************/ + +/* + * Joins a multicast group + */ +JNIEXPORT void JNICALL +Java_gnu_java_net_VMPlainDatagramSocketImpl_join(JNIEnv *env, + jclass klass __attribute__ ((__unused__)), + jobject obj, + jobject addr) +{ +#ifndef WITHOUT_NETWORK + jint netAddress; + int fd; + int result; + + /* check if address given, tr 7.3.2005 */ + if (addr != NULL) + { + netAddress = _javanet_get_netaddr(env, addr); + if ((*env)->ExceptionOccurred(env)) + { + JCL_ThrowException(env, IO_EXCEPTION, "Internal error"); + return; + } + } + else + { + netAddress = 0; + } + + fd = _javanet_get_int_field(env, obj, "native_fd"); + if ((*env)->ExceptionOccurred(env)) + { + JCL_ThrowException(env, IO_EXCEPTION, "Internal error"); + return; + } + + DBG("PlainDatagramSocketImpl.join(): have native fd\n"); + + TARGET_NATIVE_NETWORK_SOCKET_SET_OPTION_ADD_MEMBERSHIP(fd,netAddress,result); + + if (result != TARGET_NATIVE_OK) + { + JCL_ThrowException(env, IO_EXCEPTION, TARGET_NATIVE_LAST_ERROR_STRING()); + return; + } + + DBG("PlainDatagramSocketImpl.join(): finished\n"); +#else /* not WITHOUT_NETWORK */ +#endif /* not WITHOUT_NETWORK */ +} + +/*************************************************************************/ + +/* + * Leaves a multicast group + */ +JNIEXPORT void JNICALL +Java_gnu_java_net_VMPlainDatagramSocketImpl_leave(JNIEnv *env, + jclass klass __attribute__ ((__unused__)), + jobject obj, + jobject addr) +{ +#ifndef WITHOUT_NETWORK + jint netAddress; + int fd; + int result; + + /* check if address given, tr 7.3.2005 */ + if (addr != NULL) + { + netAddress = _javanet_get_netaddr(env, addr); + if ((*env)->ExceptionOccurred(env)) + { + JCL_ThrowException(env, IO_EXCEPTION, "Internal error"); + return; + } + } + else + { + netAddress = 0; + } + + fd = _javanet_get_int_field(env, obj, "native_fd"); + if ((*env)->ExceptionOccurred(env)) + { JCL_ThrowException(env, IO_EXCEPTION, "Internal error"); return; } + + DBG("PlainDatagramSocketImpl.leave(): have native fd\n"); + + TARGET_NATIVE_NETWORK_SOCKET_SET_OPTION_DROP_MEMBERSHIP(fd,netAddress,result); + if (result!=TARGET_NATIVE_OK) + { + JCL_ThrowException(env, IO_EXCEPTION, TARGET_NATIVE_LAST_ERROR_STRING()); + return; + } + + DBG("PlainDatagramSocketImpl.leave(): finished\n"); +#else /* not WITHOUT_NETWORK */ +#endif /* not WITHOUT_NETWORK */ +} + diff --git a/libjava/classpath/native/jni/java-net/gnu_java_net_PlainSocketImpl.c b/libjava/classpath/native/jni/java-net/gnu_java_net_VMPlainSocketImpl.c index f5f22ab77e7..cf10ee4b53c 100644 --- a/libjava/classpath/native/jni/java-net/gnu_java_net_PlainSocketImpl.c +++ b/libjava/classpath/native/jni/java-net/gnu_java_net_VMPlainSocketImpl.c @@ -1,5 +1,5 @@ -/* PlainSocketImpl.c - Native methods for PlainSocketImpl class - Copyright (C) 1998, 2002, 2005 Free Software Foundation, Inc. +/* VMPlainSocketImpl.c - Native methods for PlainSocketImpl class + Copyright (C) 2005, 2006 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -41,8 +41,7 @@ exception statement from your version. */ #include <stdlib.h> #include <stdio.h> #include <string.h> -#include <assert.h> - + #include <jni.h> #include <jcl.h> @@ -50,11 +49,10 @@ exception statement from your version. */ #include "target_native.h" #ifndef WITHOUT_NETWORK -#include "target_native_file.h" /* Get FIONREAD on Solaris. */ -#include "target_native_network.h" + #include "target_native_network.h" #endif /* WITHOUT_NETWORK */ -#include "gnu_java_net_PlainSocketImpl.h" +#include "gnu_java_net_VMPlainSocketImpl.h" /* * Note that the functions in this module simply redirect to another @@ -69,14 +67,12 @@ exception statement from your version. */ * Creates a new stream or datagram socket */ JNIEXPORT void JNICALL -Java_gnu_java_net_PlainSocketImpl_create (JNIEnv * env, jobject this, - jboolean stream) +Java_gnu_java_net_VMPlainSocketImpl_create(JNIEnv *env, + jclass klass __attribute__ ((__unused__)), + jobject obj) { #ifndef WITHOUT_NETWORK - assert (env != NULL); - assert ((*env) != NULL); - - _javanet_create (env, this, stream); + _javanet_create(env, obj, JNI_TRUE); #else /* not WITHOUT_NETWORK */ #endif /* not WITHOUT_NETWORK */ } @@ -88,13 +84,12 @@ Java_gnu_java_net_PlainSocketImpl_create (JNIEnv * env, jobject this, * action as well. */ JNIEXPORT void JNICALL -Java_gnu_java_net_PlainSocketImpl_close (JNIEnv * env, jobject this) +Java_gnu_java_net_VMPlainSocketImpl_close(JNIEnv *env, + jclass klass __attribute__ ((__unused__)), + jobject obj) { #ifndef WITHOUT_NETWORK - assert (env != NULL); - assert ((*env) != NULL); - - _javanet_close (env, this, 1); + _javanet_close(env, obj, 1); #else /* not WITHOUT_NETWORK */ #endif /* not WITHOUT_NETWORK */ } @@ -105,14 +100,13 @@ Java_gnu_java_net_PlainSocketImpl_close (JNIEnv * env, jobject this) * Connects to the specified destination. */ JNIEXPORT void JNICALL -Java_gnu_java_net_PlainSocketImpl_connect (JNIEnv * env, jobject this, - jobject addr, jint port) +Java_gnu_java_net_VMPlainSocketImpl_connect(JNIEnv *env, + jclass klass __attribute__ ((__unused__)), + jobject obj, + jobject addr, jint port) { #ifndef WITHOUT_NETWORK - assert (env != NULL); - assert ((*env) != NULL); - - _javanet_connect (env, this, addr, port); + _javanet_connect(env, obj, addr, port, 1); #else /* not WITHOUT_NETWORK */ #endif /* not WITHOUT_NETWORK */ } @@ -125,14 +119,13 @@ Java_gnu_java_net_PlainSocketImpl_connect (JNIEnv * env, jobject this, * variables. */ JNIEXPORT void JNICALL -Java_gnu_java_net_PlainSocketImpl_bind (JNIEnv * env, jobject this, - jobject addr, jint port) +Java_gnu_java_net_VMPlainSocketImpl_bind(JNIEnv *env, + jclass klass __attribute__ ((__unused__)), + jobject obj, jobject addr, + jint port) { #ifndef WITHOUT_NETWORK - assert (env != NULL); - assert ((*env) != NULL); - - _javanet_bind (env, this, addr, port, 1); + _javanet_bind(env, obj, addr, port, 1); #else /* not WITHOUT_NETWORK */ #endif /* not WITHOUT_NETWORK */ } @@ -144,14 +137,12 @@ Java_gnu_java_net_PlainSocketImpl_bind (JNIEnv * env, jobject this, * connections allowed. */ JNIEXPORT void JNICALL -Java_gnu_java_net_PlainSocketImpl_listen (JNIEnv * env, jobject this, - jint queuelen) +Java_gnu_java_net_VMPlainSocketImpl_listen(JNIEnv *env, + jclass klass __attribute__ ((__unused__)), + jobject obj, jint queuelen) { #ifndef WITHOUT_NETWORK - assert (env != NULL); - assert ((*env) != NULL); - - _javanet_listen (env, this, queuelen); + _javanet_listen(env, obj, queuelen); #else /* not WITHOUT_NETWORK */ #endif /* not WITHOUT_NETWORK */ } @@ -163,14 +154,12 @@ Java_gnu_java_net_PlainSocketImpl_listen (JNIEnv * env, jobject this, * object. Note that we assume this is a PlainSocketImpl just like us. */ JNIEXPORT void JNICALL -Java_gnu_java_net_PlainSocketImpl_accept (JNIEnv * env, jobject this, - jobject impl) +Java_gnu_java_net_VMPlainSocketImpl_accept(JNIEnv *env, + jclass klass __attribute__ ((__unused__)), + jobject obj, jobject impl) { #ifndef WITHOUT_NETWORK - assert (env != NULL); - assert ((*env) != NULL); - - _javanet_accept (env, this, impl); + _javanet_accept(env, obj, impl); #else /* not WITHOUT_NETWORK */ #endif /* not WITHOUT_NETWORK */ } @@ -178,39 +167,37 @@ Java_gnu_java_net_PlainSocketImpl_accept (JNIEnv * env, jobject this, /*************************************************************************/ JNIEXPORT jint JNICALL -Java_gnu_java_net_PlainSocketImpl_available (JNIEnv * env, jobject this) +Java_gnu_java_net_VMPlainSocketImpl_available(JNIEnv *env, + jclass klass __attribute__ ((__unused__)), + jobject obj) { #ifndef WITHOUT_NETWORK - jclass cls; + jclass cls; jfieldID fid; - int fd; - int bytesAvailable; - int result; - - assert (env != NULL); - assert ((*env) != NULL); - - cls = (*env)->GetObjectClass (env, this); + int fd; + int bytesAvailable; + int result; + + cls = (*env)->GetObjectClass(env, obj); if (cls == 0) { - JCL_ThrowException (env, IO_EXCEPTION, "internal error"); + JCL_ThrowException(env, IO_EXCEPTION, "internal error"); return 0; } - - fid = (*env)->GetFieldID (env, cls, "native_fd", "I"); + + fid = (*env)->GetFieldID(env, cls, "native_fd", "I"); if (fid == 0) { - JCL_ThrowException (env, IO_EXCEPTION, "internal error"); + JCL_ThrowException(env, IO_EXCEPTION, "internal error"); return 0; } - fd = (*env)->GetIntField (env, this, fid); - - TARGET_NATIVE_NETWORK_SOCKET_RECEIVE_AVAILABLE (fd, bytesAvailable, result); + fd = (*env)->GetIntField(env, obj, fid); + + TARGET_NATIVE_NETWORK_SOCKET_RECEIVE_AVAILABLE(fd,bytesAvailable,result); if (result != TARGET_NATIVE_OK) { - JCL_ThrowException (env, IO_EXCEPTION, - TARGET_NATIVE_LAST_ERROR_STRING ()); + JCL_ThrowException(env, IO_EXCEPTION, TARGET_NATIVE_LAST_ERROR_STRING()); return 0; } @@ -226,14 +213,13 @@ Java_gnu_java_net_PlainSocketImpl_available (JNIEnv * env, jobject this) * This method sets the specified option for a socket */ JNIEXPORT void JNICALL -Java_gnu_java_net_PlainSocketImpl_setOption (JNIEnv * env, jobject this, - jint option_id, jobject val) +Java_gnu_java_net_VMPlainSocketImpl_setOption(JNIEnv *env, + jclass klass __attribute__ ((__unused__)), + jobject obj, + jint option_id, jobject val) { #ifndef WITHOUT_NETWORK - assert (env != NULL); - assert ((*env) != NULL); - - _javanet_set_option (env, this, option_id, val); + _javanet_set_option(env, obj, option_id, val); #else /* not WITHOUT_NETWORK */ #endif /* not WITHOUT_NETWORK */ } @@ -241,17 +227,16 @@ Java_gnu_java_net_PlainSocketImpl_setOption (JNIEnv * env, jobject this, /*************************************************************************/ /* - * This method sets the specified option for a socket + * This method gets the specified option for a socket */ JNIEXPORT jobject JNICALL -Java_gnu_java_net_PlainSocketImpl_getOption (JNIEnv * env, jobject this, - jint option_id) +Java_gnu_java_net_VMPlainSocketImpl_getOption(JNIEnv *env, + jclass klass __attribute__ ((__unused__)), + jobject obj, + jint option_id) { #ifndef WITHOUT_NETWORK - assert (env != NULL); - assert ((*env) != NULL); - - return (_javanet_get_option (env, this, option_id)); + return(_javanet_get_option(env, obj, option_id)); #else /* not WITHOUT_NETWORK */ return NULL; #endif /* not WITHOUT_NETWORK */ @@ -263,14 +248,13 @@ Java_gnu_java_net_PlainSocketImpl_getOption (JNIEnv * env, jobject this, * Reads a buffer from a remote host */ JNIEXPORT jint JNICALL -Java_gnu_java_net_PlainSocketImpl_read (JNIEnv * env, jobject this, - jarray buf, jint offset, jint len) +Java_gnu_java_net_VMPlainSocketImpl_read(JNIEnv *env, + jclass klass __attribute__ ((__unused__)), + jobject obj, jarray buf, + jint offset, jint len) { #ifndef WITHOUT_NETWORK - assert (env != NULL); - assert ((*env) != NULL); - - return (_javanet_recvfrom (env, this, buf, offset, len, 0, 0)); + return(_javanet_recvfrom(env, obj, buf, offset, len, 0, 0)); #else /* not WITHOUT_NETWORK */ return 0; #endif /* not WITHOUT_NETWORK */ @@ -282,37 +266,34 @@ Java_gnu_java_net_PlainSocketImpl_read (JNIEnv * env, jobject this, * Writes a buffer to the remote host */ JNIEXPORT void JNICALL -Java_gnu_java_net_PlainSocketImpl_write (JNIEnv * env, jobject this, - jarray buf, jint offset, jint len) +Java_gnu_java_net_VMPlainSocketImpl_write(JNIEnv *env, + jclass klass __attribute__ ((__unused__)), + jobject obj, jarray buf, + jint offset, jint len) { #ifndef WITHOUT_NETWORK - assert (env != NULL); - assert ((*env) != NULL); - - _javanet_sendto (env, this, buf, offset, len, 0, 0); + _javanet_sendto(env, obj, buf, offset, len, 0, 0); #else /* not WITHOUT_NETWORK */ #endif /* not WITHOUT_NETWORK */ } JNIEXPORT void JNICALL -Java_gnu_java_net_PlainSocketImpl_shutdownInput (JNIEnv * env, jobject this) +Java_gnu_java_net_VMPlainSocketImpl_shutdownInput (JNIEnv * env, + jclass klass __attribute__ ((__unused__)), + jobject this) { #ifndef WITHOUT_NETWORK - assert (env != NULL); - assert ((*env) != NULL); - _javanet_shutdownInput (env, this); #else /* not WITHOUT_NETWORK */ #endif /* not WITHOUT_NETWORK */ } JNIEXPORT void JNICALL -Java_gnu_java_net_PlainSocketImpl_shutdownOutput (JNIEnv * env, jobject this) +Java_gnu_java_net_VMPlainSocketImpl_shutdownOutput (JNIEnv * env, + jclass klass __attribute__ ((__unused__)), + jobject this) { #ifndef WITHOUT_NETWORK - assert (env != NULL); - assert ((*env) != NULL); - _javanet_shutdownOutput (env, this); #else /* not WITHOUT_NETWORK */ #endif /* not WITHOUT_NETWORK */ diff --git a/libjava/classpath/native/jni/java-net/java_net_VMInetAddress.c b/libjava/classpath/native/jni/java-net/java_net_VMInetAddress.c index 0ba00d1c3c6..86ac06e6f79 100644 --- a/libjava/classpath/native/jni/java-net/java_net_VMInetAddress.c +++ b/libjava/classpath/native/jni/java-net/java_net_VMInetAddress.c @@ -1,5 +1,5 @@ /* VMInetAddress.c - Native methods for InetAddress class - Copyright (C) 1998, 2002, 2005 Free Software Foundation, Inc. + Copyright (C) 1998, 2002, 2005, 2006 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -41,7 +41,6 @@ exception statement from your version. */ #include <stdlib.h> #include <stdio.h> #include <string.h> -#include <assert.h> #include <jni.h> #include <jcl.h> @@ -69,9 +68,6 @@ Java_java_net_VMInetAddress_getLocalHostname (JNIEnv * env, int result; jstring retval; - assert (env != NULL); - assert ((*env) != NULL); - #ifndef WITHOUT_NETWORK TARGET_NATIVE_NETWORK_GET_HOSTNAME (hostname, sizeof (hostname), result); if (result != TARGET_NATIVE_OK) @@ -100,9 +96,6 @@ Java_java_net_VMInetAddress_lookupInaddrAny (JNIEnv * env, jarray IParray; jbyte *octets; - assert (env != NULL); - assert ((*env) != NULL); - /* Allocate an array for the IP address */ IParray = (*env)->NewByteArray (env, 4); if (IParray == NULL) @@ -150,9 +143,6 @@ Java_java_net_VMInetAddress_getHostByAddr (JNIEnv * env, int result; jstring retval; - assert (env != NULL); - assert ((*env) != NULL); - /* Grab the byte[] array with the IP out of the input data */ len = (*env)->GetArrayLength (env, arr); if (len != 4) @@ -215,9 +205,6 @@ Java_java_net_VMInetAddress_getHostByName (JNIEnv * env, jarray ret_octets; int max_addresses; - assert (env != NULL); - assert ((*env) != NULL); - /* Grab the hostname string */ hostname = (*env)->GetStringUTFChars (env, host, 0); if (!hostname) diff --git a/libjava/classpath/native/jni/java-net/java_net_VMNetworkInterface.c b/libjava/classpath/native/jni/java-net/java_net_VMNetworkInterface.c index 71f5e8927e5..f05e9fcc5a2 100644 --- a/libjava/classpath/native/jni/java-net/java_net_VMNetworkInterface.c +++ b/libjava/classpath/native/jni/java-net/java_net_VMNetworkInterface.c @@ -1,5 +1,5 @@ /* VMNetworkInterface.c - Native methods for NetworkInterface class - Copyright (C) 2003, 2005 Free Software Foundation, Inc. + Copyright (C) 2003, 2005, 2006 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -41,7 +41,6 @@ exception statement from your version. */ #include <stdlib.h> #include <stdio.h> #include <string.h> -#include <assert.h> #include <jni.h> #include <jcl.h> diff --git a/libjava/classpath/native/jni/java-net/javanet.c b/libjava/classpath/native/jni/java-net/javanet.c index 31afbc86997..0f296a60479 100644 --- a/libjava/classpath/native/jni/java-net/javanet.c +++ b/libjava/classpath/native/jni/java-net/javanet.c @@ -1,5 +1,5 @@ /* javanet.c - Common internal functions for the java.net package - Copyright (C) 1998, 2002, 2004, 2005 Free Software Foundation, Inc. + Copyright (C) 1998, 2002, 2004, 2005, 2006 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -41,7 +41,6 @@ exception statement from your version. */ #include <stdlib.h> #include <stdio.h> #include <string.h> -#include <assert.h> #include <jni.h> #include <jcl.h> @@ -77,9 +76,6 @@ _javanet_set_int_field (JNIEnv * env, jobject obj, jclass cls; jfieldID fid; - assert (env != NULL); - assert ((*env) != NULL); - cls = (*env)->FindClass (env, class); if (cls == NULL) return; @@ -106,9 +102,6 @@ _javanet_get_int_field (JNIEnv * env, jobject obj, const char *field) jfieldID fid; int fd; - assert (env != NULL); - assert ((*env) != NULL); - DBG ("_javanet_get_int_field(): Entered _javanet_get_int_field\n"); cls = (*env)->GetObjectClass (env, obj); @@ -133,20 +126,20 @@ _javanet_get_int_field (JNIEnv * env, jobject obj, const char *field) * need to include it. */ static void -_javanet_create_localfd (JNIEnv * env, jobject this) +_javanet_create_localfd (JNIEnv * env, jobject this, jboolean stream) { jclass this_cls, fd_cls; jfieldID fid; jmethodID mid; jobject fd_obj; - assert (env != NULL); - assert ((*env) != NULL); - DBG ("_javanet_create_localfd(): Entered _javanet_create_localfd\n"); /* Look up the fd field */ - this_cls = (*env)->FindClass (env, "java/net/SocketImpl"); + if (stream) + this_cls = (*env)->FindClass(env, "java/net/SocketImpl"); + else + this_cls = (*env)->FindClass(env, "java/net/DatagramSocketImpl"); if (this_cls == NULL) return; @@ -194,9 +187,6 @@ _javanet_create_boolean (JNIEnv * env, jboolean val) jmethodID mid; jobject obj; - assert (env != NULL); - assert ((*env) != NULL); - cls = (*env)->FindClass (env, "java/lang/Boolean"); if (cls == NULL) return NULL; @@ -224,9 +214,6 @@ _javanet_create_integer (JNIEnv * env, jint val) jmethodID mid; jobject obj; - assert (env != NULL); - assert ((*env) != NULL); - cls = (*env)->FindClass (env, "java/lang/Integer"); if (cls == NULL) return NULL; @@ -258,9 +245,6 @@ _javanet_create_inetaddress (JNIEnv * env, int netaddr) jstring ip_str; jobject ia; - assert (env != NULL); - assert ((*env) != NULL); - /* Build a string IP address */ TARGET_NATIVE_NETWORK_INT_TO_IPADDRESS_BYTES (netaddr, octets[0], @@ -315,9 +299,6 @@ _javanet_set_remhost_addr (JNIEnv * env, jobject this, jobject ia) jclass this_cls; jfieldID fid; - assert (env != NULL); - assert ((*env) != NULL); - /* Set the variable in the object */ this_cls = (*env)->FindClass (env, "java/net/SocketImpl"); if (this_cls == NULL) @@ -343,9 +324,6 @@ _javanet_set_remhost (JNIEnv * env, jobject this, int netaddr) { jobject ia; - assert (env != NULL); - assert ((*env) != NULL); - DBG ("_javanet_set_remhost(): Entered _javanet_set_remhost\n"); /* Get an InetAddress object */ @@ -372,9 +350,6 @@ _javanet_get_netaddr (JNIEnv * env, jobject addr) jbyte *octets; int netaddr, len; - assert (env != NULL); - assert ((*env) != NULL); - DBG ("_javanet_get_netaddr(): Entered _javanet_get_netaddr\n"); if (addr == NULL) @@ -441,9 +416,6 @@ _javanet_create (JNIEnv * env, jobject this, jboolean stream) int fd; int result; - assert (env != NULL); - assert ((*env) != NULL); - if (stream) { /* create a stream socket */ @@ -514,9 +486,6 @@ _javanet_close (JNIEnv * env, jobject this, int stream) int result; int error = 0; - assert (env != NULL); - assert ((*env) != NULL); - fd = _javanet_get_int_field (env, this, "native_fd"); if (fd == -1) return; @@ -552,7 +521,8 @@ _javanet_close (JNIEnv * env, jobject this, int stream) * Connects to the specified destination. */ void -_javanet_connect (JNIEnv * env, jobject this, jobject addr, jint port) +_javanet_connect (JNIEnv * env, jobject this, jobject addr, jint port, + jboolean stream) { #ifndef WITHOUT_NETWORK int netaddr, fd; @@ -560,9 +530,6 @@ _javanet_connect (JNIEnv * env, jobject this, jobject addr, jint port) int local_address, local_port; int remote_address, remote_port; - assert (env != NULL); - assert ((*env) != NULL); - DBG ("_javanet_connect(): Entered _javanet_connect\n"); /* Pre-process input variables */ @@ -613,7 +580,7 @@ _javanet_connect (JNIEnv * env, jobject this, jobject addr, jint port) return; } - _javanet_create_localfd (env, this); + _javanet_create_localfd (env, this, stream); if ((*env)->ExceptionOccurred (env)) { /* We don't care whether this succeeds. close() will cleanup later. */ @@ -622,8 +589,13 @@ _javanet_connect (JNIEnv * env, jobject this, jobject addr, jint port) } DBG ("_javanet_connect(): Created fd\n"); - _javanet_set_int_field (env, this, "java/net/SocketImpl", "localport", - local_port); + if (stream) + _javanet_set_int_field (env, this, "java/net/SocketImpl", "localport", + local_port); + else + _javanet_set_int_field (env, this, "java/net/DatagramSocketImpl", + "localPort", local_port); + if ((*env)->ExceptionOccurred (env)) { /* We don't care whether this succeeds. close() will cleanup later. */ @@ -643,31 +615,36 @@ _javanet_connect (JNIEnv * env, jobject this, jobject addr, jint port) return; } - if (remote_address == netaddr) - { - _javanet_set_remhost_addr (env, this, addr); - } - else - { - _javanet_set_remhost (env, this, remote_address); - } - if ((*env)->ExceptionOccurred (env)) + if (stream) { - /* We don't care whether this succeeds. close() will cleanup later. */ - TARGET_NATIVE_NETWORK_SOCKET_CLOSE (fd, result); - return; - } - DBG ("_javanet_connect(): Set the remote host\n"); + if (remote_address == netaddr) + { + _javanet_set_remhost_addr (env, this, addr); + } + else + { + _javanet_set_remhost (env, this, remote_address); + } + if ((*env)->ExceptionOccurred (env)) + { + /* We don't care whether this succeeds. close() will cleanup later. + */ + TARGET_NATIVE_NETWORK_SOCKET_CLOSE (fd, result); + return; + } + DBG ("_javanet_connect(): Set the remote host\n"); - _javanet_set_int_field (env, this, "java/net/SocketImpl", "port", - remote_port); - if ((*env)->ExceptionOccurred (env)) - { - /* We don't care whether this succeeds. close() will cleanup later. */ - TARGET_NATIVE_NETWORK_SOCKET_CLOSE (fd, result); - return; + _javanet_set_int_field (env, this, "java/net/SocketImpl", "port", + remote_port); + if ((*env)->ExceptionOccurred (env)) + { + /* We don't care whether this succeeds. close() will cleanup later. + */ + TARGET_NATIVE_NETWORK_SOCKET_CLOSE (fd, result); + return; + } + DBG ("_javanet_connect(): Set the remote port\n"); } - DBG ("_javanet_connect(): Set the remote port\n"); #else /* not WITHOUT_NETWORK */ #endif /* not WITHOUT_NETWORK */ } @@ -693,9 +670,6 @@ _javanet_bind (JNIEnv * env, jobject this, jobject addr, jint port, int result; int local_address, local_port; - assert (env != NULL); - assert ((*env) != NULL); - DBG ("_javanet_bind(): Entering native bind()\n"); /* Get the address to connect to */ @@ -797,9 +771,6 @@ _javanet_listen (JNIEnv * env, jobject this, jint queuelen) int fd; int result; - assert (env != NULL); - assert ((*env) != NULL); - /* Get the real file descriptor */ fd = _javanet_get_int_field (env, this, "native_fd"); if (fd == -1) @@ -836,9 +807,6 @@ _javanet_accept (JNIEnv * env, jobject this, jobject impl) int local_address, local_port; int remote_address, remote_port; - assert (env != NULL); - assert ((*env) != NULL); - /* Get the real file descriptor */ fd = _javanet_get_int_field (env, this, "native_fd"); if (fd == -1) @@ -897,7 +865,7 @@ _javanet_accept (JNIEnv * env, jobject this, jobject impl) return; } - _javanet_create_localfd (env, impl); + _javanet_create_localfd (env, impl, 1); if ((*env)->ExceptionOccurred (env)) { /* We don't care whether this succeeds. close() will cleanup later. */ @@ -971,9 +939,6 @@ _javanet_recvfrom (JNIEnv * env, jobject this, jarray buf, int offset, int from_address, from_port; int received_bytes; - assert (env != NULL); - assert ((*env) != NULL); - DBG ("_javanet_recvfrom(): Entered _javanet_recvfrom\n"); /* Get the real file descriptor */ @@ -1040,6 +1005,11 @@ _javanet_recvfrom (JNIEnv * env, jobject this, jarray buf, int offset, (*port) = from_port; } + /* zero bytes received means recv() noticed the other side orderly + closing the connection. */ + if (received_bytes == 0) + received_bytes = -1; + return (received_bytes); #else /* not WITHOUT_NETWORK */ #endif /* not WITHOUT_NETWORK */ @@ -1065,9 +1035,6 @@ _javanet_sendto (JNIEnv * env, jobject this, jarray buf, int offset, int len, jbyte *p; int bytes_sent; - assert (env != NULL); - assert ((*env) != NULL); - /* Get the real file descriptor */ fd = _javanet_get_int_field (env, this, "native_fd"); if (fd == -1) @@ -1138,9 +1105,6 @@ _javanet_set_option (JNIEnv * env, jobject this, jint option_id, jobject val) int address; int result; - assert (env != NULL); - assert ((*env) != NULL); - /* Get the real file descriptor */ fd = _javanet_get_int_field (env, this, "native_fd"); if (fd == -1) @@ -1355,9 +1319,6 @@ _javanet_get_option (JNIEnv * env, jobject this, jint option_id) int address; int result; - assert (env != NULL); - assert ((*env) != NULL); - /* Get the real file descriptor */ fd = _javanet_get_int_field (env, this, "native_fd"); if (fd == -1) @@ -1531,9 +1492,6 @@ _javanet_shutdownInput (JNIEnv * env, jobject this) { int fd; - assert (env != NULL); - assert ((*env) != NULL); - /* Get the real file descriptor. */ fd = _javanet_get_int_field (env, this, "native_fd"); if (fd == -1) @@ -1546,7 +1504,8 @@ _javanet_shutdownInput (JNIEnv * env, jobject this) /* Shutdown input stream of socket. */ if (shutdown (fd, SHUT_RD) == -1) { - JCL_ThrowException (env, SOCKET_EXCEPTION, strerror (errno)); + JCL_ThrowException (env, SOCKET_EXCEPTION, + TARGET_NATIVE_LAST_ERROR_STRING()); return; } } @@ -1556,9 +1515,6 @@ _javanet_shutdownOutput (JNIEnv * env, jobject this) { int fd; - assert (env != NULL); - assert ((*env) != NULL); - /* Get the real file descriptor. */ fd = _javanet_get_int_field (env, this, "native_fd"); if (fd == -1) @@ -1571,7 +1527,8 @@ _javanet_shutdownOutput (JNIEnv * env, jobject this) /* Shutdown output stream of socket. */ if (shutdown (fd, SHUT_WR) == -1) { - JCL_ThrowException (env, SOCKET_EXCEPTION, strerror (errno)); + JCL_ThrowException (env, SOCKET_EXCEPTION, + TARGET_NATIVE_LAST_ERROR_STRING()); return; } } diff --git a/libjava/classpath/native/jni/java-net/javanet.h b/libjava/classpath/native/jni/java-net/javanet.h index 7c77ea77f84..c173b1059f6 100644 --- a/libjava/classpath/native/jni/java-net/javanet.h +++ b/libjava/classpath/native/jni/java-net/javanet.h @@ -92,7 +92,7 @@ extern int _javanet_get_int_field(JNIEnv *, jobject, const char *); extern int _javanet_get_netaddr(JNIEnv *, jobject); extern void _javanet_create(JNIEnv *, jobject, jboolean); extern void _javanet_close(JNIEnv *, jobject, int); -extern void _javanet_connect(JNIEnv *, jobject, jobject, jint); +extern void _javanet_connect(JNIEnv *, jobject, jobject, jint, jboolean); extern void _javanet_bind(JNIEnv *, jobject, jobject, jint, int); extern void _javanet_listen(JNIEnv *, jobject, jint); extern void _javanet_accept(JNIEnv *, jobject, jobject); |