summaryrefslogtreecommitdiff
path: root/native/jni/java-net
diff options
context:
space:
mode:
authorEtienne M. Gagnon <etienne.gagnon@uqam.ca>2004-03-29 07:07:23 +0000
committerEtienne M. Gagnon <etienne.gagnon@uqam.ca>2004-03-29 07:07:23 +0000
commitdb19fb74ad16353300e70d02e9a71678352f8f13 (patch)
tree81eaa3862f0c3adab78cd89d59acdec176c1162c /native/jni/java-net
parent09f0b054866aa87e199ba9f01d6c40b2fcbed79b (diff)
downloadclasspath-db19fb74ad16353300e70d02e9a71678352f8f13.tar.gz
Reverted.
Diffstat (limited to 'native/jni/java-net')
-rw-r--r--native/jni/java-net/gnu_java_net_PlainDatagramSocketImpl.c329
-rw-r--r--native/jni/java-net/gnu_java_net_PlainSocketImpl.c136
-rw-r--r--native/jni/java-net/java_net_InetAddress.c215
-rw-r--r--native/jni/java-net/java_net_NetworkInterface.c6
-rw-r--r--native/jni/java-net/javanet.c1264
-rw-r--r--native/jni/java-net/javanet.h28
6 files changed, 945 insertions, 1033 deletions
diff --git a/native/jni/java-net/gnu_java_net_PlainDatagramSocketImpl.c b/native/jni/java-net/gnu_java_net_PlainDatagramSocketImpl.c
index 480dc7f75..779ad5679 100644
--- a/native/jni/java-net/gnu_java_net_PlainDatagramSocketImpl.c
+++ b/native/jni/java-net/gnu_java_net_PlainDatagramSocketImpl.c
@@ -50,7 +50,7 @@ exception statement from your version. */
#include "target_native.h"
#ifndef WITHOUT_NETWORK
-#include "target_native_network.h"
+ #include "target_native_network.h"
#endif /* WITHOUT_NETWORK */
#include "gnu_java_net_PlainDatagramSocketImpl.h"
@@ -67,13 +67,13 @@ exception statement from your version. */
* Creates a new datagram socket
*/
JNIEXPORT void JNICALL
-Java_gnu_java_net_PlainDatagramSocketImpl_create (JNIEnv *env, jobject this)
+Java_gnu_java_net_PlainDatagramSocketImpl_create(JNIEnv *env, jobject this)
{
- assert (env != NULL);
- assert ((*env) != NULL);
+ assert(env!=NULL);
+ assert((*env)!=NULL);
#ifndef WITHOUT_NETWORK
- _javanet_create (env, this, 0);
+ _javanet_create(env, this, 0);
#else /* not WITHOUT_NETWORK */
#endif /* not WITHOUT_NETWORK */
}
@@ -84,13 +84,13 @@ Java_gnu_java_net_PlainDatagramSocketImpl_create (JNIEnv *env, jobject this)
* Close the socket.
*/
JNIEXPORT void JNICALL
-Java_gnu_java_net_PlainDatagramSocketImpl_close (JNIEnv *env, jobject this)
+Java_gnu_java_net_PlainDatagramSocketImpl_close(JNIEnv *env, jobject this)
{
- assert (env != NULL);
- assert ((*env) != NULL);
+ assert(env!=NULL);
+ assert((*env)!=NULL);
#ifndef WITHOUT_NETWORK
- _javanet_close (env, this, 0);
+ _javanet_close(env, this, 0);
#else /* not WITHOUT_NETWORK */
#endif /* not WITHOUT_NETWORK */
}
@@ -103,14 +103,14 @@ Java_gnu_java_net_PlainDatagramSocketImpl_close (JNIEnv *env, jobject this)
* variables.
*/
JNIEXPORT void JNICALL
-Java_gnu_java_net_PlainDatagramSocketImpl_bind (JNIEnv *env, jobject this,
- jint port, jobject addr)
+Java_gnu_java_net_PlainDatagramSocketImpl_bind(JNIEnv *env, jobject this,
+ jint port, jobject addr)
{
- assert (env != NULL);
- assert ((*env) != NULL);
+ assert(env!=NULL);
+ assert((*env)!=NULL);
#ifndef WITHOUT_NETWORK
- _javanet_bind (env, this, addr, port, 0);
+ _javanet_bind(env, this, addr, port, 0);
#else /* not WITHOUT_NETWORK */
#endif /* not WITHOUT_NETWORK */
}
@@ -121,16 +121,14 @@ Java_gnu_java_net_PlainDatagramSocketImpl_bind (JNIEnv *env, jobject this,
* This method sets the specified option for a socket
*/
JNIEXPORT void JNICALL
-Java_gnu_java_net_PlainDatagramSocketImpl_setOption (JNIEnv *env,
- jobject this,
- jint option_id,
- jobject val)
+Java_gnu_java_net_PlainDatagramSocketImpl_setOption(JNIEnv *env, jobject this,
+ jint option_id, jobject val)
{
- assert (env != NULL);
- assert ((*env) != NULL);
+ assert(env!=NULL);
+ assert((*env)!=NULL);
#ifndef WITHOUT_NETWORK
- _javanet_set_option (env, this, option_id, val);
+ _javanet_set_option(env, this, option_id, val);
#else /* not WITHOUT_NETWORK */
#endif /* not WITHOUT_NETWORK */
}
@@ -141,15 +139,14 @@ Java_gnu_java_net_PlainDatagramSocketImpl_setOption (JNIEnv *env,
* This method sets the specified option for a socket
*/
JNIEXPORT jobject JNICALL
-Java_gnu_java_net_PlainDatagramSocketImpl_getOption (JNIEnv *env,
- jobject this,
- jint option_id)
+Java_gnu_java_net_PlainDatagramSocketImpl_getOption(JNIEnv *env, jobject this,
+ jint option_id)
{
- assert (env != NULL);
- assert ((*env) != NULL);
+ assert(env!=NULL);
+ assert((*env)!=NULL);
#ifndef WITHOUT_NETWORK
- return (_javanet_get_option (env, this, option_id));
+ return(_javanet_get_option(env, this, option_id));
#else /* not WITHOUT_NETWORK */
#endif /* not WITHOUT_NETWORK */
}
@@ -160,183 +157,182 @@ Java_gnu_java_net_PlainDatagramSocketImpl_getOption (JNIEnv *env,
* Reads a buffer from a remote host
*/
JNIEXPORT void JNICALL
-Java_gnu_java_net_PlainDatagramSocketImpl_receive0 (JNIEnv *env, jobject this,
- jobject packet)
+Java_gnu_java_net_PlainDatagramSocketImpl_receive0(JNIEnv *env, jobject this,
+ jobject packet)
{
#ifndef WITHOUT_NETWORK
- unsigned int addr, port, maxlen, offset, bytes_read;
- jclass cls, addr_cls;
- jmethodID mid;
- jarray arr;
+ unsigned int addr, port, maxlen, offset, bytes_read;
+ jclass cls, addr_cls;
+ jmethodID mid;
+ jarray arr;
unsigned char octets[4];
- char ip_str[16];
- jobject ip_str_obj, addr_obj;
+ char ip_str[16];
+ jobject ip_str_obj, addr_obj;
- assert (env != NULL);
- assert ((*env) != NULL);
+ assert(env!=NULL);
+ assert((*env)!=NULL);
- addr = 0;
- port = 0;
- maxlen = 0;
- offset = 0;
+ addr = 0;
+ port = 0;
+ maxlen = 0;
+ offset = 0;
bytes_read = 0;
- if (packet == NULL)
+ if(packet == NULL)
{
- JCL_ThrowException (env, "java/lang/NullPointerException",
- "Null datagram packet");
+ JCL_ThrowException(env, "java/lang/NullPointerException", "Null datagram packet");
return;
}
/* Get the buffer from the packet */
- cls = (*env)->GetObjectClass (env, packet);
+ cls = (*env)->GetObjectClass(env, packet);
if (cls == NULL)
{
- JCL_ThrowException (env, IO_EXCEPTION, "Internal error");
+ JCL_ThrowException(env, IO_EXCEPTION, "Internal error");
return;
}
- mid = (*env)->GetMethodID (env, cls, "getData", "()[B");
+ mid = (*env)->GetMethodID(env, cls, "getData", "()[B");
if (mid == NULL)
{
- JCL_ThrowException (env, IO_EXCEPTION, "Internal error: getData");
+ JCL_ThrowException(env, IO_EXCEPTION, "Internal error: getData");
return;
}
- arr = (*env)->CallObjectMethod (env, packet, mid);
- if ((arr == NULL) || (*env)->ExceptionOccurred (env))
- {
- JCL_ThrowException (env, IO_EXCEPTION, "Internal error: call getData");
+ arr = (*env)->CallObjectMethod(env, packet, mid);
+ if ((arr == NULL) || (*env)->ExceptionOccurred(env))
+ {
+ JCL_ThrowException(env, IO_EXCEPTION, "Internal error: call getData");
return;
}
/* Now get the offset from the packet */
- mid = (*env)->GetMethodID (env, cls, "getOffset", "()I");
+ mid = (*env)->GetMethodID(env, cls, "getOffset", "()I");
if (mid == NULL)
{
- JCL_ThrowException (env, IO_EXCEPTION, "Internal error: getOffset");
+ JCL_ThrowException(env, IO_EXCEPTION, "Internal error: getOffset");
return;
}
- offset = (*env)->CallIntMethod (env, packet, mid);
- if ((*env)->ExceptionOccurred (env))
+ offset = (*env)->CallIntMethod(env, packet, mid);
+ if ((*env)->ExceptionOccurred(env))
{
- JCL_ThrowException (env, IO_EXCEPTION,
- "Internal error: call getOffset");
+ JCL_ThrowException(env, IO_EXCEPTION, "Internal error: call getOffset");
return;
}
- DBG ("PlainDatagramSocketImpl.receive(): Got the offset\n");
+ DBG("PlainDatagramSocketImpl.receive(): Got the offset\n");
/* Now get the maximal available length from the packet */
- maxlen = (*env)->GetArrayLength (env, arr) - offset;
+ maxlen = (*env)->GetArrayLength(env,arr) - offset;
/* Receive the packet */
/* should we try some sort of validation on the length? */
- bytes_read =
- _javanet_recvfrom (env, this, arr, offset, maxlen, &addr, &port);
- if ((bytes_read == -1) || (*env)->ExceptionOccurred (env))
+ bytes_read = _javanet_recvfrom(env, this, arr, offset, maxlen, &addr, &port);
+ if ((bytes_read == -1) || (*env)->ExceptionOccurred(env))
{
- JCL_ThrowException (env, IO_EXCEPTION, "Internal error: receive");
+ JCL_ThrowException(env, IO_EXCEPTION, "Internal error: receive");
return;
}
- DBG ("PlainDatagramSocketImpl.receive(): Received packet\n");
-
+ 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);
+ 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");
+ {
+ JCL_ThrowException(env, IO_EXCEPTION, "Internal error: new string");
return;
}
- addr_cls = (*env)->FindClass (env, "java/net/InetAddress");
+ addr_cls = (*env)->FindClass(env, "java/net/InetAddress");
if (addr_cls == NULL)
- {
- JCL_ThrowException (env, IO_EXCEPTION,
- "Internal error: InetAddress class");
+ {
+ JCL_ThrowException(env, IO_EXCEPTION, "Internal error: InetAddress class");
return;
}
- DBG ("PlainDatagramSocketImpl.receive(): Found InetAddress class\n");
+ DBG("PlainDatagramSocketImpl.receive(): Found InetAddress class\n");
- mid = (*env)->GetStaticMethodID (env, addr_cls, "getByName",
- "(Ljava/lang/String;)Ljava/net/InetAddress;");
+ mid = (*env)->GetStaticMethodID(env, addr_cls, "getByName",
+ "(Ljava/lang/String;)Ljava/net/InetAddress;");
if (mid == NULL)
{
- JCL_ThrowException (env, IO_EXCEPTION, "Internal Error");
+ JCL_ThrowException(env, IO_EXCEPTION, "Internal Error");
return;
}
- DBG
- ("PlainDatagramSocketImpl.receive(): Found InetAddress.getByName method\n");
+ DBG("PlainDatagramSocketImpl.receive(): Found InetAddress.getByName method\n");
- addr_obj = (*env)->CallStaticObjectMethod (env, addr_cls, mid, ip_str_obj);
- if ((*env)->ExceptionOccurred (env))
+ addr_obj = (*env)->CallStaticObjectMethod(env, addr_cls, mid, ip_str_obj);
+ if ((*env)->ExceptionOccurred(env))
{
- JCL_ThrowException (env, IO_EXCEPTION,
- "Internal error: call getByName");
+ JCL_ThrowException(env, IO_EXCEPTION, "Internal error: call getByName");
return;
}
- mid = (*env)->GetMethodID (env, cls, "setAddress",
- "(Ljava/net/InetAddress;)V");
+ mid = (*env)->GetMethodID(env, cls, "setAddress",
+ "(Ljava/net/InetAddress;)V");
if (mid == NULL)
{
- JCL_ThrowException (env, IO_EXCEPTION, "Internal error: setAddress");
+ JCL_ThrowException(env, IO_EXCEPTION, "Internal error: setAddress");
return;
}
- (*env)->CallVoidMethod (env, packet, mid, addr_obj);
- if ((*env)->ExceptionOccurred (env))
+ (*env)->CallVoidMethod(env, packet, mid, addr_obj);
+ if ((*env)->ExceptionOccurred(env))
{
- JCL_ThrowException (env, IO_EXCEPTION,
- "Internal error: call setAddress");
+ JCL_ThrowException(env, IO_EXCEPTION, "Internal error: call setAddress");
return;
}
-
- DBG ("PlainDatagramSocketImpl.receive(): Stored the address\n");
+
+ DBG("PlainDatagramSocketImpl.receive(): Stored the address\n");
/* Store the port */
- port = ntohs (((unsigned short) port));
+ port = ntohs(((unsigned short)port));
- mid = (*env)->GetMethodID (env, cls, "setPort", "(I)V");
+ mid = (*env)->GetMethodID(env, cls, "setPort", "(I)V");
if (mid == NULL)
{
- JCL_ThrowException (env, IO_EXCEPTION, "Internal error: setPort");
+ JCL_ThrowException(env, IO_EXCEPTION, "Internal error: setPort");
return;
}
- (*env)->CallVoidMethod (env, packet, mid, port);
- if ((*env)->ExceptionOccurred (env))
+ (*env)->CallVoidMethod(env, packet, mid, port);
+ if ((*env)->ExceptionOccurred(env))
{
- JCL_ThrowException (env, IO_EXCEPTION, "Internal error: call setPort");
+ JCL_ThrowException(env, IO_EXCEPTION, "Internal error: call setPort");
return;
}
- DBG ("PlainDatagramSocketImpl.receive(): Stored the port\n");
+ DBG("PlainDatagramSocketImpl.receive(): Stored the port\n");
/* Store back the length */
- mid = (*env)->GetMethodID (env, cls, "setLength", "(I)V");
+ mid = (*env)->GetMethodID(env, cls, "setLength", "(I)V");
if (mid == NULL)
{
- JCL_ThrowException (env, IO_EXCEPTION, "Internal error: setLength");
+ JCL_ThrowException(env, IO_EXCEPTION, "Internal error: setLength");
return;
}
-
- (*env)->CallVoidMethod (env, packet, mid, bytes_read);
- if ((*env)->ExceptionOccurred (env))
- {
- JCL_ThrowException (env, IO_EXCEPTION,
- "Internal error: call setLength");
+
+ (*env)->CallVoidMethod(env, packet, mid, bytes_read);
+ if ((*env)->ExceptionOccurred(env))
+ {
+ JCL_ThrowException(env, IO_EXCEPTION, "Internal error: call setLength");
return;
}
- DBG ("PlainDatagramSocketImpl.receive(): Stored the length\n");
+ DBG("PlainDatagramSocketImpl.receive(): Stored the length\n");
#else /* not WITHOUT_NETWORK */
#endif /* not WITHOUT_NETWORK */
}
@@ -347,35 +343,27 @@ Java_gnu_java_net_PlainDatagramSocketImpl_receive0 (JNIEnv *env, jobject this,
* Writes a buffer to the remote host
*/
JNIEXPORT void JNICALL
-Java_gnu_java_net_PlainDatagramSocketImpl_sendto (JNIEnv *env, jobject this,
- jobject addr, jint port,
- jarray buf, jint offset,
- jint len)
+Java_gnu_java_net_PlainDatagramSocketImpl_sendto(JNIEnv *env, jobject this,
+ jobject addr, jint port, jarray buf,
+ jint offset, jint len)
{
#ifndef WITHOUT_NETWORK
jint netAddress;
- assert (env != NULL);
- assert ((*env) != NULL);
+ assert(env!=NULL);
+ assert((*env)!=NULL);
- netAddress = _javanet_get_netaddr (env, addr);
- if ((*env)->ExceptionOccurred (env))
- {
- JCL_ThrowException (env, IO_EXCEPTION,
- "Internal error: get network address");
- return;
- }
+ netAddress = _javanet_get_netaddr(env, addr);
+ if ((*env)->ExceptionOccurred(env))
+ { JCL_ThrowException(env, IO_EXCEPTION, "Internal error: get network address"); return; }
- DBG ("PlainDatagramSocketImpl.sendto(): have addr\n");
+ DBG("PlainDatagramSocketImpl.sendto(): have addr\n");
- _javanet_sendto (env, this, buf, offset, len, netAddress, port);
- if ((*env)->ExceptionOccurred (env))
- {
- JCL_ThrowException (env, IO_EXCEPTION, "Internal error: send data");
- return;
- }
+ _javanet_sendto(env, this, buf, offset, len, netAddress, port);
+ if ((*env)->ExceptionOccurred(env))
+ { JCL_ThrowException(env, IO_EXCEPTION, "Internal error: send data"); return; }
- DBG ("PlainDatagramSocketImpl.sendto(): finished\n");
+ DBG("PlainDatagramSocketImpl.sendto(): finished\n");
#else /* not WITHOUT_NETWORK */
#endif /* not WITHOUT_NETWORK */
}
@@ -386,44 +374,42 @@ Java_gnu_java_net_PlainDatagramSocketImpl_sendto (JNIEnv *env, jobject this,
* Joins a multicast group
*/
JNIEXPORT void JNICALL
-Java_gnu_java_net_PlainDatagramSocketImpl_join (JNIEnv *env, jobject this,
- jobject addr)
+Java_gnu_java_net_PlainDatagramSocketImpl_join(JNIEnv *env, jobject this,
+ jobject addr)
{
#ifndef WITHOUT_NETWORK
jint netAddress;
- int fd;
- int result;
+ int fd;
+ int result;
- assert (env != NULL);
- assert ((*env) != NULL);
+ assert(env!=NULL);
+ assert((*env)!=NULL);
- netAddress = _javanet_get_netaddr (env, addr);
- if ((*env)->ExceptionOccurred (env))
+ netAddress = _javanet_get_netaddr(env, addr);
+ if ((*env)->ExceptionOccurred(env))
{
- JCL_ThrowException (env, IO_EXCEPTION, "Internal error");
+ JCL_ThrowException(env, IO_EXCEPTION, "Internal error");
return;
}
- fd = _javanet_get_int_field (env, this, "native_fd");
- if ((*env)->ExceptionOccurred (env))
+ fd = _javanet_get_int_field(env, this, "native_fd");
+ if ((*env)->ExceptionOccurred(env))
{
- JCL_ThrowException (env, IO_EXCEPTION, "Internal error");
+ JCL_ThrowException(env, IO_EXCEPTION, "Internal error");
return;
}
- DBG ("PlainDatagramSocketImpl.join(): have native fd\n");
+ DBG("PlainDatagramSocketImpl.join(): have native fd\n");
- TARGET_NATIVE_NETWORK_SOCKET_SET_OPTION_ADD_MEMBERSHIP (fd, netAddress,
- result);
+ 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 ());
+ JCL_ThrowException(env, IO_EXCEPTION, TARGET_NATIVE_LAST_ERROR_STRING());
return;
}
- DBG ("PlainDatagramSocketImpl.join(): finished\n");
+ DBG("PlainDatagramSocketImpl.join(): finished\n");
#else /* not WITHOUT_NETWORK */
#endif /* not WITHOUT_NETWORK */
}
@@ -434,43 +420,38 @@ Java_gnu_java_net_PlainDatagramSocketImpl_join (JNIEnv *env, jobject this,
* Leaves a multicast group
*/
JNIEXPORT void JNICALL
-Java_gnu_java_net_PlainDatagramSocketImpl_leave (JNIEnv *env, jobject this,
- jobject addr)
+Java_gnu_java_net_PlainDatagramSocketImpl_leave(JNIEnv *env, jobject this,
+ jobject addr)
{
#ifndef WITHOUT_NETWORK
jint netAddress;
- int fd;
- int result;
+ int fd;
+ int result;
- assert (env != NULL);
- assert ((*env) != NULL);
+ assert(env!=NULL);
+ assert((*env)!=NULL);
- netAddress = _javanet_get_netaddr (env, addr);
- if ((*env)->ExceptionOccurred (env))
+ netAddress = _javanet_get_netaddr(env, addr);
+ if ((*env)->ExceptionOccurred(env))
{
- JCL_ThrowException (env, IO_EXCEPTION, "Internal error");
+ JCL_ThrowException(env, IO_EXCEPTION, "Internal error");
return;
}
- fd = _javanet_get_int_field (env, this, "native_fd");
- if ((*env)->ExceptionOccurred (env))
- {
- JCL_ThrowException (env, IO_EXCEPTION, "Internal error");
- return;
- }
+ fd = _javanet_get_int_field(env, this, "native_fd");
+ if ((*env)->ExceptionOccurred(env))
+ { JCL_ThrowException(env, IO_EXCEPTION, "Internal error"); return; }
- DBG ("PlainDatagramSocketImpl.leave(): have native fd\n");
+ DBG("PlainDatagramSocketImpl.leave(): have native fd\n");
- TARGET_NATIVE_NETWORK_SOCKET_SET_OPTION_DROP_MEMBERSHIP (fd, netAddress,
- result);
- if (result != TARGET_NATIVE_OK)
+ 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 ());
+ JCL_ThrowException(env, IO_EXCEPTION, TARGET_NATIVE_LAST_ERROR_STRING());
return;
}
- DBG ("PlainDatagramSocketImpl.leave(): finished\n");
+ DBG("PlainDatagramSocketImpl.leave(): finished\n");
#else /* not WITHOUT_NETWORK */
#endif /* not WITHOUT_NETWORK */
}
diff --git a/native/jni/java-net/gnu_java_net_PlainSocketImpl.c b/native/jni/java-net/gnu_java_net_PlainSocketImpl.c
index 868308fb5..e823810ac 100644
--- a/native/jni/java-net/gnu_java_net_PlainSocketImpl.c
+++ b/native/jni/java-net/gnu_java_net_PlainSocketImpl.c
@@ -42,7 +42,7 @@ exception statement from your version. */
#include <stdio.h>
#include <string.h>
#include <assert.h>
-
+
#include <jni.h>
#include <jcl.h>
@@ -50,7 +50,7 @@ exception statement from your version. */
#include "target_native.h"
#ifndef WITHOUT_NETWORK
-#include "target_native_network.h"
+ #include "target_native_network.h"
#endif /* WITHOUT_NETWORK */
#include "gnu_java_net_PlainSocketImpl.h"
@@ -68,14 +68,13 @@ 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_PlainSocketImpl_create(JNIEnv *env, jobject this, jboolean stream)
{
#ifndef WITHOUT_NETWORK
- assert (env != NULL);
- assert ((*env) != NULL);
+ assert(env!=NULL);
+ assert((*env)!=NULL);
- _javanet_create (env, this, stream);
+ _javanet_create(env, this, stream);
#else /* not WITHOUT_NETWORK */
#endif /* not WITHOUT_NETWORK */
}
@@ -87,13 +86,13 @@ 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_PlainSocketImpl_close(JNIEnv *env, jobject this)
{
#ifndef WITHOUT_NETWORK
- assert (env != NULL);
- assert ((*env) != NULL);
+ assert(env!=NULL);
+ assert((*env)!=NULL);
- _javanet_close (env, this, 1);
+ _javanet_close(env, this, 1);
#else /* not WITHOUT_NETWORK */
#endif /* not WITHOUT_NETWORK */
}
@@ -104,14 +103,14 @@ 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_PlainSocketImpl_connect(JNIEnv *env, jobject this,
+ jobject addr, jint port)
{
#ifndef WITHOUT_NETWORK
- assert (env != NULL);
- assert ((*env) != NULL);
+ assert(env!=NULL);
+ assert((*env)!=NULL);
- _javanet_connect (env, this, addr, port);
+ _javanet_connect(env, this, addr, port);
#else /* not WITHOUT_NETWORK */
#endif /* not WITHOUT_NETWORK */
}
@@ -124,14 +123,14 @@ 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_PlainSocketImpl_bind(JNIEnv *env, jobject this, jobject addr,
+ jint port)
{
#ifndef WITHOUT_NETWORK
- assert (env != NULL);
- assert ((*env) != NULL);
+ assert(env!=NULL);
+ assert((*env)!=NULL);
- _javanet_bind (env, this, addr, port, 1);
+ _javanet_bind(env, this, addr, port, 1);
#else /* not WITHOUT_NETWORK */
#endif /* not WITHOUT_NETWORK */
}
@@ -143,14 +142,13 @@ 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_PlainSocketImpl_listen(JNIEnv *env, jobject this, jint queuelen)
{
#ifndef WITHOUT_NETWORK
- assert (env != NULL);
- assert ((*env) != NULL);
+ assert(env!=NULL);
+ assert((*env)!=NULL);
- _javanet_listen (env, this, queuelen);
+ _javanet_listen(env, this, queuelen);
#else /* not WITHOUT_NETWORK */
#endif /* not WITHOUT_NETWORK */
}
@@ -162,14 +160,13 @@ 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_PlainSocketImpl_accept(JNIEnv *env, jobject this, jobject impl)
{
#ifndef WITHOUT_NETWORK
- assert (env != NULL);
- assert ((*env) != NULL);
+ assert(env!=NULL);
+ assert((*env)!=NULL);
- _javanet_accept (env, this, impl);
+ _javanet_accept(env, this, impl);
#else /* not WITHOUT_NETWORK */
#endif /* not WITHOUT_NETWORK */
}
@@ -177,39 +174,38 @@ 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_PlainSocketImpl_available(JNIEnv *env, jobject this)
{
#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;
+
+ assert(env!=NULL);
+ assert((*env)!=NULL);
+
+ cls = (*env)->GetObjectClass(env, this);
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, this, 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;
}
@@ -224,14 +220,14 @@ 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_PlainSocketImpl_setOption(JNIEnv *env, jobject this,
+ jint option_id, jobject val)
{
#ifndef WITHOUT_NETWORK
- assert (env != NULL);
- assert ((*env) != NULL);
+ assert(env!=NULL);
+ assert((*env)!=NULL);
- _javanet_set_option (env, this, option_id, val);
+ _javanet_set_option(env, this, option_id, val);
#else /* not WITHOUT_NETWORK */
#endif /* not WITHOUT_NETWORK */
}
@@ -242,14 +238,14 @@ Java_gnu_java_net_PlainSocketImpl_setOption (JNIEnv *env, jobject this,
* This method sets 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_PlainSocketImpl_getOption(JNIEnv *env, jobject this,
+ jint option_id)
{
#ifndef WITHOUT_NETWORK
- assert (env != NULL);
- assert ((*env) != NULL);
+ assert(env!=NULL);
+ assert((*env)!=NULL);
- return (_javanet_get_option (env, this, option_id));
+ return(_javanet_get_option(env, this, option_id));
#else /* not WITHOUT_NETWORK */
#endif /* not WITHOUT_NETWORK */
}
@@ -260,14 +256,14 @@ 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_PlainSocketImpl_read(JNIEnv *env, jobject this, jarray buf,
+ jint offset, jint len)
{
#ifndef WITHOUT_NETWORK
- assert (env != NULL);
- assert ((*env) != NULL);
+ assert(env!=NULL);
+ assert((*env)!=NULL);
- return (_javanet_recvfrom (env, this, buf, offset, len, 0, 0));
+ return(_javanet_recvfrom(env, this, buf, offset, len, 0, 0));
#else /* not WITHOUT_NETWORK */
#endif /* not WITHOUT_NETWORK */
}
@@ -278,14 +274,14 @@ Java_gnu_java_net_PlainSocketImpl_read (JNIEnv *env, jobject this, jarray buf,
* 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_PlainSocketImpl_write(JNIEnv *env, jobject this, jarray buf,
+ jint offset, jint len)
{
#ifndef WITHOUT_NETWORK
- assert (env != NULL);
- assert ((*env) != NULL);
+ assert(env!=NULL);
+ assert((*env)!=NULL);
- _javanet_sendto (env, this, buf, offset, len, 0, 0);
+ _javanet_sendto(env, this, buf, offset, len, 0, 0);
#else /* not WITHOUT_NETWORK */
#endif /* not WITHOUT_NETWORK */
}
diff --git a/native/jni/java-net/java_net_InetAddress.c b/native/jni/java-net/java_net_InetAddress.c
index e123462c7..8fa722fd0 100644
--- a/native/jni/java-net/java_net_InetAddress.c
+++ b/native/jni/java-net/java_net_InetAddress.c
@@ -50,7 +50,7 @@ exception statement from your version. */
#include "target_native.h"
#ifndef WITHOUT_NETWORK
-#include "target_native_network.h"
+ #include "target_native_network.h"
#endif /* WITHOUT_NETWORK */
#include "java_net_InetAddress.h"
@@ -61,28 +61,28 @@ exception statement from your version. */
* Function to return the local hostname
*/
JNIEXPORT jstring JNICALL
-Java_java_net_InetAddress_getLocalHostname (JNIEnv *env, jclass class)
+Java_java_net_InetAddress_getLocalHostname(JNIEnv *env, jclass class)
{
- char hostname[256];
- int result;
+ char hostname[256];
+ int result;
jstring retval;
- assert (env != NULL);
- assert ((*env) != NULL);
+ assert(env!=NULL);
+ assert((*env)!=NULL);
#ifndef WITHOUT_NETWORK
- TARGET_NATIVE_NETWORK_GET_HOSTNAME (hostname, sizeof (hostname), result);
+ TARGET_NATIVE_NETWORK_GET_HOSTNAME(hostname,sizeof(hostname),result);
if (result != TARGET_NATIVE_OK)
{
- strcpy (hostname, "localhost");
+ strcpy(hostname,"localhost");
}
#else /* not WITHOUT_NETWORK */
- strcpy (hostname, "localhost");
+ strcpy(hostname, "localhost");
#endif /* not WITHOUT_NETWORK */
- retval = (*env)->NewStringUTF (env, hostname);
+ retval = (*env)->NewStringUTF(env, hostname);
- return (retval);
+ return(retval);
}
/*************************************************************************/
@@ -91,39 +91,41 @@ Java_java_net_InetAddress_getLocalHostname (JNIEnv *env, jclass class)
* Returns the value of the special IP address INADDR_ANY
*/
JNIEXPORT jarray JNICALL
-Java_java_net_InetAddress_lookupInaddrAny (JNIEnv *env, jclass class)
+Java_java_net_InetAddress_lookupInaddrAny(JNIEnv *env, jclass class)
{
- jarray IParray;
- jbyte *octets;
+ jarray IParray;
+ jbyte *octets;
- assert (env != NULL);
- assert ((*env) != NULL);
+ assert(env!=NULL);
+ assert((*env)!=NULL);
/* Allocate an array for the IP address */
- IParray = (*env)->NewByteArray (env, 4);
- if (IParray == NULL)
- {
- JCL_ThrowException (env, UNKNOWN_HOST_EXCEPTION, "Internal Error");
- return (jarray) NULL;
+ IParray = (*env)->NewByteArray(env, 4);
+ if (IParray == NULL)
+ {
+ JCL_ThrowException(env, UNKNOWN_HOST_EXCEPTION, "Internal Error");
+ return (jarray)NULL;
}
/* Copy in the values */
- octets = (*env)->GetByteArrayElements (env, IParray, 0);
+ octets = (*env)->GetByteArrayElements(env, IParray, 0);
#ifndef WITHOUT_NETWORK
- TARGET_NATIVE_NETWORK_INT_TO_IPADDRESS_BYTES (INADDR_ANY,
- octets[0],
- octets[1],
- octets[2], octets[3]);
- (*env)->ReleaseByteArrayElements (env, IParray, octets, 0);
+ TARGET_NATIVE_NETWORK_INT_TO_IPADDRESS_BYTES(INADDR_ANY,
+ octets[0],
+ octets[1],
+ octets[2],
+ octets[3]
+ );
+ (*env)->ReleaseByteArrayElements(env, IParray, octets, 0);
#else /* not WITHOUT_NETWORK */
- octets[0] = 0;
- octets[1] = 0;
- octets[2] = 0;
- octets[3] = 0;
+ octets[0]=0;
+ octets[1]=0;
+ octets[2]=0;
+ octets[3]=0;
#endif /* not WITHOUT_NETWORK */
- return (IParray);
+ return(IParray);
}
/*************************************************************************/
@@ -133,141 +135,144 @@ Java_java_net_InetAddress_lookupInaddrAny (JNIEnv *env, jclass class)
* in as a byte array
*/
JNIEXPORT jstring JNICALL
-Java_java_net_InetAddress_getHostByAddr (JNIEnv *env, jclass class,
- jarray arr)
+Java_java_net_InetAddress_getHostByAddr(JNIEnv *env, jclass class, jarray arr)
{
#ifndef WITHOUT_NETWORK
- jbyte *octets;
- jsize len;
- int addr;
- char hostname[255];
- int result;
+ jbyte *octets;
+ jsize len;
+ int addr;
+ char hostname[255];
+ int result;
jstring retval;
- assert (env != NULL);
- assert ((*env) != NULL);
+ assert(env!=NULL);
+ assert((*env)!=NULL);
/* Grab the byte[] array with the IP out of the input data */
- len = (*env)->GetArrayLength (env, arr);
+ len = (*env)->GetArrayLength(env, arr);
if (len != 4)
{
- JCL_ThrowException (env, UNKNOWN_HOST_EXCEPTION, "Bad IP Address");
- return (jstring) NULL;
+ JCL_ThrowException(env, UNKNOWN_HOST_EXCEPTION, "Bad IP Address");
+ return (jstring)NULL;
}
- octets = (*env)->GetByteArrayElements (env, arr, 0);
+ octets = (*env)->GetByteArrayElements(env, arr, 0);
if (!octets)
{
- JCL_ThrowException (env, UNKNOWN_HOST_EXCEPTION, "Bad IP Address");
- return (jstring) NULL;
+ JCL_ThrowException(env, UNKNOWN_HOST_EXCEPTION, "Bad IP Address");
+ 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);
+ TARGET_NATIVE_NETWORK_IPADDRESS_BYTES_TO_INT(octets[0],
+ octets[1],
+ octets[2],
+ octets[3],
+ addr
+ );
/* Release some memory */
- (*env)->ReleaseByteArrayElements (env, arr, octets, 0);
+ (*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);
+ TARGET_NATIVE_NETWORK_GET_HOSTNAME_BY_ADDRESS(addr,hostname,sizeof(hostname),result);
if (result != TARGET_NATIVE_OK)
{
- JCL_ThrowException (env, UNKNOWN_HOST_EXCEPTION, "Bad IP address");
- return (jstring) NULL;
+ JCL_ThrowException(env, UNKNOWN_HOST_EXCEPTION, "Bad IP address");
+ return (jstring)NULL;
}
- retval = (*env)->NewStringUTF (env, hostname);
+ retval = (*env)->NewStringUTF(env, hostname);
- return (retval);
+ return(retval);
#else /* not WITHOUT_NETWORK */
- return (jstring) NULL;
+ return (jstring)NULL;
#endif /* not WITHOUT_NETWORK */
}
/*************************************************************************/
JNIEXPORT jobjectArray JNICALL
-Java_java_net_InetAddress_getHostByName (JNIEnv *env, jclass class,
- jstring host)
+Java_java_net_InetAddress_getHostByName(JNIEnv *env, jclass class, jstring host)
{
#ifndef WITHOUT_NETWORK
- const char *hostname;
+ const char *hostname;
/* FIXME: limitation of max. 64 addresses - how to make it more flexibale? */
- int addresses[64];
- jsize addresses_count;
- int result;
- jclass arr_class;
- jobjectArray addrs;
- int i;
- jbyte *octets;
- jarray ret_octets;
-
- assert (env != NULL);
- assert ((*env) != NULL);
+ int addresses[64];
+ jsize addresses_count;
+ int result;
+ jclass arr_class;
+ jobjectArray addrs;
+ int i;
+ jbyte *octets;
+ jarray ret_octets;
+
+ assert(env!=NULL);
+ assert((*env)!=NULL);
/* Grab the hostname string */
- hostname = (*env)->GetStringUTFChars (env, host, 0);
- if (!hostname)
+ hostname = (*env)->GetStringUTFChars(env, host, 0);
+ if (!hostname)
{
- JCL_ThrowException (env, UNKNOWN_HOST_EXCEPTION, "Null hostname");
- return (jobjectArray) NULL;
+ JCL_ThrowException(env, UNKNOWN_HOST_EXCEPTION, "Null hostname");
+ return (jobjectArray)NULL;
}
/* Look up the host */
- TARGET_NATIVE_NETWORK_GET_HOSTNAME_BY_NAME (hostname,
- addresses,
- sizeof (addresses) /
- sizeof (addresses[0]),
- addresses_count, result);
+ TARGET_NATIVE_NETWORK_GET_HOSTNAME_BY_NAME(hostname,
+ addresses,
+ sizeof(addresses)/sizeof(addresses[0]),
+ addresses_count,
+ result
+ );
if (result != TARGET_NATIVE_OK)
{
- JCL_ThrowException (env, UNKNOWN_HOST_EXCEPTION, (char *) hostname);
- return (jobjectArray) NULL;
+ JCL_ThrowException(env, UNKNOWN_HOST_EXCEPTION, (char*)hostname);
+ return (jobjectArray)NULL;
}
- (*env)->ReleaseStringUTFChars (env, host, hostname);
+ (*env)->ReleaseStringUTFChars(env, host, hostname);
- arr_class = (*env)->FindClass (env, "[B");
+ arr_class = (*env)->FindClass(env,"[B");
if (!arr_class)
{
- JCL_ThrowException (env, UNKNOWN_HOST_EXCEPTION, "Internal Error");
- return (jobjectArray) NULL;
+ JCL_ThrowException(env, UNKNOWN_HOST_EXCEPTION, "Internal Error");
+ return (jobjectArray)NULL;
}
- addrs = (*env)->NewObjectArray (env, addresses_count, arr_class, 0);
+ addrs = (*env)->NewObjectArray(env, addresses_count, arr_class, 0);
if (!addrs)
{
- JCL_ThrowException (env, UNKNOWN_HOST_EXCEPTION, "Internal Error");
- return (jobjectArray) NULL;
+ JCL_ThrowException(env, UNKNOWN_HOST_EXCEPTION, "Internal Error");
+ return (jobjectArray)NULL;
}
/* Now loop and copy in each address */
for (i = 0; i < addresses_count; i++)
{
- ret_octets = (*env)->NewByteArray (env, 4);
- if (!ret_octets)
- {
- JCL_ThrowException (env, UNKNOWN_HOST_EXCEPTION, "Internal Error");
- return (jobjectArray) NULL;
- }
+ ret_octets = (*env)->NewByteArray(env, 4);
+ if (!ret_octets)
+ {
+ JCL_ThrowException(env, UNKNOWN_HOST_EXCEPTION, "Internal Error");
+ return (jobjectArray)NULL;
+ }
- octets = (*env)->GetByteArrayElements (env, ret_octets, 0);
+ octets = (*env)->GetByteArrayElements(env, ret_octets, 0);
- TARGET_NATIVE_NETWORK_INT_TO_IPADDRESS_BYTES (addresses[i],
- octets[0],
- octets[1],
- octets[2], octets[3]);
+ TARGET_NATIVE_NETWORK_INT_TO_IPADDRESS_BYTES(addresses[i],
+ octets[0],
+ octets[1],
+ octets[2],
+ octets[3]
+ );
- (*env)->ReleaseByteArrayElements (env, ret_octets, octets, 0);
+ (*env)->ReleaseByteArrayElements(env, ret_octets, octets, 0);
- (*env)->SetObjectArrayElement (env, addrs, i, ret_octets);
+ (*env)->SetObjectArrayElement(env, addrs, i, ret_octets);
}
- return (addrs);
+ return(addrs);
#else /* not WITHOUT_NETWORK */
- return (jobjectArray) NULL;
+ return (jobjectArray)NULL;
#endif /* not WITHOUT_NETWORK */
}
diff --git a/native/jni/java-net/java_net_NetworkInterface.c b/native/jni/java-net/java_net_NetworkInterface.c
index 1b38681e4..6c51f872f 100644
--- a/native/jni/java-net/java_net_NetworkInterface.c
+++ b/native/jni/java-net/java_net_NetworkInterface.c
@@ -54,11 +54,9 @@ exception statement from your version. */
* Returns all local network interfaces as vector
*/
JNIEXPORT jobject JNICALL
-Java_java_net_NetworkInterface_getRealNetworkInterfaces (JNIEnv *env,
- jclass class)
+Java_java_net_NetworkInterface_getRealNetworkInterfaces (JNIEnv* env, jclass class)
{
- JCL_ThrowException (env, IO_EXCEPTION,
- "java.net.NetworkInterface.getRealNetworkInterfaces(): not implemented");
+ JCL_ThrowException (env, IO_EXCEPTION, "java.net.NetworkInterface.getRealNetworkInterfaces(): not implemented");
return 0;
}
diff --git a/native/jni/java-net/javanet.c b/native/jni/java-net/javanet.c
index 712432f44..38bad1824 100644
--- a/native/jni/java-net/javanet.c
+++ b/native/jni/java-net/javanet.c
@@ -50,7 +50,7 @@ exception statement from your version. */
#include "target_native.h"
#ifndef WITHOUT_NETWORK
-#include "target_native_network.h"
+ #include "target_native_network.h"
#endif /* WITHOUT_NETWORK */
#ifndef WITHOUT_NETWORK
@@ -71,24 +71,24 @@ exception statement from your version. */
* Sets an integer field in the specified object.
*/
static void
-_javanet_set_int_field (JNIEnv *env, jobject obj, char *class, char *field,
- int val)
+_javanet_set_int_field(JNIEnv *env, jobject obj, char *class, char *field,
+ int val)
{
- jclass cls;
+ jclass cls;
jfieldID fid;
- assert (env != NULL);
- assert ((*env) != NULL);
+ assert(env!=NULL);
+ assert((*env)!=NULL);
- cls = (*env)->FindClass (env, class);
+ cls = (*env)->FindClass(env, class);
if (cls == NULL)
return;
- fid = (*env)->GetFieldID (env, cls, field, "I");
+ fid = (*env)->GetFieldID(env, cls, field, "I");
if (fid == NULL)
return;
- (*env)->SetIntField (env, obj, fid, val);
+ (*env)->SetIntField(env, obj, fid, val);
return;
}
@@ -100,27 +100,27 @@ _javanet_set_int_field (JNIEnv *env, jobject obj, char *class, char *field,
* -1 if an error occurs.
*/
int
-_javanet_get_int_field (JNIEnv *env, jobject obj, const char *field)
+_javanet_get_int_field(JNIEnv *env, jobject obj, const char *field)
{
jclass cls = 0;
jfieldID fid;
int fd;
- assert (env != NULL);
- assert ((*env) != NULL);
+ assert(env!=NULL);
+ assert((*env)!=NULL);
- DBG ("_javanet_get_int_field(): Entered _javanet_get_int_field\n");
+ DBG("_javanet_get_int_field(): Entered _javanet_get_int_field\n");
- cls = (*env)->GetObjectClass (env, obj);
+ cls = (*env)->GetObjectClass(env, obj);
if (cls == NULL)
return -1;
- fid = (*env)->GetFieldID (env, cls, field, "I");
+ fid = (*env)->GetFieldID(env, cls, field, "I");
if (fid == NULL)
return -1;
- DBG ("_javanet_get_int_field(): Found field id\n");
+ DBG("_javanet_get_int_field(): Found field id\n");
- fd = (*env)->GetIntField (env, obj, fid);
+ fd = (*env)->GetIntField(env, obj, fid);
return fd;
}
@@ -133,51 +133,51 @@ _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)
{
- jclass this_cls, fd_cls;
- jfieldID fid;
+ jclass this_cls, fd_cls;
+ jfieldID fid;
jmethodID mid;
- jobject fd_obj;
+ jobject fd_obj;
- assert (env != NULL);
- assert ((*env) != NULL);
+ assert(env!=NULL);
+ assert((*env)!=NULL);
- DBG ("_javanet_create_localfd(): Entered _javanet_create_localfd\n");
+ DBG("_javanet_create_localfd(): Entered _javanet_create_localfd\n");
/* Look up the fd field */
- this_cls = (*env)->FindClass (env, "java/net/SocketImpl");
+ this_cls = (*env)->FindClass(env, "java/net/SocketImpl");
if (this_cls == NULL)
return;
- fid = (*env)->GetFieldID (env, this_cls, "fd", "Ljava/io/FileDescriptor;");
+ fid = (*env)->GetFieldID(env, this_cls, "fd", "Ljava/io/FileDescriptor;");
if (fid == NULL)
return;
- DBG ("_javanet_create_localfd(): Found fd variable\n");
+ DBG("_javanet_create_localfd(): Found fd variable\n");
/* Create a FileDescriptor */
- fd_cls = (*env)->FindClass (env, "java/io/FileDescriptor");
+ fd_cls = (*env)->FindClass(env, "java/io/FileDescriptor");
if (fd_cls == NULL)
return;
- DBG ("_javanet_create_localfd(): Found FileDescriptor class\n");
+ DBG("_javanet_create_localfd(): Found FileDescriptor class\n");
- mid = (*env)->GetMethodID (env, fd_cls, "<init>", "()V");
+ mid = (*env)->GetMethodID(env, fd_cls, "<init>", "()V");
if (mid == NULL)
return;
- DBG ("_javanet_create_localfd(): Found FileDescriptor constructor\n");
+ DBG("_javanet_create_localfd(): Found FileDescriptor constructor\n");
- fd_obj = (*env)->NewObject (env, fd_cls, mid);
+ fd_obj = (*env)->NewObject(env, fd_cls, mid);
if (fd_obj == NULL)
return;
- DBG ("_javanet_create_localfd(): Created FileDescriptor\n");
+ DBG("_javanet_create_localfd(): Created FileDescriptor\n");
/* Now set the pointer to the new FileDescriptor */
- (*env)->SetObjectField (env, this, fid, fd_obj);
- DBG ("_javanet_create_localfd(): Set fd field\n");
+ (*env)->SetObjectField(env, this, fid, fd_obj);
+ DBG("_javanet_create_localfd(): Set fd field\n");
return;
}
@@ -188,24 +188,24 @@ _javanet_create_localfd (JNIEnv *env, jobject this)
* Returns a Boolean object with the specfied value
*/
static jobject
-_javanet_create_boolean (JNIEnv *env, jboolean val)
+_javanet_create_boolean(JNIEnv *env, jboolean val)
{
- jclass cls;
+ jclass cls;
jmethodID mid;
- jobject obj;
+ jobject obj;
- assert (env != NULL);
- assert ((*env) != NULL);
+ assert(env!=NULL);
+ assert((*env)!=NULL);
- cls = (*env)->FindClass (env, "java/lang/Boolean");
+ cls = (*env)->FindClass(env, "java/lang/Boolean");
if (cls == NULL)
return NULL;
- mid = (*env)->GetMethodID (env, cls, "<init>", "(Z)V");
+ mid = (*env)->GetMethodID(env, cls, "<init>", "(Z)V");
if (mid == NULL)
return NULL;
- obj = (*env)->NewObject (env, cls, mid, val);
+ obj = (*env)->NewObject(env, cls, mid, val);
if (obj == NULL)
return NULL;
@@ -218,24 +218,24 @@ _javanet_create_boolean (JNIEnv *env, jboolean val)
* Returns an Integer object with the specfied value
*/
static jobject
-_javanet_create_integer (JNIEnv *env, jint val)
+_javanet_create_integer(JNIEnv *env, jint val)
{
jclass cls;
jmethodID mid;
jobject obj;
- assert (env != NULL);
- assert ((*env) != NULL);
+ assert(env!=NULL);
+ assert((*env)!=NULL);
- cls = (*env)->FindClass (env, "java/lang/Integer");
+ cls = (*env)->FindClass(env, "java/lang/Integer");
if (cls == NULL)
return NULL;
- mid = (*env)->GetMethodID (env, cls, "<init>", "(I)V");
+ mid = (*env)->GetMethodID(env, cls, "<init>", "(I)V");
if (mid == NULL)
return NULL;
- obj = (*env)->NewObject (env, cls, mid, val);
+ obj = (*env)->NewObject(env, cls, mid, val);
if (obj == NULL)
return NULL;
@@ -248,58 +248,65 @@ _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, int netaddr)
{
#ifndef WITHOUT_NETWORK
unsigned char octets[4];
- char buf[16];
- jclass ia_cls;
- jmethodID mid;
- jstring ip_str;
- jobject ia;
+ char buf[16];
+ jclass ia_cls;
+ jmethodID mid;
+ jstring ip_str;
+ jobject ia;
- assert (env != NULL);
- assert ((*env) != NULL);
+ assert(env!=NULL);
+ assert((*env)!=NULL);
/* Build a string IP address */
- TARGET_NATIVE_NETWORK_INT_TO_IPADDRESS_BYTES (netaddr,
- octets[0],
- octets[1],
- octets[2], octets[3]);
- sprintf (buf, "%d.%d.%d.%d", octets[0], octets[1], octets[2], octets[3]);
- DBG ("_javanet_create_inetaddress(): Created ip addr string\n");
+ TARGET_NATIVE_NETWORK_INT_TO_IPADDRESS_BYTES(netaddr,
+ octets[0],
+ octets[1],
+ octets[2],
+ octets[3]
+ );
+ sprintf(buf, "%d.%d.%d.%d",
+ octets[0],
+ octets[1],
+ octets[2],
+ octets[3]
+ );
+ DBG("_javanet_create_inetaddress(): Created ip addr string\n");
/* Get an InetAddress object for this IP */
- ia_cls = (*env)->FindClass (env, "java/net/InetAddress");
+ ia_cls = (*env)->FindClass(env, "java/net/InetAddress");
if (ia_cls == NULL)
{
return NULL;
}
- DBG ("_javanet_create_inetaddress(): Found InetAddress class\n");
+ DBG("_javanet_create_inetaddress(): Found InetAddress class\n");
- mid = (*env)->GetStaticMethodID (env, ia_cls, "getByName",
- "(Ljava/lang/String;)Ljava/net/InetAddress;");
+ mid = (*env)->GetStaticMethodID(env, ia_cls, "getByName",
+ "(Ljava/lang/String;)Ljava/net/InetAddress;");
if (mid == NULL)
{
return NULL;
}
- DBG ("_javanet_create_inetaddress(): Found getByName method\n");
+ DBG("_javanet_create_inetaddress(): Found getByName method\n");
- ip_str = (*env)->NewStringUTF (env, buf);
+ ip_str = (*env)->NewStringUTF(env, buf);
if (ip_str == NULL)
{
return NULL;
}
- ia = (*env)->CallStaticObjectMethod (env, ia_cls, mid, ip_str);
+ ia = (*env)->CallStaticObjectMethod(env, ia_cls, mid, ip_str);
if (ia == NULL)
{
return NULL;
}
- DBG ("_javanet_create_inetaddress(): Called getByName method\n");
+ DBG("_javanet_create_inetaddress(): Called getByName method\n");
return ia;
#else /* not WITHOUT_NETWORK */
@@ -310,28 +317,27 @@ _javanet_create_inetaddress (JNIEnv *env, int netaddr)
/*************************************************************************/
static void
-_javanet_set_remhost_addr (JNIEnv *env, jobject this, jobject ia)
+_javanet_set_remhost_addr(JNIEnv *env, jobject this, jobject ia)
{
- jclass this_cls;
+ jclass this_cls;
jfieldID fid;
- assert (env != NULL);
- assert ((*env) != NULL);
+ assert(env!=NULL);
+ assert((*env)!=NULL);
/* Set the variable in the object */
- this_cls = (*env)->FindClass (env, "java/net/SocketImpl");
+ this_cls = (*env)->FindClass(env, "java/net/SocketImpl");
if (this_cls == NULL)
return;
- fid =
- (*env)->GetFieldID (env, this_cls, "address", "Ljava/net/InetAddress;");
+ fid = (*env)->GetFieldID(env, this_cls, "address", "Ljava/net/InetAddress;");
if (fid == NULL)
return;
- DBG ("_javanet_set_remhost_addr(): Found address field\n");
+ DBG("_javanet_set_remhost_addr(): Found address field\n");
- (*env)->SetObjectField (env, this, fid, ia);
- DBG ("_javanet_set_remhost_addr(): Set field\n");
+ (*env)->SetObjectField(env, this, fid, ia);
+ DBG("_javanet_set_remhost_addr(): Set field\n");
}
/*
@@ -339,21 +345,21 @@ _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, int netaddr)
{
jobject ia;
- assert (env != NULL);
- assert ((*env) != NULL);
+ assert(env!=NULL);
+ assert((*env)!=NULL);
- DBG ("_javanet_set_remhost(): Entered _javanet_set_remhost\n");
+ DBG("_javanet_set_remhost(): Entered _javanet_set_remhost\n");
/* Get an InetAddress object */
- ia = _javanet_create_inetaddress (env, netaddr);
+ ia = _javanet_create_inetaddress(env, netaddr);
if (ia == NULL)
return;
- _javanet_set_remhost_addr (env, this, ia);
+ _javanet_set_remhost_addr(env, this, ia);
}
@@ -363,61 +369,63 @@ _javanet_set_remhost (JNIEnv *env, jobject this, int netaddr)
* Returns a 32 bit Internet address for the passed in InetAddress object
*/
int
-_javanet_get_netaddr (JNIEnv *env, jobject addr)
+_javanet_get_netaddr(JNIEnv *env, jobject addr)
{
#ifndef WITHOUT_NETWORK
- jclass cls = 0;
+ jclass cls = 0;
jmethodID mid;
- jarray arr = 0;
- jbyte *octets;
- int netaddr, len;
+ jarray arr = 0;
+ jbyte *octets;
+ int netaddr, len;
- assert (env != NULL);
- assert ((*env) != NULL);
+ assert(env!=NULL);
+ assert((*env)!=NULL);
- DBG ("_javanet_get_netaddr(): Entered _javanet_get_netaddr\n");
+ DBG("_javanet_get_netaddr(): Entered _javanet_get_netaddr\n");
/* Call the getAddress method on the object to retrieve the IP address */
- cls = (*env)->GetObjectClass (env, addr);
+ cls = (*env)->GetObjectClass(env, addr);
if (cls == NULL)
return 0;
- mid = (*env)->GetMethodID (env, cls, "getAddress", "()[B");
+ mid = (*env)->GetMethodID(env, cls, "getAddress", "()[B");
if (mid == NULL)
return 0;
- DBG ("_javanet_get_netaddr(): Got getAddress method\n");
+ DBG("_javanet_get_netaddr(): Got getAddress method\n");
- arr = (*env)->CallObjectMethod (env, addr, mid);
+ arr = (*env)->CallObjectMethod(env, addr, mid);
if (arr == NULL)
return 0;
- DBG ("_javanet_get_netaddr(): Got the address\n");
+ DBG("_javanet_get_netaddr(): Got the address\n");
/* Turn the IP address into a 32 bit Internet address in network byte order */
- len = (*env)->GetArrayLength (env, arr);
+ len = (*env)->GetArrayLength(env, arr);
if (len != 4)
{
- JCL_ThrowException (env, IO_EXCEPTION, "Internal Error");
+ JCL_ThrowException(env, IO_EXCEPTION, "Internal Error");
return 0;
}
- DBG ("_javanet_get_netaddr(): Length ok\n");
+ DBG("_javanet_get_netaddr(): Length ok\n");
- octets = (*env)->GetByteArrayElements (env, arr, 0);
+ octets = (*env)->GetByteArrayElements(env, arr, 0);
if (octets == NULL)
return 0;
- DBG ("_javanet_get_netaddr(): Grabbed bytes\n");
+ DBG("_javanet_get_netaddr(): Grabbed bytes\n");
- TARGET_NATIVE_NETWORK_IPADDRESS_BYTES_TO_INT (octets[0],
- octets[1],
- octets[2],
- octets[3], netaddr);
+ TARGET_NATIVE_NETWORK_IPADDRESS_BYTES_TO_INT(octets[0],
+ octets[1],
+ octets[2],
+ octets[3],
+ netaddr
+ );
- (*env)->ReleaseByteArrayElements (env, arr, octets, 0);
- DBG ("_javanet_get_netaddr(): Done getting addr\n");
+ (*env)->ReleaseByteArrayElements(env, arr, octets, 0);
+ DBG("_javanet_get_netaddr(): Done getting addr\n");
- return netaddr;
+ return netaddr;
#else /* not WITHOUT_NETWORK */
#endif /* not WITHOUT_NETWORK */
}
@@ -428,51 +436,48 @@ _javanet_get_netaddr (JNIEnv *env, jobject addr)
* Creates a new stream or datagram socket
*/
void
-_javanet_create (JNIEnv *env, jobject this, jboolean stream)
+_javanet_create(JNIEnv *env, jobject this, jboolean stream)
{
#ifndef WITHOUT_NETWORK
int fd;
int result;
- assert (env != NULL);
- assert ((*env) != NULL);
+ assert(env!=NULL);
+ assert((*env)!=NULL);
if (stream)
{
/* create a stream socket */
- TARGET_NATIVE_NETWORK_SOCKET_OPEN_STREAM (fd, result);
+ TARGET_NATIVE_NETWORK_SOCKET_OPEN_STREAM(fd,result);
if (result != TARGET_NATIVE_OK)
- {
- JCL_ThrowException (env, IO_EXCEPTION,
- TARGET_NATIVE_LAST_ERROR_STRING ());
- return;
- }
+ {
+ JCL_ThrowException(env, IO_EXCEPTION, TARGET_NATIVE_LAST_ERROR_STRING());
+ return;
+ }
}
else
{
/* create a datagram socket, set broadcast option */
- TARGET_NATIVE_NETWORK_SOCKET_OPEN_DATAGRAM (fd, result);
+ TARGET_NATIVE_NETWORK_SOCKET_OPEN_DATAGRAM(fd,result);
if (result != TARGET_NATIVE_OK)
- {
- JCL_ThrowException (env, IO_EXCEPTION,
- TARGET_NATIVE_LAST_ERROR_STRING ());
- return;
- }
- TARGET_NATIVE_NETWORK_SOCKET_SET_OPTION_BROADCAST (fd, 1, result);
+ {
+ JCL_ThrowException(env, IO_EXCEPTION, TARGET_NATIVE_LAST_ERROR_STRING());
+ return;
+ }
+ TARGET_NATIVE_NETWORK_SOCKET_SET_OPTION_BROADCAST(fd,1,result);
if (result != TARGET_NATIVE_OK)
- {
- JCL_ThrowException (env, IO_EXCEPTION,
- TARGET_NATIVE_LAST_ERROR_STRING ());
- return;
- }
+ {
+ JCL_ThrowException(env, IO_EXCEPTION, TARGET_NATIVE_LAST_ERROR_STRING());
+ return;
+ }
}
-
+
if (stream)
- _javanet_set_int_field (env, this, "gnu/java/net/PlainSocketImpl",
- "native_fd", fd);
+ _javanet_set_int_field(env, this, "gnu/java/net/PlainSocketImpl",
+ "native_fd", fd);
else
- _javanet_set_int_field (env, this, "gnu/java/net/PlainDatagramSocketImpl",
- "native_fd", fd);
+ _javanet_set_int_field(env, this, "gnu/java/net/PlainDatagramSocketImpl",
+ "native_fd", fd);
#else /* not WITHOUT_NETWORK */
#endif /* not WITHOUT_NETWORK */
}
@@ -484,27 +489,27 @@ _javanet_create (JNIEnv *env, jobject this, jboolean stream)
* action as well.
*/
void
-_javanet_close (JNIEnv *env, jobject this, int stream)
+_javanet_close(JNIEnv *env, jobject this, int stream)
{
#ifndef WITHOUT_NETWORK
int fd;
int result;
- assert (env != NULL);
- assert ((*env) != NULL);
+ assert(env!=NULL);
+ assert((*env)!=NULL);
- fd = _javanet_get_int_field (env, this, "native_fd");
+ fd = _javanet_get_int_field(env, this, "native_fd");
if (fd == -1)
return;
-
- TARGET_NATIVE_NETWORK_SOCKET_CLOSE (fd, result);
+
+ TARGET_NATIVE_NETWORK_SOCKET_CLOSE(fd,result);
if (stream)
- _javanet_set_int_field (env, this, "gnu/java/net/PlainSocketImpl",
- "native_fd", -1);
+ _javanet_set_int_field(env, this, "gnu/java/net/PlainSocketImpl",
+ "native_fd", -1);
else
- _javanet_set_int_field (env, this, "gnu/java/net/PlainDatagramSocketImpl",
- "native_fd", -1);
+ _javanet_set_int_field(env, this, "gnu/java/net/PlainDatagramSocketImpl",
+ "native_fd", -1);
#else /* not WITHOUT_NETWORK */
#endif /* not WITHOUT_NETWORK */
}
@@ -514,110 +519,105 @@ _javanet_close (JNIEnv *env, jobject this, int stream)
/*
* Connects to the specified destination.
*/
-void
-_javanet_connect (JNIEnv *env, jobject this, jobject addr, jint port)
+void
+_javanet_connect(JNIEnv *env, jobject this, jobject addr, jint port)
{
#ifndef WITHOUT_NETWORK
int netaddr, fd;
int result;
- int local_address, local_port;
- int remote_address, remote_port;
+ int local_address,local_port;
+ int remote_address,remote_port;
- assert (env != NULL);
- assert ((*env) != NULL);
+ assert(env!=NULL);
+ assert((*env)!=NULL);
- DBG ("_javanet_connect(): Entered _javanet_connect\n");
+ DBG("_javanet_connect(): Entered _javanet_connect\n");
/* Pre-process input variables */
- netaddr = _javanet_get_netaddr (env, addr);
- if ((*env)->ExceptionOccurred (env))
+ netaddr = _javanet_get_netaddr(env, addr);
+ if ((*env)->ExceptionOccurred(env))
return;
if (port == -1)
port = 0;
- DBG ("_javanet_connect(): Got network address\n");
+ DBG("_javanet_connect(): Got network address\n");
/* Grab the real socket file descriptor */
- fd = _javanet_get_int_field (env, this, "native_fd");
+ fd = _javanet_get_int_field(env, this, "native_fd");
if (fd == -1)
- {
- JCL_ThrowException (env, IO_EXCEPTION,
- "Internal error: _javanet_connect(): no native file descriptor");
- return;
+ {
+ JCL_ThrowException(env, IO_EXCEPTION,
+ "Internal error: _javanet_connect(): no native file descriptor");
+ return;
}
- DBG ("_javanet_connect(): Got native fd\n");
+ DBG("_javanet_connect(): Got native fd\n");
/* Connect up */
- TARGET_NATIVE_NETWORK_SOCKET_CONNECT (fd, netaddr, port, result);
+ TARGET_NATIVE_NETWORK_SOCKET_CONNECT(fd,netaddr,port,result);
if (result != TARGET_NATIVE_OK)
{
- JCL_ThrowException (env, IO_EXCEPTION,
- TARGET_NATIVE_LAST_ERROR_STRING ());
- return;
+ JCL_ThrowException(env, IO_EXCEPTION, TARGET_NATIVE_LAST_ERROR_STRING());
+ return;
}
- DBG ("_javanet_connect(): Connected successfully\n");
+ DBG("_javanet_connect(): Connected successfully\n");
/* Populate instance variables */
- TARGET_NATIVE_NETWORK_SOCKET_GET_LOCAL_INFO (fd, local_address, local_port,
- result);
+ TARGET_NATIVE_NETWORK_SOCKET_GET_LOCAL_INFO(fd,local_address,local_port,result);
if (result != TARGET_NATIVE_OK)
{
- TARGET_NATIVE_NETWORK_SOCKET_CLOSE (fd, result);
- JCL_ThrowException (env, IO_EXCEPTION,
- TARGET_NATIVE_LAST_ERROR_STRING ());
+ TARGET_NATIVE_NETWORK_SOCKET_CLOSE(fd,result);
+ JCL_ThrowException(env, IO_EXCEPTION, TARGET_NATIVE_LAST_ERROR_STRING());
return;
}
- _javanet_create_localfd (env, this);
- if ((*env)->ExceptionOccurred (env))
+ _javanet_create_localfd(env, this);
+ if ((*env)->ExceptionOccurred(env))
{
- TARGET_NATIVE_NETWORK_SOCKET_CLOSE (fd, result);
+ TARGET_NATIVE_NETWORK_SOCKET_CLOSE(fd,result);
return;
}
- DBG ("_javanet_connect(): Created fd\n");
+ DBG("_javanet_connect(): Created fd\n");
- _javanet_set_int_field (env, this, "java/net/SocketImpl", "localport",
- local_port);
- if ((*env)->ExceptionOccurred (env))
+ _javanet_set_int_field(env, this, "java/net/SocketImpl", "localport",
+ local_port);
+ if ((*env)->ExceptionOccurred(env))
{
- TARGET_NATIVE_NETWORK_SOCKET_CLOSE (fd, result);
+ TARGET_NATIVE_NETWORK_SOCKET_CLOSE(fd,result);
return;
}
- DBG ("_javanet_connect(): Set the local port\n");
-
- TARGET_NATIVE_NETWORK_SOCKET_GET_REMOTE_INFO (fd, remote_address,
- remote_port, result);
+ DBG("_javanet_connect(): Set the local port\n");
+
+ TARGET_NATIVE_NETWORK_SOCKET_GET_REMOTE_INFO(fd,remote_address,remote_port,result);
if (result != TARGET_NATIVE_OK)
{
- TARGET_NATIVE_NETWORK_SOCKET_CLOSE (fd, result);
- JCL_ThrowException (env, IO_EXCEPTION,
- TARGET_NATIVE_LAST_ERROR_STRING ());
+ TARGET_NATIVE_NETWORK_SOCKET_CLOSE(fd,result);
+ JCL_ThrowException(env, IO_EXCEPTION, TARGET_NATIVE_LAST_ERROR_STRING());
return;
}
if (remote_address == netaddr)
{
- _javanet_set_remhost_addr (env, this, addr);
+ _javanet_set_remhost_addr(env, this, addr);
}
else
{
- _javanet_set_remhost (env, this, remote_address);
+ _javanet_set_remhost(env, this, remote_address);
}
- if ((*env)->ExceptionOccurred (env))
+ if ((*env)->ExceptionOccurred(env))
{
- TARGET_NATIVE_NETWORK_SOCKET_CLOSE (fd, result);
+ TARGET_NATIVE_NETWORK_SOCKET_CLOSE(fd,result);
return;
}
- DBG ("_javanet_connect(): Set the remote host\n");
+ DBG("_javanet_connect(): Set the remote host\n");
- _javanet_set_int_field (env, this, "java/net/SocketImpl", "port",
- remote_port);
- if ((*env)->ExceptionOccurred (env))
+ _javanet_set_int_field(env, this, "java/net/SocketImpl", "port",
+ remote_port);
+ if ((*env)->ExceptionOccurred(env))
{
- TARGET_NATIVE_NETWORK_SOCKET_CLOSE (fd, result);
+ 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 */
}
@@ -630,100 +630,95 @@ _javanet_connect (JNIEnv *env, jobject this, jobject addr, jint port)
* port public instance variables.
*/
void
-_javanet_bind (JNIEnv *env, jobject this, jobject addr, jint port, int stream)
+_javanet_bind(JNIEnv *env, jobject this, jobject addr, jint port, int stream)
{
#ifndef WITHOUT_NETWORK
- jclass cls;
- jmethodID mid;
+ jclass cls;
+ jmethodID mid;
jbyteArray arr = 0;
- jbyte *octets;
- jint fd;
- int tmpaddr;
- int result;
- int local_address, local_port;
+ jbyte *octets;
+ jint fd;
+ int tmpaddr;
+ int result;
+ int local_address,local_port;
- assert (env != NULL);
- assert ((*env) != NULL);
+ assert(env!=NULL);
+ assert((*env)!=NULL);
- DBG ("_javanet_bind(): Entering native bind()\n");
+ DBG("_javanet_bind(): Entering native bind()\n");
/* Get the address to connect to */
- cls = (*env)->GetObjectClass (env, addr);
+ cls = (*env)->GetObjectClass(env, addr);
if (cls == NULL)
return;
- mid = (*env)->GetMethodID (env, cls, "getAddress", "()[B");
+ mid = (*env)->GetMethodID(env, cls, "getAddress", "()[B");
if (mid == NULL)
return;
- DBG ("_javanet_bind(): Past getAddress method id\n");
+ 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;
- }
+ 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");
+ DBG("_javanet_bind(): Past call object method\n");
- octets = (*env)->GetByteArrayElements (env, arr, 0);
+ octets = (*env)->GetByteArrayElements(env, arr, 0);
if (octets == NULL)
return;
- DBG ("_javanet_bind(): Past grab array\n");
+ DBG("_javanet_bind(): Past grab array\n");
/* Get the native socket file descriptor */
- fd = _javanet_get_int_field (env, this, "native_fd");
+ 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");
+ (*env)->ReleaseByteArrayElements(env, arr, octets, 0);
+ JCL_ThrowException(env, IO_EXCEPTION,
+ "Internal error: _javanet_bind(): no native file descriptor");
return;
}
- DBG ("_javanet_bind(): Past native_fd lookup\n");
+ DBG("_javanet_bind(): Past native_fd lookup\n");
// NYI ???
- _javanet_set_option (env, this, SOCKOPT_SO_REUSEADDR,
+ _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);
+ 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);
- (*env)->ReleaseByteArrayElements (env, arr, octets, 0);
+ (*env)->ReleaseByteArrayElements(env, arr, octets, 0);
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;
}
- DBG ("_javanet_bind(): Past bind\n");
-
+ DBG("_javanet_bind(): Past bind\n");
+
/* Update instance variables, specifically the local port number */
- TARGET_NATIVE_NETWORK_SOCKET_GET_LOCAL_INFO (fd, local_address, local_port,
- result);
+ TARGET_NATIVE_NETWORK_SOCKET_GET_LOCAL_INFO(fd,local_address,local_port,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;
}
if (stream)
- _javanet_set_int_field (env, this, "java/net/SocketImpl",
- "localport", local_port);
+ _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);
- DBG ("_javanet_bind(): Past update port number\n");
+ _javanet_set_int_field(env, this, "java/net/DatagramSocketImpl",
+ "localPort", local_port);
+ DBG("_javanet_bind(): Past update port number\n");
return;
#else /* not WITHOUT_NETWORK */
@@ -736,31 +731,30 @@ _javanet_bind (JNIEnv *env, jobject this, jobject addr, jint port, int stream)
* Starts listening on a socket with the specified number of pending
* connections allowed.
*/
-void
-_javanet_listen (JNIEnv *env, jobject this, jint queuelen)
+void
+_javanet_listen(JNIEnv *env, jobject this, jint queuelen)
{
#ifndef WITHOUT_NETWORK
int fd;
int result;
- assert (env != NULL);
- assert ((*env) != NULL);
+ assert(env!=NULL);
+ assert((*env)!=NULL);
/* Get the real file descriptor */
- fd = _javanet_get_int_field (env, this, "native_fd");
+ fd = _javanet_get_int_field(env, this, "native_fd");
if (fd == -1)
- {
- JCL_ThrowException (env, IO_EXCEPTION,
- "Internal error: _javanet_listen(): no native file descriptor");
- return;
+ {
+ JCL_ThrowException(env, IO_EXCEPTION,
+ "Internal error: _javanet_listen(): no native file descriptor");
+ return;
}
/* Start listening */
- TARGET_NATIVE_NETWORK_SOCKET_LISTEN (fd, queuelen, result);
- if (result != TARGET_NATIVE_OK)
+ TARGET_NATIVE_NETWORK_SOCKET_LISTEN(fd,queuelen,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;
}
#else /* not WITHOUT_NETWORK */
@@ -773,94 +767,89 @@ _javanet_listen (JNIEnv *env, jobject this, jint queuelen)
* Accepts a new connection and assigns it to the passed in SocketImpl
* object. Note that we assume this is a PlainSocketImpl just like us
*/
-void
-_javanet_accept (JNIEnv *env, jobject this, jobject impl)
+void
+_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;
+ int local_address,local_port;
+ int remote_address,remote_port;
- assert (env != NULL);
- assert ((*env) != NULL);
+ assert(env!=NULL);
+ assert((*env)!=NULL);
/* Get the real file descriptor */
- fd = _javanet_get_int_field (env, this, "native_fd");
+ fd = _javanet_get_int_field(env, this, "native_fd");
if (fd == -1)
- {
- JCL_ThrowException (env, IO_EXCEPTION,
- "Internal error: _javanet_accept(): no native file descriptor");
- return;
+ {
+ JCL_ThrowException(env, IO_EXCEPTION,
+ "Internal error: _javanet_accept(): no native file descriptor");
+ return;
}
/* Accept the connection */
/******* Do we need to look for EINTR? */
- TARGET_NATIVE_NETWORK_SOCKET_ACCEPT (fd, newfd, result);
+ TARGET_NATIVE_NETWORK_SOCKET_ACCEPT(fd,newfd,result);
if (result != TARGET_NATIVE_OK)
{
- JCL_ThrowException (env, IO_EXCEPTION,
- "Internal error: _javanet_accept(): ");
- return;
+ JCL_ThrowException(env, IO_EXCEPTION, "Internal error: _javanet_accept(): ");
+ return;
}
- /* Populate instance variables */
- _javanet_set_int_field (env, impl, "gnu/java/net/PlainSocketImpl",
- "native_fd", newfd);
+ /* Populate instance variables */
+ _javanet_set_int_field(env, impl, "gnu/java/net/PlainSocketImpl", "native_fd",
+ newfd);
- if ((*env)->ExceptionOccurred (env))
+ if ((*env)->ExceptionOccurred(env))
{
- TARGET_NATIVE_NETWORK_SOCKET_CLOSE (newfd, result);
+ TARGET_NATIVE_NETWORK_SOCKET_CLOSE(newfd,result);
return;
}
- TARGET_NATIVE_NETWORK_SOCKET_GET_LOCAL_INFO (newfd, local_address,
- local_port, result);
- if (result != TARGET_NATIVE_OK)
+ TARGET_NATIVE_NETWORK_SOCKET_GET_LOCAL_INFO(newfd,local_address,local_port,result);
+ if (result!=TARGET_NATIVE_OK)
{
- TARGET_NATIVE_NETWORK_SOCKET_CLOSE (newfd, result);
- JCL_ThrowException (env, IO_EXCEPTION,
- TARGET_NATIVE_LAST_ERROR_STRING ());
+ TARGET_NATIVE_NETWORK_SOCKET_CLOSE(newfd,result);
+ JCL_ThrowException(env, IO_EXCEPTION, TARGET_NATIVE_LAST_ERROR_STRING());
return;
}
- _javanet_create_localfd (env, impl);
- if ((*env)->ExceptionOccurred (env))
+ _javanet_create_localfd(env, impl);
+ if ((*env)->ExceptionOccurred(env))
{
- TARGET_NATIVE_NETWORK_SOCKET_CLOSE (newfd, result);
+ TARGET_NATIVE_NETWORK_SOCKET_CLOSE(newfd,result);
return;
}
- _javanet_set_int_field (env, impl, "java/net/SocketImpl", "localport",
- local_port);
- if ((*env)->ExceptionOccurred (env))
+ _javanet_set_int_field(env, impl, "java/net/SocketImpl", "localport",
+ local_port);
+ if ((*env)->ExceptionOccurred(env))
{
- TARGET_NATIVE_NETWORK_SOCKET_CLOSE (newfd, result);
+ TARGET_NATIVE_NETWORK_SOCKET_CLOSE(newfd,result);
return;
}
-
- TARGET_NATIVE_NETWORK_SOCKET_GET_REMOTE_INFO (newfd, remote_address,
- remote_port, result);
- if (result != TARGET_NATIVE_OK)
+
+ TARGET_NATIVE_NETWORK_SOCKET_GET_REMOTE_INFO(newfd,remote_address,remote_port,result);
+ if (result!=TARGET_NATIVE_OK)
{
- TARGET_NATIVE_NETWORK_SOCKET_CLOSE (newfd, result);
- JCL_ThrowException (env, IO_EXCEPTION,
- TARGET_NATIVE_LAST_ERROR_STRING ());
+ TARGET_NATIVE_NETWORK_SOCKET_CLOSE(newfd,result);
+ JCL_ThrowException(env, IO_EXCEPTION, TARGET_NATIVE_LAST_ERROR_STRING());
return;
}
- _javanet_set_remhost (env, impl, remote_address);
- if ((*env)->ExceptionOccurred (env))
+ _javanet_set_remhost(env, impl, remote_address);
+ if ((*env)->ExceptionOccurred(env))
{
- TARGET_NATIVE_NETWORK_SOCKET_CLOSE (newfd, result);
+ TARGET_NATIVE_NETWORK_SOCKET_CLOSE(newfd,result);
return;
}
- _javanet_set_int_field (env, impl, "java/net/SocketImpl", "port",
- remote_port);
- if ((*env)->ExceptionOccurred (env))
+ _javanet_set_int_field(env, impl, "java/net/SocketImpl", "port",
+ remote_port);
+ if ((*env)->ExceptionOccurred(env))
{
- TARGET_NATIVE_NETWORK_SOCKET_CLOSE (newfd, result);
+ TARGET_NATIVE_NETWORK_SOCKET_CLOSE(newfd,result);
return;
}
#else /* not WITHOUT_NETWORK */
@@ -884,68 +873,59 @@ _javanet_accept (JNIEnv *env, jobject this, jobject impl)
* The actual number of bytes read is returned.
*/
int
-_javanet_recvfrom (JNIEnv *env, jobject this, jarray buf, int offset, int len,
- int *addr, int *port)
+_javanet_recvfrom(JNIEnv *env, jobject this, jarray buf, int offset, int len,
+ int *addr, int *port)
{
#ifndef WITHOUT_NETWORK
- int fd;
+ int fd;
jbyte *p;
- int from_address, from_port;
- int received_bytes;
+ int from_address,from_port;
+ int received_bytes;
- assert (env != NULL);
- assert ((*env) != NULL);
+ assert(env!=NULL);
+ assert((*env)!=NULL);
- DBG ("_javanet_recvfrom(): Entered _javanet_recvfrom\n");
+ DBG("_javanet_recvfrom(): Entered _javanet_recvfrom\n");
/* Get the real file descriptor */
- fd = _javanet_get_int_field (env, this, "native_fd");
+ fd = _javanet_get_int_field(env, this, "native_fd");
if (fd == -1)
- {
- JCL_ThrowException (env, IO_EXCEPTION,
- "Internal error: _javanet_recvfrom(): no native file descriptor");
- return 0;
+ {
+ JCL_ThrowException(env, IO_EXCEPTION,
+ "Internal error: _javanet_recvfrom(): no native file descriptor");
+ return 0;
}
- DBG ("_javanet_recvfrom(): Got native_fd\n");
+ DBG("_javanet_recvfrom(): Got native_fd\n");
/* Get a pointer to the buffer */
- p = (*env)->GetByteArrayElements (env, buf, 0);
+ p = (*env)->GetByteArrayElements(env, buf, 0);
if (p == NULL)
return 0;
- DBG ("_javanet_recvfrom(): Got buffer\n");
+ DBG("_javanet_recvfrom(): Got buffer\n");
/* Read the data */
from_address = 0;
- from_port = 0;
- do
- {
- if (addr != NULL)
- {
- TARGET_NATIVE_NETWORK_SOCKET_RECEIVE_WITH_ADDRESS_PORT (fd,
- p + offset,
- len,
- from_address,
- from_port,
- received_bytes);
- }
- else
- {
- TARGET_NATIVE_NETWORK_SOCKET_RECEIVE (fd, p + offset, len,
- received_bytes);
- }
- }
- while ((received_bytes == -1) &&
- (TARGET_NATIVE_LAST_ERROR () ==
- TARGET_NATIVE_ERROR_INTERRUPT_FUNCTION_CALL));
-
- (*env)->ReleaseByteArrayElements (env, buf, p, 0);
+ from_port = 0;
+ do {
+ if (addr != NULL)
+ {
+ TARGET_NATIVE_NETWORK_SOCKET_RECEIVE_WITH_ADDRESS_PORT(fd,p+offset,len,from_address,from_port,received_bytes);
+ }
+ else
+ {
+ TARGET_NATIVE_NETWORK_SOCKET_RECEIVE(fd,p+offset,len,received_bytes);
+ }
+ } while ((received_bytes == -1) &&
+ (TARGET_NATIVE_LAST_ERROR() == TARGET_NATIVE_ERROR_INTERRUPT_FUNCTION_CALL)
+ );
+
+ (*env)->ReleaseByteArrayElements(env, buf, p, 0);
if (received_bytes == -1)
{
- JCL_ThrowException (env, IO_EXCEPTION,
- TARGET_NATIVE_LAST_ERROR_STRING ());
- return 0;
+ JCL_ThrowException(env, IO_EXCEPTION, TARGET_NATIVE_LAST_ERROR_STRING());
+ return 0;
}
/* Handle return addr case */
@@ -953,10 +933,10 @@ _javanet_recvfrom (JNIEnv *env, jobject this, jarray buf, int offset, int len,
{
(*addr) = from_address;
if (port != NULL)
- (*port) = from_port;
+ (*port) = from_port;
}
- return (received_bytes);
+ return(received_bytes);
#else /* not WITHOUT_NETWORK */
#endif /* not WITHOUT_NETWORK */
}
@@ -972,53 +952,50 @@ _javanet_recvfrom (JNIEnv *env, jobject this, jarray buf, int offset, int len,
* addr - The 32bit address to send to (may be 0)
* port - The port number to send to (may be 0)
*/
-void
-_javanet_sendto (JNIEnv *env, jobject this, jarray buf, int offset, int len,
- int addr, int port)
+void
+_javanet_sendto(JNIEnv *env, jobject this, jarray buf, int offset, int len,
+ int addr, int port)
{
#ifndef WITHOUT_NETWORK
- int fd;
+ int fd;
jbyte *p;
- int bytes_sent;
+ int bytes_sent;
- assert (env != NULL);
- assert ((*env) != NULL);
+ assert(env!=NULL);
+ assert((*env)!=NULL);
/* Get the real file descriptor */
- fd = _javanet_get_int_field (env, this, "native_fd");
+ fd = _javanet_get_int_field(env, this, "native_fd");
if (fd == -1)
- {
- JCL_ThrowException (env, IO_EXCEPTION,
- "Internal error: _javanet_sendto(): no native file descriptor");
- return;
+ {
+ JCL_ThrowException(env, IO_EXCEPTION,
+ "Internal error: _javanet_sendto(): no native file descriptor");
+ return;
}
/* Get a pointer to the buffer */
- p = (*env)->GetByteArrayElements (env, buf, 0);
+ p = (*env)->GetByteArrayElements(env, buf, 0);
if (p == NULL)
return;
/* Send the data */
if (addr == 0)
{
- DBG ("_javanet_sendto(): Sending....\n");
- TARGET_NATIVE_NETWORK_SOCKET_SEND (fd, p + offset, len, bytes_sent);
+ DBG("_javanet_sendto(): Sending....\n");
+ TARGET_NATIVE_NETWORK_SOCKET_SEND(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);
+ DBG("_javanet_sendto(): Sending....\n");
+ TARGET_NATIVE_NETWORK_SOCKET_SEND_WITH_ADDRESS_PORT(fd,p+offset,len,addr,port,bytes_sent);
}
- (*env)->ReleaseByteArrayElements (env, buf, p, 0);
+ (*env)->ReleaseByteArrayElements(env, buf, p, 0);
/***** Do we need to check EINTR? */
- if (bytes_sent < 0)
+ if (bytes_sent<0)
{
- JCL_ThrowException (env, IO_EXCEPTION,
- TARGET_NATIVE_LAST_ERROR_STRING ());
+ JCL_ThrowException(env, IO_EXCEPTION, TARGET_NATIVE_LAST_ERROR_STRING());
return;
}
#else /* not WITHOUT_NETWORK */
@@ -1030,31 +1007,31 @@ _javanet_sendto (JNIEnv *env, jobject this, jarray buf, int offset, int len,
/*
* Sets the specified option for a socket
*/
-void
-_javanet_set_option (JNIEnv *env, jobject this, jint option_id, jobject val)
+void
+_javanet_set_option(JNIEnv *env, jobject this, jint option_id, jobject val)
{
#ifndef WITHOUT_NETWORK
- int fd;
- int optval;
- jclass cls;
+ int fd;
+ int optval;
+ jclass cls;
jmethodID mid;
- int address;
- int result;
+ int address;
+ int result;
- assert (env != NULL);
- assert ((*env) != NULL);
+ assert(env!=NULL);
+ assert((*env)!=NULL);
/* Get the real file descriptor */
- fd = _javanet_get_int_field (env, this, "native_fd");
+ fd = _javanet_get_int_field(env, this, "native_fd");
if (fd == -1)
- {
- JCL_ThrowException (env, IO_EXCEPTION,
- "Internal error: _javanet_set_option(): no native file descriptor");
- return;
+ {
+ JCL_ThrowException(env, IO_EXCEPTION,
+ "Internal error: _javanet_set_option(): no native file descriptor");
+ return;
}
/* We need a class object for all cases below */
- cls = (*env)->GetObjectClass (env, val);
+ cls = (*env)->GetObjectClass(env, val);
if (cls == NULL)
return;
@@ -1063,180 +1040,151 @@ _javanet_set_option (JNIEnv *env, jobject this, jint option_id, jobject val)
switch (option_id)
{
/* TCP_NODELAY case. val is a Boolean that tells us what to do */
- case SOCKOPT_TCP_NODELAY:
- mid = (*env)->GetMethodID (env, cls, "booleanValue", "()Z");
- if (mid == NULL)
- {
- JCL_ThrowException (env, IO_EXCEPTION,
- "Internal error: _javanet_set_option()");
+ case SOCKOPT_TCP_NODELAY:
+ mid = (*env)->GetMethodID(env, cls, "booleanValue", "()Z");
+ if (mid == NULL)
+ { JCL_ThrowException(env, IO_EXCEPTION,
+ "Internal error: _javanet_set_option()"); return; }
+
+ /* Should be a 0 or a 1 */
+ optval = (*env)->CallBooleanMethod(env, val, mid);
+ if ((*env)->ExceptionOccurred(env))
return;
- }
-
- /* Should be a 0 or a 1 */
- optval = (*env)->CallBooleanMethod (env, val, mid);
- if ((*env)->ExceptionOccurred (env))
- return;
- TARGET_NATIVE_NETWORK_SOCKET_SET_OPTION_TCP_NODELAY (fd, optval,
- result);
- break;
+ TARGET_NATIVE_NETWORK_SOCKET_SET_OPTION_TCP_NODELAY(fd,optval,result);
+ break;
/* SO_LINGER case. If val is a boolean, then it will always be set
to false indicating disable linger, otherwise it will be an
integer that contains the linger value */
- case SOCKOPT_SO_LINGER:
- mid = (*env)->GetMethodID (env, cls, "booleanValue", "()Z");
- if (mid)
- {
- /* We are disabling linger */
- TARGET_NATIVE_NETWORK_SOCKET_SET_OPTION_SO_LINGER (fd, 1, 0,
- result);
- }
- else
- {
- /* Clear exception if thrown for failure to do method lookup
- above */
- if ((*env)->ExceptionOccurred (env))
- (*env)->ExceptionClear (env);
-
- mid = (*env)->GetMethodID (env, cls, "intValue", "()I");
- if (mid == NULL)
- {
- JCL_ThrowException (env, IO_EXCEPTION,
- "Internal error: _javanet_set_option()");
- return;
- }
+ case SOCKOPT_SO_LINGER:
+ mid = (*env)->GetMethodID(env, cls, "booleanValue", "()Z");
+ if (mid)
+ {
+ /* We are disabling linger */
+ TARGET_NATIVE_NETWORK_SOCKET_SET_OPTION_SO_LINGER(fd,1,0,result);
+ }
+ else
+ {
+ /* Clear exception if thrown for failure to do method lookup
+ above */
+ if ((*env)->ExceptionOccurred(env))
+ (*env)->ExceptionClear(env);
+
+ mid = (*env)->GetMethodID(env, cls, "intValue", "()I");
+ if (mid == NULL)
+ { JCL_ThrowException(env, IO_EXCEPTION,
+ "Internal error: _javanet_set_option()"); return; }
- optval = (*env)->CallIntMethod (env, val, mid);
- if ((*env)->ExceptionOccurred (env))
- return;
+ optval= (*env)->CallIntMethod(env, val, mid);
+ if ((*env)->ExceptionOccurred(env))
+ return;
- TARGET_NATIVE_NETWORK_SOCKET_SET_OPTION_SO_LINGER (fd, 0, optval,
- result);
- }
- break;
+ TARGET_NATIVE_NETWORK_SOCKET_SET_OPTION_SO_LINGER(fd,0,optval,result);
+ }
+ break;
/* SO_TIMEOUT case. Val will be an integer with the new value */
/* Not writable on Linux */
- case SOCKOPT_SO_TIMEOUT:
+ case SOCKOPT_SO_TIMEOUT:
#ifdef SO_TIMEOUT
- mid = (*env)->GetMethodID (env, cls, "intValue", "()I");
- if (mid == NULL)
- {
- JCL_ThrowException (env, IO_EXCEPTION,
- "Internal error: _javanet_set_option()");
- return;
- }
+ mid = (*env)->GetMethodID(env, cls, "intValue", "()I");
+ if (mid == NULL)
+ { JCL_ThrowException(env, IO_EXCEPTION,
+ "Internal error: _javanet_set_option()"); return; }
- optval = (*env)->CallIntMethod (env, val, mid);
- if ((*env)->ExceptionOccurred (env))
- return;
+ optval = (*env)->CallIntMethod(env, val, mid);
+ if ((*env)->ExceptionOccurred(env))
+ return;
- TARGET_NATIVE_NETWORK_SOCKET_SET_OPTION_SO_TIMEOUT (fd, optval, result);
+ TARGET_NATIVE_NETWORK_SOCKET_SET_OPTION_SO_TIMEOUT(fd,optval,result);
#endif
- result = TARGET_NATIVE_OK; // ignore errors and do not throw an exception
- break;
+ result = TARGET_NATIVE_OK; // ignore errors and do not throw an exception
+ break;
- case SOCKOPT_SO_SNDBUF:
- case SOCKOPT_SO_RCVBUF:
- mid = (*env)->GetMethodID (env, cls, "intValue", "()I");
- if (mid == NULL)
- {
- JCL_ThrowException (env, IO_EXCEPTION,
- "Internal error: _javanet_set_option()");
- return;
- }
+ case SOCKOPT_SO_SNDBUF:
+ case SOCKOPT_SO_RCVBUF:
+ mid = (*env)->GetMethodID(env, cls, "intValue", "()I");
+ if (mid == NULL)
+ { JCL_ThrowException(env, IO_EXCEPTION,
+ "Internal error: _javanet_set_option()"); return; }
- optval = (*env)->CallIntMethod (env, val, mid);
- if ((*env)->ExceptionOccurred (env))
- return;
-
- if (option_id == SOCKOPT_SO_SNDBUF)
- TARGET_NATIVE_NETWORK_SOCKET_SET_OPTION_SO_SNDBUF (fd, optval,
- result);
- else
- TARGET_NATIVE_NETWORK_SOCKET_SET_OPTION_SO_RCDBUF (fd, optval,
- result);
- break;
+ optval = (*env)->CallIntMethod(env, val, mid);
+ if ((*env)->ExceptionOccurred(env))
+ return;
+
+ if (option_id == SOCKOPT_SO_SNDBUF)
+ TARGET_NATIVE_NETWORK_SOCKET_SET_OPTION_SO_SNDBUF(fd,optval,result);
+ else
+ TARGET_NATIVE_NETWORK_SOCKET_SET_OPTION_SO_RCDBUF(fd,optval,result);
+ break;
/* TTL case. Val with be an Integer with the new time to live value */
- case SOCKOPT_IP_TTL:
- mid = (*env)->GetMethodID (env, cls, "intValue", "()I");
- if (!mid)
- {
- JCL_ThrowException (env, IO_EXCEPTION,
- "Internal error: _javanet_set_option()");
+ case SOCKOPT_IP_TTL:
+ mid = (*env)->GetMethodID(env, cls, "intValue", "()I");
+ if (!mid)
+ { JCL_ThrowException(env, IO_EXCEPTION,
+ "Internal error: _javanet_set_option()"); return; }
+
+ optval = (*env)->CallIntMethod(env, val, mid);
+ if ((*env)->ExceptionOccurred(env))
return;
- }
-
- optval = (*env)->CallIntMethod (env, val, mid);
- if ((*env)->ExceptionOccurred (env))
- return;
-
- TARGET_NATIVE_NETWORK_SOCKET_SET_OPTION_IP_TTL (fd, optval, result);
- break;
+
+ TARGET_NATIVE_NETWORK_SOCKET_SET_OPTION_IP_TTL(fd,optval,result);
+ break;
/* Multicast Interface case - val is InetAddress object */
- case SOCKOPT_IP_MULTICAST_IF:
- address = _javanet_get_netaddr (env, val);
+ case SOCKOPT_IP_MULTICAST_IF:
+ address = _javanet_get_netaddr(env, val);
- if ((*env)->ExceptionOccurred (env))
- return;
+ if ((*env)->ExceptionOccurred(env))
+ return;
- TARGET_NATIVE_NETWORK_SOCKET_SET_OPTION_IP_MULTICAST_IF (fd, address,
- result);
- break;
+ TARGET_NATIVE_NETWORK_SOCKET_SET_OPTION_IP_MULTICAST_IF(fd,address,result);
+ break;
- case SOCKOPT_SO_REUSEADDR:
- mid = (*env)->GetMethodID (env, cls, "booleanValue", "()Z");
- if (mid == NULL)
- {
- JCL_ThrowException (env, IO_EXCEPTION,
- "Internal error: _javanet_set_option()");
- return;
- }
+ case SOCKOPT_SO_REUSEADDR:
+ mid = (*env)->GetMethodID(env, cls, "booleanValue", "()Z");
+ if (mid == NULL)
+ { JCL_ThrowException(env, IO_EXCEPTION,
+ "Internal error: _javanet_set_option()"); return; }
- /* Should be a 0 or a 1 */
- optval = (*env)->CallBooleanMethod (env, val, mid);
- if ((*env)->ExceptionOccurred (env))
- return;
+ /* Should be a 0 or a 1 */
+ optval = (*env)->CallBooleanMethod(env, val, mid);
+ if ((*env)->ExceptionOccurred(env))
+ return;
- TARGET_NATIVE_NETWORK_SOCKET_SET_OPTION_REUSE_ADDRESS (fd, optval,
- result);
- break;
+ TARGET_NATIVE_NETWORK_SOCKET_SET_OPTION_REUSE_ADDRESS(fd,optval,result);
+ break;
case SOCKOPT_SO_KEEPALIVE:
- mid = (*env)->GetMethodID (env, cls, "booleanValue", "()Z");
- if (mid == NULL)
- {
- JCL_ThrowException (env, IO_EXCEPTION,
- "Internal error: _javanet_set_option()");
+ mid = (*env)->GetMethodID(env, cls, "booleanValue", "()Z");
+ if (mid == NULL)
+ { JCL_ThrowException(env, IO_EXCEPTION,
+ "Internal error: _javanet_set_option()"); return; }
+
+ /* Should be a 0 or a 1 */
+ optval = (*env)->CallBooleanMethod(env, val, mid);
+ if ((*env)->ExceptionOccurred(env))
return;
- }
-
- /* Should be a 0 or a 1 */
- optval = (*env)->CallBooleanMethod (env, val, mid);
- if ((*env)->ExceptionOccurred (env))
- return;
- TARGET_NATIVE_NETWORK_SOCKET_SET_OPTION_KEEP_ALIVE (fd, optval, result);
+ TARGET_NATIVE_NETWORK_SOCKET_SET_OPTION_KEEP_ALIVE(fd,optval,result);
break;
-
+
case SOCKOPT_SO_BINDADDR:
- JCL_ThrowException (env, SOCKET_EXCEPTION, "This option cannot be set");
+ JCL_ThrowException(env, SOCKET_EXCEPTION, "This option cannot be set");
break;
default:
- JCL_ThrowException (env, SOCKET_EXCEPTION, "Unrecognized option");
+ JCL_ThrowException(env, SOCKET_EXCEPTION, "Unrecognized option");
return;
}
/* Check to see if above operations succeeded */
if (result != TARGET_NATIVE_OK)
{
- JCL_ThrowException (env, SOCKET_EXCEPTION,
- TARGET_NATIVE_LAST_ERROR_STRING ());
+ JCL_ThrowException(env, SOCKET_EXCEPTION, TARGET_NATIVE_LAST_ERROR_STRING());
return;
}
#else /* not WITHOUT_NETWORK */
@@ -1248,183 +1196,167 @@ _javanet_set_option (JNIEnv *env, jobject this, jint option_id, jobject val)
/*
* Retrieves the specified option values for a socket
*/
-jobject
-_javanet_get_option (JNIEnv *env, jobject this, jint option_id)
+jobject
+_javanet_get_option(JNIEnv *env, jobject this, jint option_id)
{
#ifndef WITHOUT_NETWORK
int fd;
- int flag, optval;
+ int flag,optval;
int address;
int result;
- assert (env != NULL);
- assert ((*env) != NULL);
+ assert(env!=NULL);
+ assert((*env)!=NULL);
/* Get the real file descriptor */
- fd = _javanet_get_int_field (env, this, "native_fd");
+ fd = _javanet_get_int_field(env, this, "native_fd");
if (fd == -1)
- {
- JCL_ThrowException (env, SOCKET_EXCEPTION,
- "Internal error: _javanet_get_option(): no native file descriptor");
- return (0);
+ {
+ JCL_ThrowException(env, SOCKET_EXCEPTION,
+ "Internal error: _javanet_get_option(): no native file descriptor");
+ return(0);
}
/* Process the option requested */
switch (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)
- {
- JCL_ThrowException (env, SOCKET_EXCEPTION,
- TARGET_NATIVE_LAST_ERROR_STRING ());
- return (0);
- }
-
- if (optval)
- return (_javanet_create_boolean (env, JNI_TRUE));
- else
- return (_javanet_create_boolean (env, JNI_FALSE));
-
- break;
+ case SOCKOPT_TCP_NODELAY:
+ TARGET_NATIVE_NETWORK_SOCKET_GET_OPTION_TCP_NODELAY(fd,optval,result);
+ if (result != TARGET_NATIVE_OK)
+ {
+ JCL_ThrowException(env, SOCKET_EXCEPTION, TARGET_NATIVE_LAST_ERROR_STRING());
+ return(0);
+ }
+
+ if (optval)
+ return(_javanet_create_boolean(env, JNI_TRUE));
+ else
+ return(_javanet_create_boolean(env, JNI_FALSE));
+
+ break;
/* 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)
- {
- JCL_ThrowException (env, SOCKET_EXCEPTION,
- TARGET_NATIVE_LAST_ERROR_STRING ());
- return (0);
- }
+ case SOCKOPT_SO_LINGER:
+ TARGET_NATIVE_NETWORK_SOCKET_GET_OPTION_SO_LINGER(fd,flag,optval,result);
+ if (result != TARGET_NATIVE_OK)
+ {
+ JCL_ThrowException(env, SOCKET_EXCEPTION, TARGET_NATIVE_LAST_ERROR_STRING());
+ return(0);
+ }
- if (optval)
- return (_javanet_create_integer (env, JNI_TRUE));
- else
- return (_javanet_create_boolean (env, JNI_FALSE));
+ if (optval)
+ return(_javanet_create_integer(env, JNI_TRUE));
+ else
+ return(_javanet_create_boolean(env, JNI_FALSE));
- break;
+ break;
/* SO_TIMEOUT case. Return an Integer object with the timeout value */
- case SOCKOPT_SO_TIMEOUT:
+ case SOCKOPT_SO_TIMEOUT:
#ifdef SO_TIMEOUT
- TARGET_NATIVE_NETWORK_SOCKET_GET_OPTION_SO_TIMEOUT (fd, optval, result);
- if (result != TARGET_NATIVE_OK)
- {
- JCL_ThrowException (env, SOCKET_EXCEPTION,
- TARGET_NATIVE_LAST_ERROR_STRING ());
- return (0);
- }
-
- return (_javanet_create_integer (env, optval));
+ TARGET_NATIVE_NETWORK_SOCKET_GET_OPTION_SO_TIMEOUT(fd,optval,result);
+ if (result != TARGET_NATIVE_OK)
+ {
+ JCL_ThrowException(env, SOCKET_EXCEPTION, TARGET_NATIVE_LAST_ERROR_STRING());
+ return(0);
+ }
+
+ return(_javanet_create_integer(env, optval));
#else
- JCL_ThrowException (env, SOCKET_EXCEPTION,
- "SO_TIMEOUT not supported on this platform");
- return (0);
+ 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);
- else
- TARGET_NATIVE_NETWORK_SOCKET_GET_OPTION_SO_RCDBUF (fd, optval,
- result);
- if (result != TARGET_NATIVE_OK)
- {
- JCL_ThrowException (env, SOCKET_EXCEPTION,
- TARGET_NATIVE_LAST_ERROR_STRING ());
- return (0);
- }
-
- return (_javanet_create_integer (env, optval));
- break;
+ 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);
+ else
+ TARGET_NATIVE_NETWORK_SOCKET_GET_OPTION_SO_RCDBUF(fd,optval,result);
+ if (result != TARGET_NATIVE_OK)
+ {
+ JCL_ThrowException(env, SOCKET_EXCEPTION, TARGET_NATIVE_LAST_ERROR_STRING());
+ return(0);
+ }
+
+ return(_javanet_create_integer(env, optval));
+ break;
/* 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)
- {
- JCL_ThrowException (env, SOCKET_EXCEPTION,
- TARGET_NATIVE_LAST_ERROR_STRING ());
- return (0);
- }
+ case SOCKOPT_IP_TTL:
+ TARGET_NATIVE_NETWORK_SOCKET_GET_OPTION_IP_TTL(fd,optval,result);
+ if (result != TARGET_NATIVE_OK)
+ {
+ JCL_ThrowException(env, SOCKET_EXCEPTION, TARGET_NATIVE_LAST_ERROR_STRING());
+ return(0);
+ }
- return (_javanet_create_integer (env, optval));
- break;
+ return(_javanet_create_integer(env, optval));
+ break;
/* 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)
- {
- JCL_ThrowException (env, SOCKET_EXCEPTION,
- TARGET_NATIVE_LAST_ERROR_STRING ());
- return (0);
- }
-
- return (_javanet_create_inetaddress (env, address));
- break;
-
- case SOCKOPT_SO_BINDADDR:
- TARGET_NATIVE_NETWORK_SOCKET_GET_OPTION_BIND_ADDRESS (fd, address,
- result);
- if (result != TARGET_NATIVE_OK)
- {
- JCL_ThrowException (env, SOCKET_EXCEPTION,
- TARGET_NATIVE_LAST_ERROR_STRING ());
- return (0);
- }
-
- return (_javanet_create_inetaddress (env, address));
- break;
-
- case SOCKOPT_SO_REUSEADDR:
- TARGET_NATIVE_NETWORK_SOCKET_GET_OPTION_REUSE_ADDRESS (fd, optval,
- result);
- if (result != TARGET_NATIVE_OK)
- {
- JCL_ThrowException (env, SOCKET_EXCEPTION,
- TARGET_NATIVE_LAST_ERROR_STRING ());
- return (0);
- }
-
- if (optval)
- return (_javanet_create_boolean (env, JNI_TRUE));
- else
- 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)
- {
- JCL_ThrowException (env, SOCKET_EXCEPTION,
- TARGET_NATIVE_LAST_ERROR_STRING ());
- return (0);
- }
-
- if (optval)
- return (_javanet_create_boolean (env, JNI_TRUE));
- else
- return (_javanet_create_boolean (env, JNI_FALSE));
-
- break;
-
- default:
- JCL_ThrowException (env, SOCKET_EXCEPTION, "No such option");
- return (0);
+ case SOCKOPT_IP_MULTICAST_IF:
+ TARGET_NATIVE_NETWORK_SOCKET_GET_OPTION_IP_MULTICAST_IF(fd,address,result);
+ if (result != TARGET_NATIVE_OK)
+ {
+ JCL_ThrowException(env, SOCKET_EXCEPTION, TARGET_NATIVE_LAST_ERROR_STRING());
+ return(0);
+ }
+
+ return(_javanet_create_inetaddress(env, address));
+ break;
+
+ case SOCKOPT_SO_BINDADDR:
+ TARGET_NATIVE_NETWORK_SOCKET_GET_OPTION_BIND_ADDRESS(fd,address,result);
+ if (result != TARGET_NATIVE_OK)
+ {
+ JCL_ThrowException(env, SOCKET_EXCEPTION, TARGET_NATIVE_LAST_ERROR_STRING());
+ return(0);
+ }
+
+ return(_javanet_create_inetaddress(env, address));
+ break;
+
+ case SOCKOPT_SO_REUSEADDR:
+ TARGET_NATIVE_NETWORK_SOCKET_GET_OPTION_REUSE_ADDRESS(fd,optval,result);
+ if (result != TARGET_NATIVE_OK)
+ {
+ JCL_ThrowException(env, SOCKET_EXCEPTION, TARGET_NATIVE_LAST_ERROR_STRING());
+ return(0);
+ }
+
+ if (optval)
+ return(_javanet_create_boolean(env, JNI_TRUE));
+ else
+ 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)
+ {
+ JCL_ThrowException(env, SOCKET_EXCEPTION, TARGET_NATIVE_LAST_ERROR_STRING());
+ return(0);
+ }
+
+ if (optval)
+ return(_javanet_create_boolean(env, JNI_TRUE));
+ else
+ return(_javanet_create_boolean(env, JNI_FALSE));
+
+ break;
+
+ default:
+ JCL_ThrowException(env, SOCKET_EXCEPTION, "No such option" );
+ return(0);
}
- return (0);
+ return(0);
#else /* not WITHOUT_NETWORK */
#endif /* not WITHOUT_NETWORK */
}
diff --git a/native/jni/java-net/javanet.h b/native/jni/java-net/javanet.h
index 2c6cf5591..f27f811e2 100644
--- a/native/jni/java-net/javanet.h
+++ b/native/jni/java-net/javanet.h
@@ -37,7 +37,7 @@ exception statement from your version. */
#ifndef _JAVANET_LOADED
-#define _JAVANET_LOADED
+#define _JAVANET_LOADED
#include <jni.h>
@@ -87,20 +87,20 @@ exception statement from your version. */
* Function Prototypes
*/
-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_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 jobject _javanet_get_option (JNIEnv *, jobject, jint);
-extern void _javanet_set_option (JNIEnv *, jobject, jint, jobject);
+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_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 jobject _javanet_get_option(JNIEnv *, jobject, jint);
+extern void _javanet_set_option(JNIEnv *, jobject, jint, jobject);
/*************************************************************************/
#endif /* not _JAVANET_H_LOADED */
+