summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuilhem Lavaux <guilhem@kaffe.org>2006-01-28 16:38:23 +0000
committerGuilhem Lavaux <guilhem@kaffe.org>2006-01-28 16:38:23 +0000
commita92748b017d37f8e4a83997933c5850f9484df9d (patch)
tree0fa7a99c2052d7327aa78be34727040c954d5823
parent0865f0240989b34acb940a364059b69f9d9df05f (diff)
downloadclasspath-a92748b017d37f8e4a83997933c5850f9484df9d.tar.gz
2006-01-28 Guilhem Lavaux <guilhem@kaffe.org>
* native/jni/java-io/java_io_VMFile.c, native/jni/java-net/gnu_java_net_VMPlainDatagramSocketImpl.c, native/jni/java-net/gnu_java_net_VMPlainSocketImpl.c, native/jni/java-net/javanet.c, native/jni/java-net/javanet.h: Adapted the VM layer code to the new native layer. * native/jni/native-lib/cpnet.h (cpnet_addMembership, cpnet_dropMembership, cpnet_getAvailableBytes): Added the declarations of some new functions. (cpnet_newIPV6Address, cpnet_IPV6AddressToBytes, cpnet_bytesToIPV6Address): Implemented. (cpnet_newIPV4Address): Initialize the sin_family field.
-rw-r--r--ChangeLog19
-rw-r--r--native/jni/java-io/java_io_VMFile.c16
-rw-r--r--native/jni/java-net/gnu_java_net_VMPlainDatagramSocketImpl.c75
-rw-r--r--native/jni/java-net/gnu_java_net_VMPlainSocketImpl.c17
-rw-r--r--native/jni/java-net/java_net_VMInetAddress.c43
-rw-r--r--native/jni/java-net/javanet.c418
-rw-r--r--native/jni/java-net/javanet.h7
-rw-r--r--native/jni/native-lib/cpnet.h33
8 files changed, 316 insertions, 312 deletions
diff --git a/ChangeLog b/ChangeLog
index 3c7f9a9b9..dc5c13016 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,24 @@
2006-01-28 Guilhem Lavaux <guilhem@kaffe.org>
+ * native/jni/java-io/java_io_VMFile.c,
+ native/jni/java-net/gnu_java_net_VMPlainDatagramSocketImpl.c,
+ native/jni/java-net/gnu_java_net_VMPlainSocketImpl.c,
+ native/jni/java-net/javanet.c,
+ native/jni/java-net/javanet.h: Adapted the VM layer code
+ to the new native layer.
+
+ * native/jni/native-lib/cpnet.h
+ (cpnet_addMembership,
+ cpnet_dropMembership,
+ cpnet_getAvailableBytes): Added the declarations of
+ some new functions.
+ (cpnet_newIPV6Address,
+ cpnet_IPV6AddressToBytes,
+ cpnet_bytesToIPV6Address): Implemented.
+ (cpnet_newIPV4Address): Initialize the sin_family field.
+
+2006-01-28 Guilhem Lavaux <guilhem@kaffe.org>
+
* native/target: Removed.
* configure.ac: Removed target from CLASSPATH_INCLUDES and
diff --git a/native/jni/java-io/java_io_VMFile.c b/native/jni/java-io/java_io_VMFile.c
index 2aab58ed4..cb4d25795 100644
--- a/native/jni/java-io/java_io_VMFile.c
+++ b/native/jni/java-io/java_io_VMFile.c
@@ -38,11 +38,13 @@ exception statement from your version. */
/* do not move; needed here because of some macro definitions */
#include <config.h>
+#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <jni.h>
#include <jcl.h>
+#include "cpmath.h"
#include "cpio.h"
#include "cpnative.h"
@@ -320,7 +322,7 @@ Java_java_io_VMFile_isDirectory (JNIEnv * env,
result = cpio_checkType (filename, &entryType);
(*env)->ReleaseStringUTFChars (env, name, filename);
- return ((result == TARGET_NATIVE_OK && entryType == CPFILE_DIRECTORY) ? 1 : 0);
+ return ((result == CPNATIVE_OK && entryType == CPFILE_DIRECTORY) ? 1 : 0);
#else /* not WITHOUT_FILESYSTEM */
return (0);
#endif /* not WITHOUT_FILESYSTEM */
@@ -351,26 +353,26 @@ Java_java_io_VMFile_length (JNIEnv * env,
on failure */
filename = (*env)->GetStringUTFChars (env, name, 0);
if (filename == NULL)
- return CPJLONG0;
+ return CP_JLONG0;
/* open file for reading, get size and close file */
result = cpio_openFile (filename, &tmpfd, CPFILE_FLAG_READ, 0);
if (result != CPNATIVE_OK)
- return CPJLONG0;
+ return CP_JLONG0;
result = cpio_getFileSize (tmpfd, &length);
if (result != CPNATIVE_OK)
{
cpio_closeFile (tmpfd);
- return CPJLONG0;
+ return CP_JLONG0;
}
result = cpio_closeFile (tmpfd);
(*env)->ReleaseStringUTFChars (env, name, filename);
- return (result == CPNATIVE_OK) ? length : CPJLONG0;
+ return (result == CPNATIVE_OK) ? length : CP_JLONG0;
#else /* not WITHOUT_FILESYSTEM */
- return CPJLONG0;
+ return CP_JLONG0;
#endif /* not WITHOUT_FILESYSTEM */
}
@@ -607,7 +609,7 @@ Java_java_io_VMFile_list (JNIEnv * env, jobject obj
(*env)->ReleaseStringUTFChars (env, name, dirname);
- if (result != TARGET_NATIVE_OK)
+ if (result != CPNATIVE_OK)
{
return (0);
}
diff --git a/native/jni/java-net/gnu_java_net_VMPlainDatagramSocketImpl.c b/native/jni/java-net/gnu_java_net_VMPlainDatagramSocketImpl.c
index 1b3cb97e0..e608e1dde 100644
--- a/native/jni/java-net/gnu_java_net_VMPlainDatagramSocketImpl.c
+++ b/native/jni/java-net/gnu_java_net_VMPlainDatagramSocketImpl.c
@@ -45,13 +45,10 @@ exception statement from your version. */
#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 "cpnative.h"
+#include "cpnet.h"
+#include "javanet.h"
#include "gnu_java_net_VMPlainDatagramSocketImpl.h"
@@ -188,8 +185,9 @@ Java_gnu_java_net_VMPlainDatagramSocketImpl_nativeReceive(JNIEnv *env,
jintArray receivedLength)
{
#ifndef WITHOUT_NETWORK
- int addr, *port, *bytes_read;
- char *addressBytes;
+ int *port, *bytes_read;
+ cpnet_address *addr;
+ jbyte *addressBytes;
addr = 0;
@@ -210,13 +208,14 @@ Java_gnu_java_net_VMPlainDatagramSocketImpl_nativeReceive(JNIEnv *env,
/* Receive the packet */
/* should we try some sort of validation on the length? */
- (*bytes_read) = _javanet_recvfrom(env, obj, arr, offset, length, &addr, port);
+ (*bytes_read) = _javanet_recvfrom(env, obj, arr, offset, length, &addr);
/* 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);
@@ -225,6 +224,15 @@ Java_gnu_java_net_VMPlainDatagramSocketImpl_nativeReceive(JNIEnv *env,
return;
}
+ *port = cpnet_addressGetPort (addr);
+
+ /* Store the address */
+ addressBytes = (jbyte*)(*env)->GetPrimitiveArrayCritical(env, receivedFromAddress, NULL);
+ cpnet_IPV4AddressToBytes (addr, addressBytes);
+ (*env)->ReleasePrimitiveArrayCritical(env, receivedFromAddress, addressBytes, 0);
+
+ cpnet_freeAddress (env, addr);
+
(*env)->ReleaseIntArrayElements(env, receivedFromPort, (jint*)port, 0);
(*env)->ReleaseIntArrayElements(env, receivedLength, (jint*)bytes_read, 0);
@@ -235,17 +243,6 @@ Java_gnu_java_net_VMPlainDatagramSocketImpl_nativeReceive(JNIEnv *env,
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 */
}
@@ -266,25 +263,26 @@ Java_gnu_java_net_VMPlainDatagramSocketImpl_nativeSendTo(JNIEnv *env,
jint len)
{
#ifndef WITHOUT_NETWORK
- jint netAddress;
+ cpnet_address *netAddress;
/* check if address given, tr 7.3.2005 */
if (addr != NULL)
{
- netAddress = _javanet_get_netaddr(env, addr);
+ netAddress = _javanet_get_ip_netaddr(env, addr);
if ((*env)->ExceptionOccurred(env))
{
return;
}
+ cpnet_addressSetPort (netAddress, port);
}
else
{
- netAddress = 0;
+ netAddress = NULL;
}
DBG("PlainDatagramSocketImpl.sendto(): have addr\n");
- _javanet_sendto(env, obj, buf, offset, len, netAddress, port);
+ _javanet_sendto(env, obj, buf, offset, len, netAddress);
if ((*env)->ExceptionOccurred(env))
{
return;
@@ -307,14 +305,14 @@ Java_gnu_java_net_VMPlainDatagramSocketImpl_join(JNIEnv *env,
jobject addr)
{
#ifndef WITHOUT_NETWORK
- jint netAddress;
+ cpnet_address *netAddress;
int fd;
int result;
/* check if address given, tr 7.3.2005 */
if (addr != NULL)
{
- netAddress = _javanet_get_netaddr(env, addr);
+ netAddress = _javanet_get_ip_netaddr(env, addr);
if ((*env)->ExceptionOccurred(env))
{
JCL_ThrowException(env, IO_EXCEPTION, "Internal error");
@@ -323,7 +321,7 @@ Java_gnu_java_net_VMPlainDatagramSocketImpl_join(JNIEnv *env,
}
else
{
- netAddress = 0;
+ netAddress = NULL;
}
fd = _javanet_get_int_field(env, obj, "native_fd");
@@ -335,11 +333,11 @@ Java_gnu_java_net_VMPlainDatagramSocketImpl_join(JNIEnv *env,
DBG("PlainDatagramSocketImpl.join(): have native fd\n");
- TARGET_NATIVE_NETWORK_SOCKET_SET_OPTION_ADD_MEMBERSHIP(fd,netAddress,result);
-
- if (result != TARGET_NATIVE_OK)
+ result = cpnet_addMembership (env, fd, netAddress);
+ if (result != CPNATIVE_OK)
{
- JCL_ThrowException(env, IO_EXCEPTION, TARGET_NATIVE_LAST_ERROR_STRING());
+ JCL_ThrowException(env, IO_EXCEPTION,
+ cpnative_getErrorString (result));
return;
}
@@ -360,14 +358,14 @@ Java_gnu_java_net_VMPlainDatagramSocketImpl_leave(JNIEnv *env,
jobject addr)
{
#ifndef WITHOUT_NETWORK
- jint netAddress;
+ cpnet_address *netAddress;
int fd;
int result;
/* check if address given, tr 7.3.2005 */
if (addr != NULL)
{
- netAddress = _javanet_get_netaddr(env, addr);
+ netAddress = _javanet_get_ip_netaddr(env, addr);
if ((*env)->ExceptionOccurred(env))
{
JCL_ThrowException(env, IO_EXCEPTION, "Internal error");
@@ -381,14 +379,17 @@ Java_gnu_java_net_VMPlainDatagramSocketImpl_leave(JNIEnv *env,
fd = _javanet_get_int_field(env, obj, "native_fd");
if ((*env)->ExceptionOccurred(env))
- { JCL_ThrowException(env, IO_EXCEPTION, "Internal error"); return; }
+ {
+ 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)
+ result = cpnet_dropMembership (env, fd, netAddress);
+ if (result != CPNATIVE_OK)
{
- JCL_ThrowException(env, IO_EXCEPTION, TARGET_NATIVE_LAST_ERROR_STRING());
+ JCL_ThrowException(env, IO_EXCEPTION, cpnative_getErrorString (result));
return;
}
diff --git a/native/jni/java-net/gnu_java_net_VMPlainSocketImpl.c b/native/jni/java-net/gnu_java_net_VMPlainSocketImpl.c
index cf10ee4b5..fb9855908 100644
--- a/native/jni/java-net/gnu_java_net_VMPlainSocketImpl.c
+++ b/native/jni/java-net/gnu_java_net_VMPlainSocketImpl.c
@@ -45,13 +45,10 @@ exception statement from your version. */
#include <jni.h>
#include <jcl.h>
+#include <cpnative.h>
+#include <cpnet.h>
#include "javanet.h"
-#include "target_native.h"
-#ifndef WITHOUT_NETWORK
- #include "target_native_network.h"
-#endif /* WITHOUT_NETWORK */
-
#include "gnu_java_net_VMPlainSocketImpl.h"
/*
@@ -194,10 +191,10 @@ Java_gnu_java_net_VMPlainSocketImpl_available(JNIEnv *env,
fd = (*env)->GetIntField(env, obj, fid);
- TARGET_NATIVE_NETWORK_SOCKET_RECEIVE_AVAILABLE(fd,bytesAvailable,result);
- if (result != TARGET_NATIVE_OK)
+ result = cpnet_getAvailableBytes (env, fd, &bytesAvailable);
+ if (result != CPNATIVE_OK)
{
- JCL_ThrowException(env, IO_EXCEPTION, TARGET_NATIVE_LAST_ERROR_STRING());
+ JCL_ThrowException(env, IO_EXCEPTION, cpnative_getErrorString (result));
return 0;
}
@@ -254,7 +251,7 @@ Java_gnu_java_net_VMPlainSocketImpl_read(JNIEnv *env,
jint offset, jint len)
{
#ifndef WITHOUT_NETWORK
- return(_javanet_recvfrom(env, obj, buf, offset, len, 0, 0));
+ return(_javanet_recvfrom(env, obj, buf, offset, len, 0));
#else /* not WITHOUT_NETWORK */
return 0;
#endif /* not WITHOUT_NETWORK */
@@ -272,7 +269,7 @@ Java_gnu_java_net_VMPlainSocketImpl_write(JNIEnv *env,
jint offset, jint len)
{
#ifndef WITHOUT_NETWORK
- _javanet_sendto(env, obj, buf, offset, len, 0, 0);
+ _javanet_sendto(env, obj, buf, offset, len, 0);
#else /* not WITHOUT_NETWORK */
#endif /* not WITHOUT_NETWORK */
}
diff --git a/native/jni/java-net/java_net_VMInetAddress.c b/native/jni/java-net/java_net_VMInetAddress.c
index 86ac06e6f..67849416e 100644
--- a/native/jni/java-net/java_net_VMInetAddress.c
+++ b/native/jni/java-net/java_net_VMInetAddress.c
@@ -45,13 +45,10 @@ exception statement from your version. */
#include <jni.h>
#include <jcl.h>
+#include "cpnative.h"
+#include "cpnet.h"
#include "javanet.h"
-#include "target_native.h"
-#ifndef WITHOUT_NETWORK
-#include "target_native_network.h"
-#endif /* WITHOUT_NETWORK */
-
#include "java_net_VMInetAddress.h"
/*************************************************************************/
@@ -69,8 +66,8 @@ Java_java_net_VMInetAddress_getLocalHostname (JNIEnv * env,
jstring retval;
#ifndef WITHOUT_NETWORK
- TARGET_NATIVE_NETWORK_GET_HOSTNAME (hostname, sizeof (hostname), result);
- if (result != TARGET_NATIVE_OK)
+ result = cpnet_getHostname (hostname, sizeof (hostname));
+ if (result != CPNATIVE_OK)
{
strcpy (hostname, "localhost");
}
@@ -138,14 +135,14 @@ Java_java_net_VMInetAddress_getHostByAddr (JNIEnv * env,
#ifndef WITHOUT_NETWORK
jbyte *octets;
jsize len;
- int addr;
+ cpnet_address *addr;
char hostname[255];
int result;
jstring retval;
/* Grab the byte[] array with the IP out of the input data */
len = (*env)->GetArrayLength (env, arr);
- if (len != 4)
+ if (len != 4 && len != 16)
{
JCL_ThrowException (env, UNKNOWN_HOST_EXCEPTION, "Bad IP Address");
return (jstring) NULL;
@@ -158,21 +155,31 @@ Java_java_net_VMInetAddress_getHostByAddr (JNIEnv * env,
return (jstring) NULL;
}
- /* Convert it to a 32 bit address */
- TARGET_NATIVE_NETWORK_IPADDRESS_BYTES_TO_INT (octets[0],
- octets[1],
- octets[2], octets[3], addr);
+ switch (len)
+ {
+ case 4:
+ addr = cpnet_newIPV4Address(env);
+ cpnet_bytesToIPV4Address (octets, addr);
+ break;
+ case 16:
+ addr = cpnew_newIPV6Address(env);
+ cpnet_bytesToIPV6Address (octets, addr);
+ break;
+ default:
+ JCL_ThrowException (env, UNKNOWN_HOST_EXCEPTION, "Bad IP Address");
+ return (jstring) NULL;
+
+ }
/* Release some memory */
(*env)->ReleaseByteArrayElements (env, arr, octets, 0);
/* Resolve the address and return the name */
- TARGET_NATIVE_NETWORK_GET_HOSTNAME_BY_ADDRESS (addr, hostname,
- sizeof (hostname), result);
- if (result != TARGET_NATIVE_OK)
+ result = cpnet_getHostByAddr (addr, hostname, sizeof (hostname));
+ if (result != CPNATIVE_OK)
{
JCL_ThrowException (env, UNKNOWN_HOST_EXCEPTION,
- TARGET_NATIVE_LAST_ERROR_STRING ());
+ cpnative_getErrorString (result));
return (jstring) NULL;
}
@@ -218,7 +225,7 @@ Java_java_net_VMInetAddress_getHostByName (JNIEnv * env,
addresses,
max_addresses,
addresses_count, result);
- if (result != TARGET_NATIVE_OK)
+ if (result != CPNATIVE_OK)
{
JCL_ThrowException (env, UNKNOWN_HOST_EXCEPTION, (char *) hostname);
return (jobjectArray) NULL;
diff --git a/native/jni/java-net/javanet.c b/native/jni/java-net/javanet.c
index 5ecf8bebd..f7a64e7de 100644
--- a/native/jni/java-net/javanet.c
+++ b/native/jni/java-net/javanet.c
@@ -45,12 +45,10 @@ exception statement from your version. */
#include <jni.h>
#include <jcl.h>
-#include "javanet.h"
+#include "cpnative.h"
+#include "cpnet.h"
-#include "target_native.h"
-#ifndef WITHOUT_NETWORK
-#include "target_native_network.h"
-#endif /* WITHOUT_NETWORK */
+#include "javanet.h"
#ifndef WITHOUT_NETWORK
/* Need to have some value for SO_TIMEOUT */
@@ -235,7 +233,7 @@ _javanet_create_integer (JNIEnv * env, jint val)
* Builds an InetAddress object from a 32 bit address in host byte order
*/
static jobject
-_javanet_create_inetaddress (JNIEnv * env, int netaddr)
+_javanet_create_inetaddress (JNIEnv * env, cpnet_address *netaddr)
{
#ifndef WITHOUT_NETWORK
unsigned char octets[4];
@@ -246,7 +244,7 @@ _javanet_create_inetaddress (JNIEnv * env, int netaddr)
jobject ia;
/* Build a string IP address */
- cpnet_netaddrToBytes(netaddr, octets);
+ cpnet_IPV4AddressToBytes(netaddr, octets);
sprintf (buf, "%d.%d.%d.%d", octets[0], octets[1], octets[2], octets[3]);
DBG ("_javanet_create_inetaddress(): Created ip addr string\n");
@@ -317,7 +315,7 @@ _javanet_set_remhost_addr (JNIEnv * env, jobject this, jobject ia)
* InetAddress for the specified addr
*/
static void
-_javanet_set_remhost (JNIEnv * env, jobject this, int netaddr)
+_javanet_set_remhost (JNIEnv * env, jobject this, cpnet_address *netaddr)
{
jobject ia;
@@ -345,9 +343,10 @@ _javanet_get_ip_netaddr (JNIEnv * env, jobject addr)
jmethodID mid;
jarray arr = 0;
jbyte *octets;
- cpnet_address *netaddr, len;
+ cpnet_address *netaddr;
+ jint len;
- DBG ("_javanet_get_netaddr(): Entered _javanet_get_netaddr\n");
+ DBG ("_javanet_get_ip_netaddr(): Entered _javanet_get_ip_netaddr\n");
if (addr == NULL)
{
@@ -365,13 +364,13 @@ _javanet_get_ip_netaddr (JNIEnv * env, jobject addr)
if (mid == NULL)
return 0;
- DBG ("_javanet_get_netaddr(): Got getAddress method\n");
+ DBG ("_javanet_get_ip_netaddr(): Got getAddress method\n");
arr = (*env)->CallObjectMethod (env, addr, mid);
if (arr == NULL)
return 0;
- DBG ("_javanet_get_netaddr(): Got the address\n");
+ DBG ("_javanet_get_ip_netaddr(): Got the address\n");
/* Turn the IP address into a system cpnet address.
* If the length is 4 then it is an IPV4 address, if it
@@ -382,28 +381,34 @@ _javanet_get_ip_netaddr (JNIEnv * env, jobject addr)
JCL_ThrowException (env, IO_EXCEPTION, "Internal Error");
return 0;
}
- DBG ("_javanet_get_netaddr(): Length ok\n");
+ DBG ("_javanet_get_ip_netaddr(): Length ok\n");
octets = (*env)->GetByteArrayElements (env, arr, 0);
if (octets == NULL)
return 0;
- DBG ("_javanet_get_netaddr(): Grabbed bytes\n");
+ DBG ("_javanet_get_ip_netaddr(): Grabbed bytes\n");
switch (len)
{
case 4:
netaddr = cpnet_newIPV4Address(env);
- cpnet_bytesToIPV4netaddr(octets, netaddr);
+ cpnet_bytesToIPV4Address(netaddr, octets);
break;
case 16:
netaddr = cpnet_newIPV6Address(env);
- cpnet_bytesToIPV6netaddr(octets, netaddr);
+ cpnet_bytesToIPV6Address(netaddr, octets);
break;
+ default:
+ /* This should not happen as we have checked before.
+ * But that way we shut the compiler warnings */
+ JCL_ThrowException (env, IO_EXCEPTION, "Internal Error");
+ return 0;
+
}
(*env)->ReleaseByteArrayElements (env, arr, octets, 0);
- DBG ("_javanet_get_netaddr(): Done getting addr\n");
+ DBG ("_javanet_get_ip_netaddr(): Done getting addr\n");
return netaddr;
#else /* not WITHOUT_NETWORK */
@@ -425,7 +430,7 @@ _javanet_create (JNIEnv * env, jobject this, jboolean stream)
if (stream)
{
/* create a stream socket */
- result = cpnet_openSocketStream(&fd);
+ result = cpnet_openSocketStream(env, &fd);
if (result != CPNATIVE_OK)
{
JCL_ThrowException (env, IO_EXCEPTION,
@@ -436,14 +441,14 @@ _javanet_create (JNIEnv * env, jobject this, jboolean stream)
else
{
/* create a datagram socket, set broadcast option */
- result = cpnet_openSocketDatagram (&fd);
+ result = cpnet_openSocketDatagram (env, &fd);
if (result != CPNATIVE_OK)
{
JCL_ThrowException (env, IO_EXCEPTION,
cpnative_getErrorString (result));
return;
}
- result = cpnet_setBroadcast(fd, 1);
+ result = cpnet_setBroadcast(env, fd, 1);
if (result != CPNATIVE_OK)
{
JCL_ThrowException (env, IO_EXCEPTION,
@@ -464,7 +469,7 @@ _javanet_create (JNIEnv * env, jobject this, jboolean stream)
/* Try to make sure we close the socket since close() won't work. */
do
{
- result = cpnet_close(fd);
+ result = cpnet_close(env, fd);
if (result != CPNATIVE_OK && result != CPNATIVE_EINTR)
return;
}
@@ -502,7 +507,7 @@ _javanet_close (JNIEnv * env, jobject this, int stream)
"native_fd", -1);
do
{
- result = cpnet_close (fd);
+ result = cpnet_close (env, fd);
if (result != CPNATIVE_OK)
{
/* Only throw an error when a "real" error occurs. */
@@ -531,12 +536,12 @@ _javanet_connect (JNIEnv * env, jobject this, jobject addr, jint port,
int fd;
int result;
cpnet_address *local_addr;
- int remote_address, remote_port;
+ cpnet_address *remote_addr;
DBG ("_javanet_connect(): Entered _javanet_connect\n");
/* Pre-process input variables */
- netaddr = _javanet_get_netaddr (env, addr);
+ netaddr = _javanet_get_ip_netaddr (env, addr);
if ((*env)->ExceptionOccurred (env))
return;
@@ -560,7 +565,7 @@ _javanet_connect (JNIEnv * env, jobject this, jobject addr, jint port,
/* Connect up */
do
{
- result = cpnet_connect (fd, netaddr);
+ result = cpnet_connect (env, fd, netaddr);
if (result != CPNATIVE_OK && result != CPNATIVE_EINTR)
{
JCL_ThrowException (env, IO_EXCEPTION,
@@ -575,13 +580,13 @@ _javanet_connect (JNIEnv * env, jobject this, jobject addr, jint port,
DBG ("_javanet_connect(): Connected successfully\n");
/* Populate instance variables */
- result = cpnet_getLocalAddr (fd, &local_addr);
+ result = cpnet_getLocalAddr (env, fd, &local_addr);
if (result != CPNATIVE_OK)
{
JCL_ThrowException (env, IO_EXCEPTION,
cpnative_getErrorString (result));
/* We don't care whether this succeeds. close() will cleanup later. */
- cpnet_close (fd);
+ cpnet_close (env, fd);
return;
}
@@ -590,7 +595,7 @@ _javanet_connect (JNIEnv * env, jobject this, jobject addr, jint port,
{
/* We don't care whether this succeeds. close() will cleanup later. */
cpnet_freeAddress(env, local_addr);
- cpnet_close (fd);
+ cpnet_close (env, fd);
return;
}
DBG ("_javanet_connect(): Created fd\n");
@@ -602,22 +607,22 @@ _javanet_connect (JNIEnv * env, jobject this, jobject addr, jint port,
_javanet_set_int_field (env, this, "java/net/DatagramSocketImpl",
"localPort", cpnet_addressGetPort(local_addr));
- cpnet_freeAddress (env, fd);
+ cpnet_freeAddress (env, local_addr);
if ((*env)->ExceptionOccurred (env))
{
/* We don't care whether this succeeds. close() will cleanup later. */
- cpnet_close (fd);
+ cpnet_close (env, fd);
return;
}
DBG ("_javanet_connect(): Set the local port\n");
- result = cpnet_getRemoteAddr (fd, &remote_addr);
+ result = cpnet_getRemoteAddr (env, fd, &remote_addr);
if (result != CPNATIVE_OK)
{
JCL_ThrowException (env, IO_EXCEPTION,
cpnative_getErrorString (result));
/* We don't care whether this succeeds. close() will cleanup later. */
- cpnet_close (fd);
+ cpnet_close (env, fd);
return;
}
@@ -636,8 +641,8 @@ _javanet_connect (JNIEnv * env, jobject this, jobject addr, jint port,
{
/* We don't care whether this succeeds. close() will cleanup later.
*/
- cpnet_freeAddress (env, fd);
- cpnet_close (fd);
+ cpnet_freeAddress (env, remote_addr);
+ cpnet_close (env, fd);
return;
}
DBG ("_javanet_connect(): Set the remote host\n");
@@ -650,7 +655,7 @@ _javanet_connect (JNIEnv * env, jobject this, jobject addr, jint port,
{
/* We don't care whether this succeeds. close() will cleanup later.
*/
- cpnet_close (fd);
+ cpnet_close (env, fd);
return;
}
DBG ("_javanet_connect(): Set the remote port\n");
@@ -671,98 +676,64 @@ _javanet_bind (JNIEnv * env, jobject this, jobject addr, jint port,
int stream)
{
#ifndef WITHOUT_NETWORK
- jclass cls;
- jmethodID mid;
jbyteArray arr = 0;
jbyte *octets;
jint fd;
- int tmpaddr;
+ cpnet_address *tmpaddr;
+ cpnet_address *local_addr;
int result;
- int local_address, local_port;
DBG ("_javanet_bind(): Entering native bind()\n");
-
- /* Get the address to connect to */
- cls = (*env)->GetObjectClass (env, addr);
- if (cls == NULL)
- return;
-
- mid = (*env)->GetMethodID (env, cls, "getAddress", "()[B");
- if (mid == NULL)
- return;
-
- DBG ("_javanet_bind(): Past getAddress method id\n");
-
- arr = (*env)->CallObjectMethod (env, addr, mid);
- if ((arr == NULL) || (*env)->ExceptionOccurred (env))
- {
- JCL_ThrowException (env, IO_EXCEPTION,
- "Internal error: _javanet_bind()");
- return;
- }
-
- DBG ("_javanet_bind(): Past call object method\n");
-
- octets = (*env)->GetByteArrayElements (env, arr, 0);
- if (octets == NULL)
- return;
-
- DBG ("_javanet_bind(): Past grab array\n");
-
- /* Get the native socket file descriptor */
+
+ /* Grab the real socket file descriptor */
fd = _javanet_get_int_field (env, this, "native_fd");
if (fd == -1)
{
- (*env)->ReleaseByteArrayElements (env, arr, octets, 0);
JCL_ThrowException (env, IO_EXCEPTION,
- "Internal error: _javanet_bind(): no native file descriptor");
+ "Internal error: _javanet_connect(): no native file descriptor");
return;
}
- DBG ("_javanet_bind(): Past native_fd lookup\n");
- /* XXX NYI ??? */
- _javanet_set_option (env, this, SOCKOPT_SO_REUSEADDR,
- _javanet_create_boolean (env, JNI_TRUE));
-
-
- /* Bind the socket */
- TARGET_NATIVE_NETWORK_IPADDRESS_BYTES_TO_INT (octets[0],
- octets[1],
- octets[2],
- octets[3], tmpaddr);
- TARGET_NATIVE_NETWORK_SOCKET_BIND (fd, tmpaddr, port, result);
+ /* Get the address to connect to */
+ tmpaddr = _javanet_get_ip_netaddr (env, addr);
+ if ((*env)->ExceptionOccurred (env))
+ return;
- if (result != TARGET_NATIVE_OK)
+ cpnet_addressSetPort (tmpaddr, port);
+ result = cpnet_bind(env, fd, tmpaddr);
+ cpnet_freeAddress (env, tmpaddr);
+ if (result != CPNATIVE_OK)
{
- char *errorstr = TARGET_NATIVE_LAST_ERROR_STRING ();
(*env)->ReleaseByteArrayElements (env, arr, octets, 0);
JCL_ThrowException (env, BIND_EXCEPTION,
- errorstr);
+ cpnative_getErrorString (result));
return;
}
DBG ("_javanet_bind(): Past bind\n");
+
(*env)->ReleaseByteArrayElements (env, arr, octets, 0);
/* Update instance variables, specifically the local port number */
- TARGET_NATIVE_NETWORK_SOCKET_GET_LOCAL_INFO (fd, local_address, local_port,
- result);
- if (result != TARGET_NATIVE_OK)
+ result = cpnet_getLocalAddr (env, fd, &local_addr);
+ if (result != CPNATIVE_OK)
{
JCL_ThrowException (env, IO_EXCEPTION,
- TARGET_NATIVE_LAST_ERROR_STRING ());
+ cpnative_getErrorString (result));
return;
}
if (stream)
_javanet_set_int_field (env, this, "java/net/SocketImpl",
- "localport", local_port);
+ "localport", cpnet_addressGetPort (local_addr));
else
_javanet_set_int_field (env, this, "java/net/DatagramSocketImpl",
- "localPort", local_port);
+ "localPort", cpnet_addressGetPort (local_addr));
DBG ("_javanet_bind(): Past update port number\n");
+ cpnet_freeAddress (env, local_addr);
+
return;
#else /* not WITHOUT_NETWORK */
#endif /* not WITHOUT_NETWORK */
@@ -791,11 +762,11 @@ _javanet_listen (JNIEnv * env, jobject this, jint queuelen)
}
/* Start listening */
- TARGET_NATIVE_NETWORK_SOCKET_LISTEN (fd, queuelen, result);
- if (result != TARGET_NATIVE_OK)
+ result = cpnet_listen (env, fd, queuelen);
+ if (result != CPNATIVE_OK)
{
JCL_ThrowException (env, IO_EXCEPTION,
- TARGET_NATIVE_LAST_ERROR_STRING ());
+ cpnative_getErrorString (result));
return;
}
#else /* not WITHOUT_NETWORK */
@@ -814,8 +785,7 @@ _javanet_accept (JNIEnv * env, jobject this, jobject impl)
#ifndef WITHOUT_NETWORK
int fd, newfd;
int result;
- int local_address, local_port;
- int remote_address, remote_port;
+ cpnet_address *remote_addr, *local_addr;
/* Get the real file descriptor */
fd = _javanet_get_int_field (env, this, "native_fd");
@@ -829,21 +799,19 @@ _javanet_accept (JNIEnv * env, jobject this, jobject impl)
/* Accept the connection */
do
{
- TARGET_NATIVE_NETWORK_SOCKET_ACCEPT (fd, newfd, result);
- if (result != TARGET_NATIVE_OK
- && (TARGET_NATIVE_LAST_ERROR ()
- != TARGET_NATIVE_ERROR_INTERRUPT_FUNCTION_CALL))
+ result = cpnet_accept (env, fd, &newfd);
+ if (result != CPNATIVE_OK && result != CPNATIVE_EINTR)
{
- if (TARGET_NATIVE_LAST_ERROR () == EAGAIN)
+ if (result == EAGAIN)
JCL_ThrowException (env, "java/net/SocketTimeoutException",
"Timeout");
else
JCL_ThrowException (env, IO_EXCEPTION,
- TARGET_NATIVE_LAST_ERROR_STRING ());
+ cpnative_getErrorString (result));
return;
}
}
- while (result != TARGET_NATIVE_OK);
+ while (result != CPNATIVE_OK);
/* Populate instance variables */
_javanet_set_int_field (env, impl, "gnu/java/net/PlainSocketImpl",
@@ -854,24 +822,21 @@ _javanet_accept (JNIEnv * env, jobject this, jobject impl)
/* Try to make sure we close the socket since close() won't work. */
do
{
- TARGET_NATIVE_NETWORK_SOCKET_CLOSE (newfd, result);
- if (result != TARGET_NATIVE_OK
- && (TARGET_NATIVE_LAST_ERROR ()
- != TARGET_NATIVE_ERROR_INTERRUPT_FUNCTION_CALL))
+ result = cpnet_close (env, newfd);
+ if (result != CPNATIVE_OK && result != CPNATIVE_EINTR)
return;
}
- while (result != TARGET_NATIVE_OK);
+ while (result != CPNATIVE_OK);
return;
}
- TARGET_NATIVE_NETWORK_SOCKET_GET_LOCAL_INFO (newfd, local_address,
- local_port, result);
- if (result != TARGET_NATIVE_OK)
+ result = cpnet_getLocalAddr (env, newfd, &local_addr);
+ if (result != CPNATIVE_OK)
{
/* We don't care whether this succeeds. close() will cleanup later. */
- TARGET_NATIVE_NETWORK_SOCKET_CLOSE (newfd, result);
+ cpnet_close (env, newfd);
JCL_ThrowException (env, IO_EXCEPTION,
- TARGET_NATIVE_LAST_ERROR_STRING ());
+ cpnative_getErrorString (result));
return;
}
@@ -879,44 +844,47 @@ _javanet_accept (JNIEnv * env, jobject this, jobject impl)
if ((*env)->ExceptionOccurred (env))
{
/* We don't care whether this succeeds. close() will cleanup later. */
- TARGET_NATIVE_NETWORK_SOCKET_CLOSE (newfd, result);
+ cpnet_freeAddress (env, local_addr);
+ cpnet_close (env, newfd);
return;
}
_javanet_set_int_field (env, impl, "java/net/SocketImpl", "localport",
- local_port);
+ cpnet_addressGetPort (local_addr));
+ cpnet_freeAddress (env, local_addr);
if ((*env)->ExceptionOccurred (env))
{
/* We don't care whether this succeeds. close() will cleanup later. */
- TARGET_NATIVE_NETWORK_SOCKET_CLOSE (newfd, result);
+ cpnet_close (env, newfd);
return;
}
- TARGET_NATIVE_NETWORK_SOCKET_GET_REMOTE_INFO (newfd, remote_address,
- remote_port, result);
- if (result != TARGET_NATIVE_OK)
+ result = cpnet_getRemoteAddr (env, newfd, &remote_addr);
+ if (result != CPNATIVE_OK)
{
JCL_ThrowException (env, IO_EXCEPTION,
- TARGET_NATIVE_LAST_ERROR_STRING ());
+ cpnative_getErrorString (result));
/* We don't care whether this succeeds. close() will cleanup later. */
- TARGET_NATIVE_NETWORK_SOCKET_CLOSE (newfd, result);
+ cpnet_close (env, newfd);
return;
}
- _javanet_set_remhost (env, impl, remote_address);
+ _javanet_set_remhost (env, impl, remote_addr);
if ((*env)->ExceptionOccurred (env))
{
/* We don't care whether this succeeds. close() will cleanup later. */
- TARGET_NATIVE_NETWORK_SOCKET_CLOSE (newfd, result);
+ cpnet_close (env, newfd);
+ cpnet_freeAddress (env, remote_addr);
return;
}
_javanet_set_int_field (env, impl, "java/net/SocketImpl", "port",
- remote_port);
+ cpnet_addressGetPort (remote_addr));
+ cpnet_freeAddress (env, remote_addr);
if ((*env)->ExceptionOccurred (env))
{
/* We don't care whether this succeeds. close() will cleanup later. */
- TARGET_NATIVE_NETWORK_SOCKET_CLOSE (newfd, result);
+ cpnet_close (env, newfd);
return;
}
#else /* not WITHOUT_NETWORK */
@@ -941,13 +909,14 @@ _javanet_accept (JNIEnv * env, jobject this, jobject impl)
*/
int
_javanet_recvfrom (JNIEnv * env, jobject this, jarray buf, int offset,
- int len, int *addr, int *port)
+ int len, cpnet_address **addr)
{
#ifndef WITHOUT_NETWORK
int fd;
jbyte *p;
- int from_address, from_port;
- int received_bytes;
+ cpnet_address *from_addr;
+ jint received_bytes;
+ int result;
DBG ("_javanet_recvfrom(): Entered _javanet_recvfrom\n");
@@ -969,36 +938,28 @@ _javanet_recvfrom (JNIEnv * env, jobject this, jarray buf, int offset,
DBG ("_javanet_recvfrom(): Got buffer\n");
/* Read the data */
- from_address = 0;
- from_port = 0;
+ from_addr = NULL;
do
{
if (addr != NULL)
{
- TARGET_NATIVE_NETWORK_SOCKET_RECEIVE_WITH_ADDRESS_PORT (fd,
- p + offset,
- len,
- from_address,
- from_port,
- received_bytes);
+ result = cpnet_recvFrom (env, fd, p + offset, len, &from_addr, &received_bytes);
}
else
{
- TARGET_NATIVE_NETWORK_SOCKET_RECEIVE (fd, p + offset, len,
- received_bytes);
+ result = cpnet_recv (env, fd, p + offset, len, &received_bytes);
}
}
while ((received_bytes == -1) &&
- (TARGET_NATIVE_LAST_ERROR () ==
- TARGET_NATIVE_ERROR_INTERRUPT_FUNCTION_CALL));
+ (result == CPNATIVE_EINTR));
if (received_bytes == -1)
{
- if (TARGET_NATIVE_LAST_ERROR () == EAGAIN)
+ if (result == EAGAIN)
JCL_ThrowException (env, "java/net/SocketTimeoutException", "Timeout");
else
JCL_ThrowException (env, IO_EXCEPTION,
- TARGET_NATIVE_LAST_ERROR_STRING ());
+ cpnative_getErrorString (result));
/* Cleanup and return. */
(*env)->ReleaseByteArrayElements (env, buf, p, 0);
@@ -1010,9 +971,7 @@ _javanet_recvfrom (JNIEnv * env, jobject this, jarray buf, int offset,
/* Handle return addr case */
if (addr != NULL)
{
- (*addr) = from_address;
- if (port != NULL)
- (*port) = from_port;
+ (*addr) = from_addr;
}
/* zero bytes received means recv() noticed the other side orderly
@@ -1038,12 +997,13 @@ _javanet_recvfrom (JNIEnv * env, jobject this, jarray buf, int offset,
*/
void
_javanet_sendto (JNIEnv * env, jobject this, jarray buf, int offset, int len,
- int addr, int port)
+ cpnet_address *addr)
{
#ifndef WITHOUT_NETWORK
int fd;
jbyte *p;
- int bytes_sent;
+ jint bytes_sent;
+ int result;
/* Get the real file descriptor */
fd = _javanet_get_int_field (env, this, "native_fd");
@@ -1066,23 +1026,20 @@ _javanet_sendto (JNIEnv * env, jobject this, jarray buf, int offset, int len,
if (addr == 0)
{
DBG ("_javanet_sendto(): Sending....\n");
- TARGET_NATIVE_NETWORK_SOCKET_SEND (fd, p + offset, len, bytes_sent);
+ result = cpnet_send (env, fd, p + offset, len, &bytes_sent);
}
else
{
DBG ("_javanet_sendto(): Sending....\n");
- TARGET_NATIVE_NETWORK_SOCKET_SEND_WITH_ADDRESS_PORT (fd, p + offset,
- len, addr, port,
- bytes_sent);
+ result = cpnet_sendTo (env, fd, p + offset, len, addr, &bytes_sent);
}
if (bytes_sent < 0)
{
- if (TARGET_NATIVE_LAST_ERROR ()
- != TARGET_NATIVE_ERROR_INTERRUPT_FUNCTION_CALL)
+ if (result != CPNATIVE_EINTR)
{
JCL_ThrowException (env, IO_EXCEPTION,
- TARGET_NATIVE_LAST_ERROR_STRING ());
+ cpnative_getErrorString (result));
break;
}
}
@@ -1112,8 +1069,8 @@ _javanet_set_option (JNIEnv * env, jobject this, jint option_id, jobject val)
int optval;
jclass cls;
jmethodID mid;
- int address;
- int result;
+ cpnet_address * address;
+ int result = CPNATIVE_OK;
/* Get the real file descriptor */
fd = _javanet_get_int_field (env, this, "native_fd");
@@ -1130,7 +1087,6 @@ _javanet_set_option (JNIEnv * env, jobject this, jint option_id, jobject val)
return;
/* Process the option request */
- result = TARGET_NATIVE_ERROR;
switch (option_id)
{
/* TCP_NODELAY case. val is a Boolean that tells us what to do */
@@ -1148,8 +1104,7 @@ _javanet_set_option (JNIEnv * env, jobject this, jint option_id, jobject val)
if ((*env)->ExceptionOccurred (env))
return;
- TARGET_NATIVE_NETWORK_SOCKET_SET_OPTION_TCP_NODELAY (fd, optval,
- result);
+ result = cpnet_setSocketTCPNoDelay (env, fd, optval);
break;
/* SO_LINGER case. If val is a boolean, then it will always be set
@@ -1160,8 +1115,7 @@ _javanet_set_option (JNIEnv * env, jobject this, jint option_id, jobject val)
if (mid)
{
/* We are disabling linger */
- TARGET_NATIVE_NETWORK_SOCKET_SET_OPTION_SO_LINGER (fd, 1, 0,
- result);
+ result = cpnet_setLinger (env, fd, JNI_FALSE, 0);
}
else
{
@@ -1182,15 +1136,13 @@ _javanet_set_option (JNIEnv * env, jobject this, jint option_id, jobject val)
if ((*env)->ExceptionOccurred (env))
return;
- TARGET_NATIVE_NETWORK_SOCKET_SET_OPTION_SO_LINGER (fd, 0, optval,
- result);
+ result = cpnet_setLinger(env, fd, JNI_TRUE, optval);
}
break;
/* SO_TIMEOUT case. Val will be an integer with the new value */
/* Not writable on Linux */
case SOCKOPT_SO_TIMEOUT:
-#ifdef SO_TIMEOUT
mid = (*env)->GetMethodID (env, cls, "intValue", "()I");
if (mid == NULL)
{
@@ -1203,10 +1155,7 @@ _javanet_set_option (JNIEnv * env, jobject this, jint option_id, jobject val)
if ((*env)->ExceptionOccurred (env))
return;
- TARGET_NATIVE_NETWORK_SOCKET_SET_OPTION_SO_TIMEOUT (fd, optval, result);
-#else
- result = TARGET_NATIVE_OK;
-#endif
+ result = cpnet_setSocketTimeout (env, fd, optval);
break;
case SOCKOPT_SO_SNDBUF:
@@ -1225,11 +1174,9 @@ _javanet_set_option (JNIEnv * env, jobject this, jint option_id, jobject val)
return;
if (option_id == SOCKOPT_SO_SNDBUF)
- TARGET_NATIVE_NETWORK_SOCKET_SET_OPTION_SO_SNDBUF (fd, optval,
- result);
+ result = cpnet_setSendBuf (env, fd, optval);
else
- TARGET_NATIVE_NETWORK_SOCKET_SET_OPTION_SO_RCDBUF (fd, optval,
- result);
+ result = cpnet_setRecvBuf (env, fd, optval);
break;
/* TTL case. Val with be an Integer with the new time to live value */
@@ -1246,18 +1193,18 @@ _javanet_set_option (JNIEnv * env, jobject this, jint option_id, jobject val)
if ((*env)->ExceptionOccurred (env))
return;
- TARGET_NATIVE_NETWORK_SOCKET_SET_OPTION_IP_TTL (fd, optval, result);
+ result = cpnet_setTTL (env, fd, optval);
break;
/* Multicast Interface case - val is InetAddress object */
case SOCKOPT_IP_MULTICAST_IF:
- address = _javanet_get_netaddr (env, val);
+ address = _javanet_get_ip_netaddr (env, val);
if ((*env)->ExceptionOccurred (env))
return;
-
- TARGET_NATIVE_NETWORK_SOCKET_SET_OPTION_IP_MULTICAST_IF (fd, address,
- result);
+
+ result = cpnet_setMulticastIF (env, fd, address);
+ cpnet_freeAddress (env, address);
break;
case SOCKOPT_SO_REUSEADDR:
@@ -1274,8 +1221,7 @@ _javanet_set_option (JNIEnv * env, jobject this, jint option_id, jobject val)
if ((*env)->ExceptionOccurred (env))
return;
- TARGET_NATIVE_NETWORK_SOCKET_SET_OPTION_REUSE_ADDRESS (fd, optval,
- result);
+ result = cpnet_setReuseAddress (env, fd, optval);
break;
case SOCKOPT_SO_KEEPALIVE:
@@ -1292,7 +1238,7 @@ _javanet_set_option (JNIEnv * env, jobject this, jint option_id, jobject val)
if ((*env)->ExceptionOccurred (env))
return;
- TARGET_NATIVE_NETWORK_SOCKET_SET_OPTION_KEEP_ALIVE (fd, optval, result);
+ result = cpnet_setKeepAlive (env, fd, optval);
break;
case SOCKOPT_SO_BINDADDR:
@@ -1305,10 +1251,10 @@ _javanet_set_option (JNIEnv * env, jobject this, jint option_id, jobject val)
}
/* Check to see if above operations succeeded */
- if (result != TARGET_NATIVE_OK)
+ if (result != CPNATIVE_OK)
{
JCL_ThrowException (env, SOCKET_EXCEPTION,
- TARGET_NATIVE_LAST_ERROR_STRING ());
+ cpnative_getErrorString (result));
return;
}
#else /* not WITHOUT_NETWORK */
@@ -1326,8 +1272,9 @@ _javanet_get_option (JNIEnv * env, jobject this, jint option_id)
#ifndef WITHOUT_NETWORK
int fd;
int flag, optval;
- int address;
+ cpnet_address *address;
int result;
+ jobject obj;
/* Get the real file descriptor */
fd = _javanet_get_int_field (env, this, "native_fd");
@@ -1343,12 +1290,11 @@ _javanet_get_option (JNIEnv * env, jobject this, jint option_id)
{
/* TCP_NODELAY case. Return a Boolean indicating on or off */
case SOCKOPT_TCP_NODELAY:
- TARGET_NATIVE_NETWORK_SOCKET_GET_OPTION_TCP_NODELAY (fd, optval,
- result);
- if (result != TARGET_NATIVE_OK)
+ result = cpnet_getSocketTCPNoDelay (env, fd, &optval);
+ if (result != CPNATIVE_OK)
{
JCL_ThrowException (env, SOCKET_EXCEPTION,
- TARGET_NATIVE_LAST_ERROR_STRING ());
+ cpnative_getErrorString (result));
return (0);
}
@@ -1362,17 +1308,17 @@ _javanet_get_option (JNIEnv * env, jobject this, jint option_id)
/* SO_LINGER case. If disabled, return a Boolean object that represents
false, else return an Integer that is the value of SO_LINGER */
case SOCKOPT_SO_LINGER:
- TARGET_NATIVE_NETWORK_SOCKET_GET_OPTION_SO_LINGER (fd, flag, optval,
- result);
- if (result != TARGET_NATIVE_OK)
+ result = cpnet_getLinger (env, fd, &flag, &optval);
+
+ if (result != CPNATIVE_OK)
{
JCL_ThrowException (env, SOCKET_EXCEPTION,
- TARGET_NATIVE_LAST_ERROR_STRING ());
+ cpnative_getErrorString (result));
return (0);
}
- if (optval)
- return (_javanet_create_integer (env, JNI_TRUE));
+ if (flag)
+ return (_javanet_create_integer (env, optval));
else
return (_javanet_create_boolean (env, JNI_FALSE));
@@ -1380,34 +1326,27 @@ _javanet_get_option (JNIEnv * env, jobject this, jint option_id)
/* SO_TIMEOUT case. Return an Integer object with the timeout value */
case SOCKOPT_SO_TIMEOUT:
-#ifdef SO_TIMEOUT
- TARGET_NATIVE_NETWORK_SOCKET_GET_OPTION_SO_TIMEOUT (fd, optval, result);
- if (result != TARGET_NATIVE_OK)
+ result = cpnet_getSocketTimeout (env, fd, &optval);
+ if (result != CPNATIVE_OK)
{
JCL_ThrowException (env, SOCKET_EXCEPTION,
- TARGET_NATIVE_LAST_ERROR_STRING ());
+ cpnative_getErrorString (result));
return (0);
}
return (_javanet_create_integer (env, optval));
-#else
- JCL_ThrowException (env, SOCKET_EXCEPTION,
- "SO_TIMEOUT not supported on this platform");
- return (0);
-#endif /* not SO_TIMEOUT */
break;
case SOCKOPT_SO_SNDBUF:
case SOCKOPT_SO_RCVBUF:
if (option_id == SOCKOPT_SO_SNDBUF)
- TARGET_NATIVE_NETWORK_SOCKET_GET_OPTION_SO_SNDBUF (fd, optval,
- result);
+ result = cpnet_getSendBuf (env, fd, &optval);
else
- TARGET_NATIVE_NETWORK_SOCKET_GET_OPTION_SO_RCDBUF (fd, optval,
- result);
- if (result != TARGET_NATIVE_OK)
+ result = cpnet_getRecvBuf (env, fd, &optval);
+
+ if (result != CPNATIVE_OK)
{
JCL_ThrowException (env, SOCKET_EXCEPTION,
- TARGET_NATIVE_LAST_ERROR_STRING ());
+ cpnative_getErrorString (result));
return (0);
}
@@ -1416,11 +1355,11 @@ _javanet_get_option (JNIEnv * env, jobject this, jint option_id)
/* The TTL case. Return an Integer with the Time to Live value */
case SOCKOPT_IP_TTL:
- TARGET_NATIVE_NETWORK_SOCKET_GET_OPTION_IP_TTL (fd, optval, result);
- if (result != TARGET_NATIVE_OK)
+ result = cpnet_getTTL (env, fd, &optval);
+ if (result != CPNATIVE_OK)
{
JCL_ThrowException (env, SOCKET_EXCEPTION,
- TARGET_NATIVE_LAST_ERROR_STRING ());
+ cpnative_getErrorString (result));
return (0);
}
@@ -1429,61 +1368,64 @@ _javanet_get_option (JNIEnv * env, jobject this, jint option_id)
/* Multicast interface case */
case SOCKOPT_IP_MULTICAST_IF:
- TARGET_NATIVE_NETWORK_SOCKET_GET_OPTION_IP_MULTICAST_IF (fd, address,
- result);
- if (result != TARGET_NATIVE_OK)
+ result = cpnet_getMulticastIF (env, fd, &address);
+ if (result != CPNATIVE_OK)
{
JCL_ThrowException (env, SOCKET_EXCEPTION,
- TARGET_NATIVE_LAST_ERROR_STRING ());
+ cpnative_getErrorString (result));
return (0);
}
- return (_javanet_create_inetaddress (env, address));
+ obj = _javanet_create_inetaddress (env, address);
+ cpnet_freeAddress (env, address);
+
+ return obj;
break;
case SOCKOPT_SO_BINDADDR:
- TARGET_NATIVE_NETWORK_SOCKET_GET_OPTION_BIND_ADDRESS (fd, address,
- result);
- if (result != TARGET_NATIVE_OK)
+ result = cpnet_getBindAddress (env, fd, &address);
+ if (result != CPNATIVE_OK)
{
JCL_ThrowException (env, SOCKET_EXCEPTION,
- TARGET_NATIVE_LAST_ERROR_STRING ());
+ cpnative_getErrorString (result));
return (0);
}
- return (_javanet_create_inetaddress (env, address));
+ obj = _javanet_create_inetaddress (env, address);
+ cpnet_freeAddress (env, address);
+
+ return obj;
break;
case SOCKOPT_SO_REUSEADDR:
- TARGET_NATIVE_NETWORK_SOCKET_GET_OPTION_REUSE_ADDRESS (fd, optval,
- result);
- if (result != TARGET_NATIVE_OK)
+ result = cpnet_getReuseAddress (env, fd, &optval);
+ if (result != CPNATIVE_OK)
{
JCL_ThrowException (env, SOCKET_EXCEPTION,
- TARGET_NATIVE_LAST_ERROR_STRING ());
+ cpnative_getErrorString (result));
return (0);
}
if (optval)
- return (_javanet_create_boolean (env, JNI_TRUE));
+ return _javanet_create_boolean (env, JNI_TRUE);
else
- return (_javanet_create_boolean (env, JNI_FALSE));
+ return _javanet_create_boolean (env, JNI_FALSE);
break;
case SOCKOPT_SO_KEEPALIVE:
- TARGET_NATIVE_NETWORK_SOCKET_GET_OPTION_KEEP_ALIVE (fd, optval, result);
- if (result != TARGET_NATIVE_OK)
+ result = cpnet_getKeepAlive (env, fd, &optval);
+ if (result != CPNATIVE_OK)
{
JCL_ThrowException (env, SOCKET_EXCEPTION,
- TARGET_NATIVE_LAST_ERROR_STRING ());
+ cpnative_getErrorString (result));
return (0);
}
if (optval)
- return (_javanet_create_boolean (env, JNI_TRUE));
+ return _javanet_create_boolean (env, JNI_TRUE);
else
- return (_javanet_create_boolean (env, JNI_FALSE));
+ return _javanet_create_boolean (env, JNI_FALSE);
break;
@@ -1500,6 +1442,7 @@ _javanet_get_option (JNIEnv * env, jobject this, jint option_id)
void
_javanet_shutdownInput (JNIEnv * env, jobject this)
{
+ int result;
int fd;
/* Get the real file descriptor. */
@@ -1512,10 +1455,11 @@ _javanet_shutdownInput (JNIEnv * env, jobject this)
}
/* Shutdown input stream of socket. */
- if (shutdown (fd, SHUT_RD) == -1)
+ result = cpnet_shutdown (env, fd, CPNET_SHUTDOWN_READ);
+ if (result != CPNATIVE_OK)
{
JCL_ThrowException (env, SOCKET_EXCEPTION,
- TARGET_NATIVE_LAST_ERROR_STRING());
+ cpnative_getErrorString (result));
return;
}
}
@@ -1524,6 +1468,7 @@ void
_javanet_shutdownOutput (JNIEnv * env, jobject this)
{
int fd;
+ int result;
/* Get the real file descriptor. */
fd = _javanet_get_int_field (env, this, "native_fd");
@@ -1535,10 +1480,11 @@ _javanet_shutdownOutput (JNIEnv * env, jobject this)
}
/* Shutdown output stream of socket. */
- if (shutdown (fd, SHUT_WR) == -1)
+ result = cpnet_shutdown (env, fd, CPNET_SHUTDOWN_WRITE);
+ if (result != CPNATIVE_OK)
{
JCL_ThrowException (env, SOCKET_EXCEPTION,
- TARGET_NATIVE_LAST_ERROR_STRING());
+ cpnative_getErrorString (result));
return;
}
}
diff --git a/native/jni/java-net/javanet.h b/native/jni/java-net/javanet.h
index c173b1059..6551faccd 100644
--- a/native/jni/java-net/javanet.h
+++ b/native/jni/java-net/javanet.h
@@ -40,6 +40,7 @@ exception statement from your version. */
#define _JAVANET_LOADED
#include <jni.h>
+#include <cpnet.h>
/*************************************************************************/
@@ -89,15 +90,15 @@ exception statement from your version. */
*/
extern int _javanet_get_int_field(JNIEnv *, jobject, const char *);
-extern int _javanet_get_netaddr(JNIEnv *, jobject);
+extern cpnet_address *_javanet_get_ip_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, jboolean);
extern void _javanet_bind(JNIEnv *, jobject, jobject, jint, int);
extern void _javanet_listen(JNIEnv *, jobject, jint);
extern void _javanet_accept(JNIEnv *, jobject, jobject);
-extern int _javanet_recvfrom(JNIEnv *, jobject, jarray, int, int, int *, int *);
-extern void _javanet_sendto(JNIEnv *, jobject, jarray, int, int, int, int);
+extern int _javanet_recvfrom(JNIEnv *, jobject, jarray, int, int, cpnet_address **);
+extern void _javanet_sendto(JNIEnv *, jobject, jarray, int, int, cpnet_address *);
extern jobject _javanet_get_option(JNIEnv *, jobject, jint);
extern void _javanet_set_option(JNIEnv *, jobject, jint, jobject);
extern void _javanet_shutdownInput (JNIEnv *, jobject);
diff --git a/native/jni/native-lib/cpnet.h b/native/jni/native-lib/cpnet.h
index 2884229cf..a1f8a9555 100644
--- a/native/jni/native-lib/cpnet.h
+++ b/native/jni/native-lib/cpnet.h
@@ -87,11 +87,28 @@ JNIEXPORT jint cpnet_getReuseAddress (JNIEnv *env, jint fd, jint *reuse);
JNIEXPORT jint cpnet_setKeepAlive (JNIEnv *env, jint fd, jint keep);
JNIEXPORT jint cpnet_getKeepAlive (JNIEnv *env, jint fd, jint *keep);
JNIEXPORT jint cpnet_getBindAddress (JNIEnv *env, jint fd, cpnet_address **addr);
+JNIEXPORT jint cpnet_addMembership (JNIEnv *env, jint fd, cpnet_address *addr);
+JNIEXPORT jint cpnet_dropMembership (JNIEnv *env, jint fd, cpnet_address *addr);
+JNIEXPORT jint cpnet_getAvailableBytes (JNIEnv *env, jint fd, jint *availableBytes);
static inline cpnet_address *cpnet_newIPV4Address(JNIEnv * env)
{
cpnet_address *addr = (cpnet_address *)JCL_malloc(env, sizeof(cpnet_address) + sizeof(struct sockaddr_in));
+ struct sockaddr_in *netaddr = (struct sockaddr_in *)&(addr->data[0]);
+
addr->len = sizeof(struct sockaddr_in);
+ netaddr->sin_family = AF_INET;
+
+ return addr;
+}
+
+static inline cpnet_address *cpnet_newIPV6Address(JNIEnv * env)
+{
+ cpnet_address * addr = (cpnet_address *)JCL_malloc(env, sizeof(cpnet_address) + sizeof(struct sockaddr_in6));
+ struct sockaddr_in6 *netaddr = (struct sockaddr_in6 *)&(addr->data[0]);
+
+ addr->len = sizeof(struct sockaddr_in6);
+ netaddr->sin6_family = AF_INET6;
return addr;
}
@@ -123,7 +140,7 @@ static inline jboolean cpnet_isAddressEqual(cpnet_address *addr1, cpnet_address
return memcmp(addr1->data, addr2->data, addr1->len) == 0;
}
-static inline void cpnet_IPV4AddressToBytes(cpnet_address *netaddr, unsigned char *octets)
+static inline void cpnet_IPV4AddressToBytes(cpnet_address *netaddr, jbyte *octets)
{
struct sockaddr_in *ipaddr = (struct sockaddr_in *)&(netaddr->data[0]);
jint sysaddr = ipaddr->sin_addr.s_addr;
@@ -147,4 +164,18 @@ static inline void cpnet_bytesToIPV4Address(cpnet_address *netaddr, unsigned cha
ipaddr->sin_addr.s_addr = sysaddr;
}
+static inline void cpnet_IPV6AddressToBytes(cpnet_address *netaddr, jbyte *octets)
+{
+ struct sockaddr_in6 *ipaddr = (struct sockaddr_in6 *)&(netaddr->data[0]);
+
+ memcpy(octets, &ipaddr->sin6_addr, 16);
+}
+
+static inline void cpnet_bytesToIPV6Address(cpnet_address *netaddr, jbyte *octets)
+{
+ struct sockaddr_in6 *ipaddr = (struct sockaddr_in6 *)&(netaddr->data[0]);
+
+ memcpy(&ipaddr->sin6_addr, octets, 16);
+}
+
#endif