summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoman Kennke <roman@kennke.org>2006-01-17 19:55:08 +0000
committerRoman Kennke <roman@kennke.org>2006-01-17 19:55:08 +0000
commit45e2f7ee429bff73111173a0e2dd09e4b3ab56ed (patch)
tree1176fcfe9bc606f8658907d2f1ee30b54366884e
parenteb554ab3cd7009c2b885d199df3e82db6a9c8c5b (diff)
downloadclasspath-45e2f7ee429bff73111173a0e2dd09e4b3ab56ed.tar.gz
2006-01-17 Roman Kennke <kennke@aicas.com>
* native/jni/java-net/javanet.c: (_javanet_connect): Changed type of some local variables to jint. Fixed error handling to throw a SocketTimeoutException if the connection attempt times out. (_javanet_bind): Changed type of some local variables to jint. (_javanet_accept): Likewise. (_javanet_recvfrom): Likewise. (_javanet_sendto): Fixed error handling to throw a PortUnreachableException when connection is refused. (_javanet_get_option): Changed type of some local variables to jint. Implemented SOCKOPT_SO_BROADCAST. (_javanet_shutdownInput): Replaced shutdown call with corresponding target native macro. (_javanet_shutdownOutput): Replaced shutdown call with corresponding target native macro. * native/jni/java-net/javanet.h: Defined SOCKET_TIMEOUT_EXCEPTION, PORT_UNREACHABLE_EXCEPTION and SOCKOPT_SO_BROADCAST.
-rw-r--r--ChangeLog21
-rw-r--r--native/jni/java-net/javanet.c101
-rw-r--r--native/jni/java-net/javanet.h3
3 files changed, 90 insertions, 35 deletions
diff --git a/ChangeLog b/ChangeLog
index ca0006ec8..fb2f11629 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,24 @@
+2006-01-17 Roman Kennke <kennke@aicas.com>
+
+ * native/jni/java-net/javanet.c:
+ (_javanet_connect): Changed type of some local variables to jint.
+ Fixed error handling to throw a SocketTimeoutException if the
+ connection attempt times out.
+ (_javanet_bind): Changed type of some local variables to jint.
+ (_javanet_accept): Likewise.
+ (_javanet_recvfrom): Likewise.
+ (_javanet_sendto): Fixed error handling to throw a
+ PortUnreachableException when connection is refused.
+ (_javanet_get_option): Changed type of some local variables to jint.
+ Implemented SOCKOPT_SO_BROADCAST.
+ (_javanet_shutdownInput): Replaced shutdown call with corresponding
+ target native macro.
+ (_javanet_shutdownOutput): Replaced shutdown call with corresponding
+ target native macro.
+ * native/jni/java-net/javanet.h:
+ Defined SOCKET_TIMEOUT_EXCEPTION, PORT_UNREACHABLE_EXCEPTION and
+ SOCKOPT_SO_BROADCAST.
+
2006-01-17 Lillian Angel <langel@redhat.com>
* javax/swing/text/JTextComponent.java
diff --git a/native/jni/java-net/javanet.c b/native/jni/java-net/javanet.c
index c3ae43e2b..942ef575c 100644
--- a/native/jni/java-net/javanet.c
+++ b/native/jni/java-net/javanet.c
@@ -50,9 +50,6 @@ exception statement from your version. */
#include "target_native.h"
#ifndef WITHOUT_NETWORK
#include "target_native_network.h"
-#endif /* WITHOUT_NETWORK */
-
-#ifndef WITHOUT_NETWORK
/* Need to have some value for SO_TIMEOUT */
#ifndef SO_TIMEOUT
#ifndef SO_RCVTIMEO
@@ -340,10 +337,10 @@ _javanet_set_remhost (JNIEnv * env, jobject this, int netaddr)
/*
* Returns a 32 bit Internet address for the passed in InetAddress object
*/
+#ifndef WITHOUT_NETWORK
int
_javanet_get_netaddr (JNIEnv * env, jobject addr)
{
-#ifndef WITHOUT_NETWORK
jclass cls = 0;
jmethodID mid;
jarray arr = 0;
@@ -400,9 +397,8 @@ _javanet_get_netaddr (JNIEnv * env, jobject addr)
DBG ("_javanet_get_netaddr(): Done getting addr\n");
return netaddr;
-#else /* not WITHOUT_NETWORK */
-#endif /* not WITHOUT_NETWORK */
}
+#endif /* not WITHOUT_NETWORK */
/*************************************************************************/
@@ -527,8 +523,8 @@ _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;
+ jint local_address, local_port;
+ jint remote_address, remote_port;
DBG ("_javanet_connect(): Entered _javanet_connect\n");
@@ -552,17 +548,24 @@ _javanet_connect (JNIEnv * env, jobject this, jobject addr, jint port,
DBG ("_javanet_connect(): Got native fd\n");
/* Connect up */
- do
+ TARGET_NATIVE_NETWORK_SOCKET_CONNECT (fd, netaddr, port, result);
+ if (result != TARGET_NATIVE_OK)
{
- TARGET_NATIVE_NETWORK_SOCKET_CONNECT (fd, netaddr, port, result);
- if (result != TARGET_NATIVE_OK
- && (TARGET_NATIVE_LAST_ERROR ()
- != TARGET_NATIVE_ERROR_INTERRUPT_FUNCTION_CALL))
+ switch (TARGET_NATIVE_LAST_ERROR())
{
- JCL_ThrowException (env, IO_EXCEPTION,
- TARGET_NATIVE_LAST_ERROR_STRING ());
- return;
+ case TARGET_NATIVE_ERROR_TIMEDOUT:
+ JCL_ThrowException(env,
+ SOCKET_TIMEOUT_EXCEPTION,
+ "connect timed out");
+ break;
+ default:
+ JCL_ThrowException(env,
+ IO_EXCEPTION,
+ TARGET_NATIVE_LAST_ERROR_STRING()
+ );
+ break;
}
+ return;
}
while (result != TARGET_NATIVE_OK);
@@ -668,7 +671,7 @@ _javanet_bind (JNIEnv * env, jobject this, jobject addr, jint port,
jint fd;
int tmpaddr;
int result;
- int local_address, local_port;
+ jint local_address, local_port;
DBG ("_javanet_bind(): Entering native bind()\n");
@@ -804,8 +807,8 @@ _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;
+ jint local_address, local_port;
+ jint remote_address, remote_port;
/* Get the real file descriptor */
fd = _javanet_get_int_field (env, this, "native_fd");
@@ -936,7 +939,7 @@ _javanet_recvfrom (JNIEnv * env, jobject this, jarray buf, int offset,
#ifndef WITHOUT_NETWORK
int fd;
jbyte *p;
- int from_address, from_port;
+ jint from_address, from_port;
int received_bytes;
DBG ("_javanet_recvfrom(): Entered _javanet_recvfrom\n");
@@ -1068,12 +1071,16 @@ _javanet_sendto (JNIEnv * env, jobject this, jarray buf, int offset, int len,
if (bytes_sent < 0)
{
- if (TARGET_NATIVE_LAST_ERROR ()
- != TARGET_NATIVE_ERROR_INTERRUPT_FUNCTION_CALL)
+ if (TARGET_NATIVE_LAST_ERROR()
+ == TARGET_NATIVE_ERROR_CONNECTION_REFUSED)
{
- JCL_ThrowException (env, IO_EXCEPTION,
- TARGET_NATIVE_LAST_ERROR_STRING ());
- break;
+ JCL_ThrowException(env, PORT_UNREACHABLE_EXCEPTION,
+ TARGET_NATIVE_LAST_ERROR_STRING());
+ }
+ else
+ {
+ JCL_ThrowException(env, IO_EXCEPTION,
+ TARGET_NATIVE_LAST_ERROR_STRING());
}
}
else
@@ -1316,7 +1323,7 @@ _javanet_get_option (JNIEnv * env, jobject this, jint option_id)
#ifndef WITHOUT_NETWORK
int fd;
int flag, optval;
- int address;
+ jint address;
int result;
/* Get the real file descriptor */
@@ -1461,6 +1468,22 @@ _javanet_get_option (JNIEnv * env, jobject this, jint option_id)
break;
+ case SOCKOPT_SO_BROADCAST:
+ TARGET_NATIVE_NETWORK_SOCKET_GET_OPTION_BROADCAST(fd,optval,result);
+ if (result != TARGET_NATIVE_OK)
+ {
+ JCL_ThrowException(env, SOCKET_EXCEPTION,
+ TARGET_NATIVE_LAST_ERROR_STRING());
+ return NULL;
+ }
+
+ 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)
@@ -1482,15 +1505,18 @@ _javanet_get_option (JNIEnv * env, jobject this, jint option_id)
return (0);
}
- return (0);
+ return NULL;
#else /* not WITHOUT_NETWORK */
+ return NULL;
#endif /* not WITHOUT_NETWORK */
}
void
_javanet_shutdownInput (JNIEnv * env, jobject this)
{
+#ifndef WITHOUT_NETWORK
int fd;
+ int result;
/* Get the real file descriptor. */
fd = _javanet_get_int_field (env, this, "native_fd");
@@ -1502,18 +1528,22 @@ _javanet_shutdownInput (JNIEnv * env, jobject this)
}
/* Shutdown input stream of socket. */
- if (shutdown (fd, SHUT_RD) == -1)
+ TARGET_NATIVE_NETWORK_SOCKET_SHUTDOWN_INPUT(fd, result);
+ if (result != TARGET_NATIVE_OK)
{
JCL_ThrowException (env, SOCKET_EXCEPTION,
TARGET_NATIVE_LAST_ERROR_STRING());
return;
}
+#endif /* not WITHOUT_NETWORK */
}
void
_javanet_shutdownOutput (JNIEnv * env, jobject this)
{
+#ifndef WITHOUT_NETWORK
int fd;
+ int result;
/* Get the real file descriptor. */
fd = _javanet_get_int_field (env, this, "native_fd");
@@ -1525,12 +1555,13 @@ _javanet_shutdownOutput (JNIEnv * env, jobject this)
}
/* Shutdown output stream of socket. */
- if (shutdown (fd, SHUT_WR) == -1)
- {
- JCL_ThrowException (env, SOCKET_EXCEPTION,
- TARGET_NATIVE_LAST_ERROR_STRING());
- return;
- }
+ TARGET_NATIVE_NETWORK_SOCKET_SHUTDOWN_OUTPUT(fd, result);
+ if (result != TARGET_NATIVE_OK)
+ {
+ JCL_ThrowException (env, SOCKET_EXCEPTION,
+ TARGET_NATIVE_LAST_ERROR_STRING());
+ return;
+ }
+#endif /* not WITHOUT_NETWORK */
}
-
/* end of file */
diff --git a/native/jni/java-net/javanet.h b/native/jni/java-net/javanet.h
index c173b1059..4f557e3f7 100644
--- a/native/jni/java-net/javanet.h
+++ b/native/jni/java-net/javanet.h
@@ -51,7 +51,9 @@ exception statement from your version. */
#define BIND_EXCEPTION "java/net/BindException"
#define IO_EXCEPTION "java/io/IOException"
#define SOCKET_EXCEPTION "java/net/SocketException"
+#define SOCKET_TIMEOUT_EXCEPTION "java/net/SocketTimeoutException"
#define UNKNOWN_HOST_EXCEPTION "java/net/UnknownHostException"
+#define PORT_UNREACHABLE_EXCEPTION "java/net/PortUnreachableException"
/* Socket Option Identifiers - Don't change or binary compatibility with
the JDK will be broken! These also need to
@@ -63,6 +65,7 @@ exception statement from your version. */
#define SOCKOPT_SO_SNDBUF 4097
#define SOCKOPT_SO_RCVBUF 4098
#define SOCKOPT_SO_REUSEADDR 4
+#define SOCKOPT_SO_BROADCAST 32
#define SOCKOPT_IP_MULTICAST_IF 16
#define SOCKOPT_SO_KEEPALIVE 8