diff options
author | jfrijters <jfrijters> | 2010-09-09 10:55:31 +0400 |
---|---|---|
committer | jfrijters <jfrijters> | 2010-09-09 10:55:31 +0400 |
commit | e57a3213625777da5740614fc86afb6cb4e9e23e (patch) | |
tree | d117f574bdbb2afc471339612187b8bcc5dd57bc /openjdk/java/net/TwoStacksPlainSocketImpl_c.java | |
parent | 0720c24a212c240d952a1d20f5595ed15f7fabf3 (diff) |
Implemented IPv6 support for java.net package APIs.
Diffstat (limited to 'openjdk/java/net/TwoStacksPlainSocketImpl_c.java')
-rw-r--r-- | openjdk/java/net/TwoStacksPlainSocketImpl_c.java | 674 |
1 files changed, 289 insertions, 385 deletions
diff --git a/openjdk/java/net/TwoStacksPlainSocketImpl_c.java b/openjdk/java/net/TwoStacksPlainSocketImpl_c.java index cd694933..4764acfc 100644 --- a/openjdk/java/net/TwoStacksPlainSocketImpl_c.java +++ b/openjdk/java/net/TwoStacksPlainSocketImpl_c.java @@ -22,7 +22,32 @@ * CA 95054 USA or visit www.sun.com if you need additional information or * have any questions. */ +package java.net; +import java.io.FileDescriptor; +import static ikvm.internal.JNI.*; +import static ikvm.internal.Winsock.*; +import static java.net.net_util_md.*; +import static java.net.InetAddress.IPv4; +import static java.net.InetAddress.IPv6; + +final class TwoStacksPlainSocketImpl_c +{ +static final int JVM_IO_ERR = -1; +static final int JVM_IO_INTR = -2; + +static final int java_net_SocketOptions_SO_TIMEOUT = SocketOptions.SO_TIMEOUT; +static final int java_net_SocketOptions_SO_BINDADDR = SocketOptions.SO_BINDADDR; +static final int java_net_SocketOptions_SO_SNDBUF = SocketOptions.SO_SNDBUF; +static final int java_net_SocketOptions_SO_RCVBUF = SocketOptions.SO_RCVBUF; +static final int java_net_SocketOptions_IP_TOS = SocketOptions.IP_TOS; +static final int java_net_SocketOptions_SO_REUSEADDR = SocketOptions.SO_REUSEADDR; +static final int java_net_SocketOptions_TCP_NODELAY = SocketOptions.TCP_NODELAY; +static final int java_net_SocketOptions_SO_OOBINLINE = SocketOptions.SO_OOBINLINE; +static final int java_net_SocketOptions_SO_KEEPALIVE = SocketOptions.SO_KEEPALIVE; +static final int java_net_SocketOptions_SO_LINGER = SocketOptions.SO_LINGER; + +/* #include <windows.h> #include <winsock2.h> #include <ctype.h> @@ -41,11 +66,13 @@ #include "jvm.h" #include "net_util.h" #include "jni_util.h" +*/ /************************************************************************ * TwoStacksPlainSocketImpl */ +/* static jfieldID IO_fd_fdID; jfieldID psi_fdID; @@ -57,6 +84,7 @@ jfieldID psi_timeoutID; jfieldID psi_trafficClassID; jfieldID psi_serverSocketID; jfieldID psi_lastfdID; +*/ /* * the level of the TCP protocol for setsockopt and getsockopt @@ -65,22 +93,22 @@ jfieldID psi_lastfdID; */ static int tcp_level = -1; -static int getFD(JNIEnv *env, jobject this) { - jobject fdObj = (*env)->GetObjectField(env, this, psi_fdID); +static cli.System.Net.Sockets.Socket getFD(JNIEnv env, TwoStacksPlainSocketImpl _this) { + FileDescriptor fdObj = _this.fd; if (fdObj == NULL) { - return -1; + return null; } - return (*env)->GetIntField(env, fdObj, IO_fd_fdID); + return fdObj.getSocket(); } -static int getFD1(JNIEnv *env, jobject this) { - jobject fdObj = (*env)->GetObjectField(env, this, psi_fd1ID); +static cli.System.Net.Sockets.Socket getFD1(JNIEnv env, TwoStacksPlainSocketImpl _this) { + FileDescriptor fdObj = _this.fd1; if (fdObj == NULL) { - return -1; + return null; } - return (*env)->GetIntField(env, fdObj, IO_fd_fdID); + return fdObj.getSocket(); } @@ -94,6 +122,7 @@ static int getFD1(JNIEnv *env, jobject this) { * Signature: ()V */ +/* JNIEXPORT void JNICALL Java_java_net_TwoStacksPlainSocketImpl_initProto(JNIEnv *env, jclass cls) { @@ -123,55 +152,53 @@ Java_java_net_TwoStacksPlainSocketImpl_initProto(JNIEnv *env, jclass cls) { IO_fd_fdID = NET_GetFileDescriptorID(env); CHECK_NULL(IO_fd_fdID); } +*/ /* * Class: java_net_TwoStacksPlainSocketImpl * Method: socketCreate * Signature: (Z)V */ -JNIEXPORT void JNICALL -Java_java_net_TwoStacksPlainSocketImpl_socketCreate(JNIEnv *env, jobject this, - jboolean stream) { - jobject fdObj, fd1Obj; - int fd, fd1; - - fdObj = (*env)->GetObjectField(env, this, psi_fdID); +static void socketCreate(JNIEnv env, TwoStacksPlainSocketImpl _this, boolean stream) { + FileDescriptor fdObj = _this.fd; + FileDescriptor fd1Obj = _this.fd1; + cli.System.Net.Sockets.Socket fd = null; + cli.System.Net.Sockets.Socket fd1 = null; if (IS_NULL(fdObj)) { - JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", + JNU_ThrowByName(env, JNU_JAVANETPKG+"SocketException", "null fd object"); return; } fd = socket(AF_INET, (stream ? SOCK_STREAM: SOCK_DGRAM), 0); - if (fd == -1) { + if (fd == INVALID_SOCKET) { NET_ThrowCurrent(env, "create"); return; } else { /* Set socket attribute so it is not passed to any child process */ - SetHandleInformation((HANDLE)(UINT_PTR)fd, HANDLE_FLAG_INHERIT, FALSE); - (*env)->SetIntField(env, fdObj, IO_fd_fdID, (int)fd); + //SetHandleInformation((HANDLE)(UINT_PTR)fd, HANDLE_FLAG_INHERIT, FALSE); + fdObj.setSocket(fd); } if (ipv6_available()) { - fd1Obj = (*env)->GetObjectField(env, this, psi_fd1ID); if (IS_NULL(fd1Obj)) { - JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", + JNU_ThrowByName(env, JNU_JAVANETPKG+"SocketException", "null fd1 object"); - (*env)->SetIntField(env, fdObj, IO_fd_fdID, -1); + fdObj.setSocket(null); NET_SocketClose(fd); return; } fd1 = socket(AF_INET6, (stream ? SOCK_STREAM: SOCK_DGRAM), 0); - if (fd1 == -1) { + if (fd1 == INVALID_SOCKET) { NET_ThrowCurrent(env, "create"); - (*env)->SetIntField(env, fdObj, IO_fd_fdID, -1); + fdObj.setSocket(null); NET_SocketClose(fd); return; } else { - (*env)->SetIntField(env, fd1Obj, IO_fd_fdID, fd1); + fd1Obj.setSocket(fd1); } } else { - (*env)->SetObjectField(env, this, psi_fd1ID, NULL); + _this.fd1 = null; } } @@ -183,37 +210,35 @@ Java_java_net_TwoStacksPlainSocketImpl_socketCreate(JNIEnv *env, jobject this, * Method: socketConnect * Signature: (Ljava/net/InetAddress;I)V */ -JNIEXPORT void JNICALL -Java_java_net_TwoStacksPlainSocketImpl_socketConnect(JNIEnv *env, jobject this, - jobject iaObj, jint port, - jint timeout) +static void socketConnect(JNIEnv env, TwoStacksPlainSocketImpl _this, InetAddress iaObj, int port, int timeout) { - jint localport = (*env)->GetIntField(env, this, psi_localportID); + int localport = _this.localport; /* family and localport are int fields of iaObj */ int family; - jint fd, fd1=-1; - jint len; - int ipv6_supported = ipv6_available(); + cli.System.Net.Sockets.Socket fd = null; + cli.System.Net.Sockets.Socket fd1 = null; + boolean ipv6_supported = ipv6_available(); /* fd initially points to the IPv4 socket and fd1 to the IPv6 socket * If we want to connect to IPv6 then we swap the two sockets/objects * This way, fd is always the connected socket, and fd1 always gets closed. */ - jobject fdObj = (*env)->GetObjectField(env, this, psi_fdID); - jobject fd1Obj = (*env)->GetObjectField(env, this, psi_fd1ID); + FileDescriptor fdObj = _this.fd; + FileDescriptor fd1Obj = _this.fd1; SOCKETADDRESS him; + him = new SOCKETADDRESS(); /* The result of the connection */ int connect_res; if (!IS_NULL(fdObj)) { - fd = (*env)->GetIntField(env, fdObj, IO_fd_fdID); + fd = fdObj.getSocket(); } if (ipv6_supported && !IS_NULL(fd1Obj)) { - fd1 = (*env)->GetIntField(env, fd1Obj, IO_fd_fdID); + fd1 = fd1Obj.getSocket(); } if (IS_NULL(iaObj)) { @@ -221,67 +246,67 @@ Java_java_net_TwoStacksPlainSocketImpl_socketConnect(JNIEnv *env, jobject this, return; } - if (NET_InetAddressToSockaddr(env, iaObj, port, (struct sockaddr *)&him, &len, JNI_FALSE) != 0) { + if (NET_InetAddressToSockaddr(env, iaObj, port, him, JNI_FALSE) != 0) { return; } family = him.him.sa_family; if (family == AF_INET6) { if (!ipv6_supported) { - JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", + JNU_ThrowByName(env, JNU_JAVANETPKG+"SocketException", "Protocol family not supported"); return; } else { - if (fd1 == -1) { - JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", + if (fd1 == null) { + JNU_ThrowByName(env, JNU_JAVANETPKG+"SocketException", "Destination unreachable"); return; } /* close the v4 socket, and set fd to be the v6 socket */ - (*env)->SetObjectField(env, this, psi_fdID, fd1Obj); - (*env)->SetObjectField(env, this, psi_fd1ID, NULL); + _this.fd = fd1Obj; + _this.fd1 = null; NET_SocketClose(fd); fd = fd1; fdObj = fd1Obj; } } else { - if (fd1 != -1) { - (*env)->SetIntField(env, fd1Obj, IO_fd_fdID, -1); + if (fd1 != null) { + fd1Obj.setSocket(null); NET_SocketClose(fd1); } - if (fd == -1) { - JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", + if (fd == null) { + JNU_ThrowByName(env, JNU_JAVANETPKG+"SocketException", "Destination unreachable"); return; } } - (*env)->SetObjectField(env, this, psi_fd1ID, NULL); + _this.fd1 = null; if (timeout <= 0) { - connect_res = connect(fd, (struct sockaddr *) &him, SOCKETADDRESS_LEN(&him)); + connect_res = connect(fd, him); if (connect_res == SOCKET_ERROR) { connect_res = WSAGetLastError(); } } else { int optval; - int optlen = sizeof(optval); /* make socket non-blocking */ optval = 1; - ioctlsocket( fd, FIONBIO, &optval ); + ioctlsocket( fd, FIONBIO, optval ); /* initiate the connect */ - connect_res = connect(fd, (struct sockaddr *) &him, SOCKETADDRESS_LEN(&him)); + connect_res = connect(fd, him); if (connect_res == SOCKET_ERROR) { if (WSAGetLastError() != WSAEWOULDBLOCK) { connect_res = WSAGetLastError(); } else { fd_set wr, ex; - struct timeval t; + wr = new fd_set(); ex = new fd_set(); + timeval t = new timeval(); - FD_ZERO(&wr); - FD_ZERO(&ex); - FD_SET(fd, &wr); - FD_SET(fd, &ex); + FD_ZERO(wr); + FD_ZERO(ex); + FD_SET(fd, wr); + FD_SET(fd, ex); t.tv_sec = timeout / 1000; t.tv_usec = (timeout % 1000) * 1000; @@ -289,7 +314,7 @@ Java_java_net_TwoStacksPlainSocketImpl_socketConnect(JNIEnv *env, jobject this, * Wait for timout, connection established or * connection failed. */ - connect_res = select(fd+1, 0, &wr, &ex, &t); + connect_res = select(null, wr, ex, t); /* * Timeout before connection is established/failed so @@ -298,13 +323,13 @@ Java_java_net_TwoStacksPlainSocketImpl_socketConnect(JNIEnv *env, jobject this, * The socket should be closed immediately by the caller. */ if (connect_res == 0) { - JNU_ThrowByName(env, JNU_JAVANETPKG "SocketTimeoutException", + JNU_ThrowByName(env, JNU_JAVANETPKG+"SocketTimeoutException", "connect timed out"); shutdown( fd, SD_BOTH ); /* make socket blocking again - just in case */ optval = 0; - ioctlsocket( fd, FIONBIO, &optval ); + ioctlsocket( fd, FIONBIO, optval ); return; } @@ -317,21 +342,23 @@ Java_java_net_TwoStacksPlainSocketImpl_socketConnect(JNIEnv *env, jobject this, * yielding and retrying. As yielding is problematic in heavy * load conditions we attempt up to 3 times to get the error reason. */ - if (!FD_ISSET(fd, &ex)) { + if (!FD_ISSET(fd, ex)) { connect_res = 0; } else { int retry; for (retry=0; retry<3; retry++) { + int[] tmp = { 0 }; NET_GetSockOpt(fd, SOL_SOCKET, SO_ERROR, - (char*)&connect_res, &optlen); - if (connect_res) { + tmp); + connect_res = tmp[0]; + if (connect_res != 0) { break; } Sleep(0); } if (connect_res == 0) { - JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", + JNU_ThrowByName(env, JNU_JAVANETPKG+"SocketException", "Unable to establish connection"); return; } @@ -341,12 +368,12 @@ Java_java_net_TwoStacksPlainSocketImpl_socketConnect(JNIEnv *env, jobject this, /* make socket blocking again */ optval = 0; - ioctlsocket(fd, FIONBIO, &optval); + ioctlsocket(fd, FIONBIO, optval); } - if (connect_res) { + if (connect_res != 0) { if (connect_res == WSAEADDRNOTAVAIL) { - JNU_ThrowByName(env, JNU_JAVANETPKG "ConnectException", + JNU_ThrowByName(env, JNU_JAVANETPKG+"ConnectException", "connect: Address is invalid on local machine, or port is not valid on remote machine"); } else { NET_ThrowNew(env, connect_res, "connect"); @@ -354,11 +381,11 @@ Java_java_net_TwoStacksPlainSocketImpl_socketConnect(JNIEnv *env, jobject this, return; } - (*env)->SetIntField(env, fdObj, IO_fd_fdID, (int)fd); + fdObj.setSocket(fd); /* set the remote peer address and port */ - (*env)->SetObjectField(env, this, psi_addressID, iaObj); - (*env)->SetIntField(env, this, psi_portID, port); + _this.address = iaObj; + _this.port = port; /* * we need to initialize the local port field if bind was called @@ -369,20 +396,18 @@ Java_java_net_TwoStacksPlainSocketImpl_socketConnect(JNIEnv *env, jobject this, /* Now that we're a connected socket, let's extract the port number * that the system chose for us and store it in the Socket object. */ - u_short port; - int len = SOCKETADDRESS_LEN(&him); - if (getsockname(fd, (struct sockaddr *)&him, &len) == -1) { + if (getsockname(fd, him) == -1) { if (WSAGetLastError() == WSAENOTSOCK) { - JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", + JNU_ThrowByName(env, JNU_JAVANETPKG+"SocketException", "Socket closed"); } else { NET_ThrowCurrent(env, "getsockname failed"); } return; } - port = ntohs ((u_short)GET_PORT(&him)); - (*env)->SetIntField(env, this, psi_localportID, (int) port); + port = ntohs (GET_PORT(him)); + _this.localport = port; } } @@ -391,41 +416,36 @@ Java_java_net_TwoStacksPlainSocketImpl_socketConnect(JNIEnv *env, jobject this, * Method: socketBind * Signature: (Ljava/net/InetAddress;I)V */ -JNIEXPORT void JNICALL -Java_java_net_TwoStacksPlainSocketImpl_socketBind(JNIEnv *env, jobject this, - jobject iaObj, jint localport) { - - /* fdObj is the FileDescriptor field on this */ - jobject fdObj, fd1Obj; - /* fd is an int field on fdObj */ - int fd, fd1, len; - int ipv6_supported = ipv6_available(); +static void socketBind(JNIEnv env, TwoStacksPlainSocketImpl _this, InetAddress iaObj, int localport) { + FileDescriptor fdObj = _this.fd; + FileDescriptor fd1Obj = _this.fd1; + cli.System.Net.Sockets.Socket fd = null; + cli.System.Net.Sockets.Socket fd1 = null; + boolean ipv6_supported = ipv6_available(); /* family is an int field of iaObj */ int family; int rv; SOCKETADDRESS him; + him = new SOCKETADDRESS(); - fdObj = (*env)->GetObjectField(env, this, psi_fdID); - fd1Obj = (*env)->GetObjectField(env, this, psi_fd1ID); - - family = (*env)->GetIntField(env, iaObj, ia_familyID); + family = iaObj.family; if (family == IPv6 && !ipv6_supported) { - JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", + JNU_ThrowByName(env, JNU_JAVANETPKG+"SocketException", "Protocol family not supported"); return; } if (IS_NULL(fdObj) || (ipv6_supported && IS_NULL(fd1Obj))) { - JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", + JNU_ThrowByName(env, JNU_JAVANETPKG+"SocketException", "Socket closed"); return; } else { - fd = (*env)->GetIntField(env, fdObj, IO_fd_fdID); + fd = fdObj.getSocket(); if (ipv6_supported) { - fd1 = (*env)->GetIntField(env, fd1Obj, IO_fd_fdID); + fd1 = fd1Obj.getSocket(); } } if (IS_NULL(iaObj)) { @@ -434,41 +454,41 @@ Java_java_net_TwoStacksPlainSocketImpl_socketBind(JNIEnv *env, jobject this, } if (NET_InetAddressToSockaddr(env, iaObj, localport, - (struct sockaddr *)&him, &len, JNI_FALSE) != 0) { + him, JNI_FALSE) != 0) { return; } if (ipv6_supported) { - struct ipv6bind v6bind; - v6bind.addr = &him; + ipv6bind v6bind = new ipv6bind(); + v6bind.addr = him; v6bind.ipv4_fd = fd; v6bind.ipv6_fd = fd1; - rv = NET_BindV6(&v6bind); + rv = NET_BindV6(v6bind); if (rv != -1) { /* check if the fds have changed */ if (v6bind.ipv4_fd != fd) { fd = v6bind.ipv4_fd; - if (fd == -1) { + if (fd == null) { /* socket is closed. */ - (*env)->SetObjectField(env, this, psi_fdID, NULL); + _this.fd = null; } else { /* socket was re-created */ - (*env)->SetIntField(env, fdObj, IO_fd_fdID, fd); + fdObj.setSocket(fd); } } if (v6bind.ipv6_fd != fd1) { fd1 = v6bind.ipv6_fd; - if (fd1 == -1) { + if (fd1 == null) { /* socket is closed. */ - (*env)->SetObjectField(env, this, psi_fd1ID, NULL); + _this.fd1 = null; } else { /* socket was re-created */ - (*env)->SetIntField(env, fd1Obj, IO_fd_fdID, fd1); + fd1Obj.setSocket(fd1); } } } } else { - rv = NET_Bind(fd, (struct sockaddr *)&him, len); + rv = NET_Bind(fd, him); } if (rv == -1) { @@ -477,26 +497,25 @@ Java_java_net_TwoStacksPlainSocketImpl_socketBind(JNIEnv *env, jobject this, } /* set the address */ - (*env)->SetObjectField(env, this, psi_addressID, iaObj); + _this.address = iaObj; /* intialize the local port */ if (localport == 0) { /* Now that we're a bound socket, let's extract the port number * that the system chose for us and store it in the Socket object. */ - int len = SOCKETADDRESS_LEN(&him); - u_short port; + int port; fd = him.him.sa_family == AF_INET? fd: fd1; - if (getsockname(fd, (struct sockaddr *)&him, &len) == -1) { + if (getsockname(fd, him) == -1) { NET_ThrowCurrent(env, "getsockname in plain socketBind"); return; } - port = ntohs ((u_short) GET_PORT (&him)); + port = ntohs (GET_PORT (him)); - (*env)->SetIntField(env, this, psi_localportID, (int) port); + _this.localport = port; } else { - (*env)->SetIntField(env, this, psi_localportID, localport); + _this.localport = localport; } } @@ -505,52 +524,51 @@ Java_java_net_TwoStacksPlainSocketImpl_socketBind(JNIEnv *env, jobject this, * Method: socketListen * Signature: (I)V */ -JNIEXPORT void JNICALL -Java_java_net_TwoStacksPlainSocketImpl_socketListen (JNIEnv *env, jobject this, - jint count) +static void socketListen (JNIEnv env, TwoStacksPlainSocketImpl _this, int count) { /* this FileDescriptor fd field */ - jobject fdObj = (*env)->GetObjectField(env, this, psi_fdID); - jobject fd1Obj = (*env)->GetObjectField(env, this, psi_fd1ID); - jobject address; + FileDescriptor fdObj = _this.fd; + FileDescriptor fd1Obj = _this.fd1; + InetAddress address; /* fdObj's int fd field */ - int fd, fd1; - SOCKETADDRESS addr; int addrlen; + cli.System.Net.Sockets.Socket fd = null; + cli.System.Net.Sockets.Socket fd1 = null; + SOCKETADDRESS addr = new SOCKETADDRESS(); if (IS_NULL(fdObj) && IS_NULL(fd1Obj)) { - JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", + JNU_ThrowByName(env, JNU_JAVANETPKG+"SocketException", "socket closed"); return; } if (!IS_NULL(fdObj)) { - fd = (*env)->GetIntField(env, fdObj, IO_fd_fdID); + fd = fdObj.getSocket(); } /* Listen on V4 if address type is v4 or if v6 and address is ::0. * Listen on V6 if address type is v6 or if v4 and address is 0.0.0.0. * In cases, where we listen on one space only, we close the other socket. */ - address = (*env)->GetObjectField(env, this, psi_addressID); + address = _this.address; if (IS_NULL(address)) { JNU_ThrowNullPointerException(env, "socket address"); return; } - if (NET_InetAddressToSockaddr(env, address, 0, (struct sockaddr *)&addr, - &addrlen, JNI_FALSE) != 0) { + if (NET_InetAddressToSockaddr(env, address, 0, addr, + JNI_FALSE) != 0) { return; } - if (addr.him.sa_family == AF_INET || IN6ADDR_ISANY(&addr.him6)) { + if (addr.him.sa_family == AF_INET || IN6ADDR_ISANY(addr.him6)) { /* listen on v4 */ if (listen(fd, count) == -1) { NET_ThrowCurrent(env, "listen failed"); } } else { NET_SocketClose (fd); - (*env)->SetObjectField(env, this, psi_fdID, NULL); + _this.fd = null; } if (ipv6_available() && !IS_NULL(fd1Obj)) { - fd1 = (*env)->GetIntField(env, fd1Obj, IO_fd_fdID); + fd1 = fd1Obj.getSocket(); if (addr.him.sa_family == AF_INET6 || addr.him4.sin_addr.s_addr == INADDR_ANY) { /* listen on v6 */ if (listen(fd1, count) == -1) { @@ -558,7 +576,7 @@ Java_java_net_TwoStacksPlainSocketImpl_socketListen (JNIEnv *env, jobject this, } } else { NET_SocketClose (fd1); - (*env)->SetObjectField(env, this, psi_fd1ID, NULL); + _this.fd1 = null; } } } @@ -568,200 +586,139 @@ Java_java_net_TwoStacksPlainSocketImpl_socketListen (JNIEnv *env, jobject this, * Method: socketAccept * Signature: (Ljava/net/SocketImpl;)V */ -JNIEXPORT void JNICALL -Java_java_net_TwoStacksPlainSocketImpl_socketAccept(JNIEnv *env, jobject this, - jobject socket) +static void socketAccept(JNIEnv env, TwoStacksPlainSocketImpl _this, SocketImpl socket) { /* fields on this */ - jint port; - jint timeout = (*env)->GetIntField(env, this, psi_timeoutID); - jobject fdObj = (*env)->GetObjectField(env, this, psi_fdID); - jobject fd1Obj = (*env)->GetObjectField(env, this, psi_fd1ID); + int port; + int timeout = _this.timeout; + FileDescriptor fdObj = _this.fd; + FileDescriptor fd1Obj = _this.fd1; /* the FileDescriptor field on socket */ - jobject socketFdObj; - - /* cache the Inet4/6Address classes */ - static jclass inet4Cls; - static jclass inet6Cls; + FileDescriptor socketFdObj; /* the InetAddress field on socket */ - jobject socketAddressObj; + InetAddress socketAddressObj; /* the fd int field on fdObj */ - jint fd=-1, fd1=-1; + cli.System.Net.Sockets.Socket fd=null, fd1=null; SOCKETADDRESS him; - jint len; + him = new SOCKETADDRESS(); if (IS_NULL(fdObj) && IS_NULL(fd1Obj)) { - JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", + JNU_ThrowByName(env, JNU_JAVANETPKG+"SocketException", "Socket closed"); return; } if (!IS_NULL(fdObj)) { - fd = (*env)->GetIntField(env, fdObj, IO_fd_fdID); + fd = fdObj.getSocket(); } if (!IS_NULL(fd1Obj)) { - fd1 = (*env)->GetIntField(env, fd1Obj, IO_fd_fdID); + fd1 = fd1Obj.getSocket(); } if (IS_NULL(socket)) { JNU_ThrowNullPointerException(env, "socket is null"); return; } else { - socketFdObj = (*env)->GetObjectField(env, socket, psi_fdID); - socketAddressObj = (*env)->GetObjectField(env, socket, psi_addressID); + socketFdObj = socket.fd; + socketAddressObj = socket.address; } if ((IS_NULL(socketAddressObj)) || (IS_NULL(socketFdObj))) { JNU_ThrowNullPointerException(env, "socket address or fd obj"); return; } - if (fd != -1 && fd1 != -1) { - fd_set rfds; - struct timeval t, *tP=&t; - int lastfd, res, fd2; - FD_ZERO(&rfds); - FD_SET(fd,&rfds); - FD_SET(fd1,&rfds); - if (timeout) { + if (fd != null && fd1 != null) { + fd_set rfds = new fd_set(); + timeval t = new timeval(); + cli.System.Net.Sockets.Socket lastfd, fd2; + FD_ZERO(rfds); + FD_SET(fd,rfds); + FD_SET(fd1,rfds); + if (timeout != 0) { t.tv_sec = timeout/1000; t.tv_usec = (timeout%1000)*1000; } else { - tP = NULL; + t = null; } - res = select (fd, &rfds, NULL, NULL, tP); + int res = select (rfds, null, null, t); if (res == 0) { - JNU_ThrowByName(env, JNU_JAVANETPKG "SocketTimeoutException", + JNU_ThrowByName(env, JNU_JAVANETPKG+"SocketTimeoutException", "Accept timed out"); return; } else if (res == 1) { - fd2 = FD_ISSET(fd, &rfds)? fd: fd1; + fd2 = FD_ISSET(fd, rfds)? fd: fd1; } else if (res == 2) { /* avoid starvation */ - lastfd = (*env)->GetIntField(env, this, psi_lastfdID); - if (lastfd != -1) { + lastfd = _this.lastfd; + if (lastfd != null) { fd2 = lastfd==fd? fd1: fd; } else { fd2 = fd; } - (*env)->SetIntField(env, this, psi_lastfdID, fd2); + _this.lastfd = fd2; } else { - JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", + JNU_ThrowByName(env, JNU_JAVANETPKG+"SocketException", "select failed"); return; } - if (fd2 == fd) { /* v4 */ - len = sizeof (struct sockaddr_in); - } else { - len = sizeof (struct SOCKADDR_IN6); - } fd = fd2; } else { int ret; - if (fd1 != -1) { + if (fd1 != null) { fd = fd1; - len = sizeof (struct SOCKADDR_IN6); - } else { - len = sizeof (struct sockaddr_in); } - if (timeout) { + if (timeout != 0) { ret = NET_Timeout(fd, timeout); if (ret == 0) { - JNU_ThrowByName(env, JNU_JAVANETPKG "SocketTimeoutException", + JNU_ThrowByName(env, JNU_JAVANETPKG+"SocketTimeoutException", "Accept timed out"); return; } else if (ret == -1) { - JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", "socket closed"); + JNU_ThrowByName(env, JNU_JAVANETPKG+"SocketException", "socket closed"); /* REMIND: SOCKET CLOSED PROBLEM */ /* NET_ThrowCurrent(env, "Accept failed"); */ return; } else if (ret == -2) { - JNU_ThrowByName(env, JNU_JAVAIOPKG "InterruptedIOException", + JNU_ThrowByName(env, JNU_JAVAIOPKG+"InterruptedIOException", "operation interrupted"); return; } } } - fd = accept(fd, (struct sockaddr *)&him, &len); - if (fd < 0) { + fd = accept(fd, him); + if (fd == null) { /* REMIND: SOCKET CLOSED PROBLEM */ - if (fd == -2) { - JNU_ThrowByName(env, JNU_JAVAIOPKG "InterruptedIOException", + if (false) { + JNU_ThrowByName(env, JNU_JAVAIOPKG+"InterruptedIOException", "operation interrupted"); } else { - JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", + JNU_ThrowByName(env, JNU_JAVANETPKG+"SocketException", "socket closed"); } return; } - (*env)->SetIntField(env, socketFdObj, IO_fd_fdID, fd); + socketFdObj.setSocket(fd); if (him.him.sa_family == AF_INET) { - if (inet4Cls == NULL) { - jclass c = (*env)->FindClass(env, "java/net/Inet4Address"); - if (c != NULL) { - inet4Cls = (*env)->NewGlobalRef(env, c); - (*env)->DeleteLocalRef(env, c); - } - } /* * fill up the remote peer port and address in the new socket structure */ - if (inet4Cls != NULL) { - socketAddressObj = (*env)->NewObject(env, inet4Cls, ia4_ctrID); - } else { - socketAddressObj = NULL; - } - if (socketAddressObj == NULL) { - /* - * FindClass or NewObject failed so close connection and - * exist (there will be a pending exception). - */ - NET_SocketClose(fd); - return; - } - - (*env)->SetIntField(env, socketAddressObj, ia_addressID, - ntohl(him.him4.sin_addr.s_addr)); - (*env)->SetIntField(env, socketAddressObj, ia_familyID, IPv4); - (*env)->SetObjectField(env, socket, psi_addressID, socketAddressObj); + socketAddressObj = new Inet4Address(null, ntohl(him.him4.sin_addr.s_addr)); + socket.address = socketAddressObj; } else { - jbyteArray addr; /* AF_INET6 -> Inet6Address */ - if (inet6Cls == 0) { - jclass c = (*env)->FindClass(env, "java/net/Inet6Address"); - if (c != NULL) { - inet6Cls = (*env)->NewGlobalRef(env, c); - (*env)->DeleteLocalRef(env, c); - } - } - if (inet6Cls != NULL) { - socketAddressObj = (*env)->NewObject(env, inet6Cls, ia6_ctrID); - } else { - socketAddressObj = NULL; - } - if (socketAddressObj == NULL) { - /* - * FindClass or NewObject failed so close connection and - * exist (there will be a pending exception). - */ - NET_SocketClose(fd); - return; - } - addr = (*env)->GetObjectField (env, socketAddressObj, ia6_ipaddressID); - (*env)->SetByteArrayRegion (env, addr, 0, 16, (const char *)&him.him6.sin6_addr); - (*env)->SetIntField(env, socketAddressObj, ia_familyID, IPv6); - (*env)->SetIntField(env, socketAddressObj, ia6_scopeidID, him.him6.sin6_scope_id); + socketAddressObj = new Inet6Address(null, him.him6.sin6_addr, him.him6.sin6_scope_id); } /* fields common to AF_INET and AF_INET6 */ - port = ntohs ((u_short) GET_PORT (&him)); - (*env)->SetIntField(env, socket, psi_portID, (int)port); - port = (*env)->GetIntField(env, this, psi_localportID); - (*env)->SetIntField(env, socket, psi_localportID, port); - (*env)->SetObjectField(env, socket, psi_addressID, socketAddressObj); + port = ntohs (GET_PORT (him)); + socket.port = port; + port = _this.localport; + socket.localport = port; + socket.address = socketAddressObj; } /* @@ -769,26 +726,25 @@ Java_java_net_TwoStacksPlainSocketImpl_socketAccept(JNIEnv *env, jobject this, * Method: socketAvailable * Signature: ()I */ -JNIEXPORT jint JNICALL -Java_java_net_TwoStacksPlainSocketImpl_socketAvailable(JNIEnv *env, jobject this) { +static int socketAvailable(JNIEnv env, TwoStacksPlainSocketImpl _this) { - jint available = -1; - jint res; - jobject fdObj = (*env)->GetObjectField(env, this, psi_fdID); - jint fd; + int[] available = { -1 }; + int res; + FileDescriptor fdObj = _this.fd; + cli.System.Net.Sockets.Socket fd; if (IS_NULL(fdObj)) { - JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", "Socket closed"); + JNU_ThrowByName(env, JNU_JAVANETPKG+"SocketException", "Socket closed"); return -1; } else { - fd = (*env)->GetIntField(env, fdObj, IO_fd_fdID); + fd = fdObj.getSocket(); } - res = ioctlsocket(fd, FIONREAD, &available); + res = ioctlsocket(fd, FIONREAD, available); /* if result isn't 0, it means an error */ if (res != 0) { NET_ThrowNew(env, res, "socket available"); } - return available; + return available[0]; } /* @@ -796,31 +752,30 @@ Java_java_net_TwoStacksPlainSocketImpl_socketAvailable(JNIEnv *env, jobject this * Method: socketClose * Signature: ()V */ -JNIEXPORT void JNICALL -Java_java_net_TwoStacksPlainSocketImpl_socketClose0(JNIEnv *env, jobject this, - jboolean useDeferredClose) { +static void socketClose0(JNIEnv env, TwoStacksPlainSocketImpl _this, boolean useDeferredClose) { - jobject fdObj = (*env)->GetObjectField(env, this, psi_fdID); - jobject fd1Obj = (*env)->GetObjectField(env, this, psi_fd1ID); - jint fd=-1, fd1=-1; + FileDescriptor fdObj = _this.fd; + FileDescriptor fd1Obj = _this.fd1; + cli.System.Net.Sockets.Socket fd = null; + cli.System.Net.Sockets.Socket fd1 = null; if (IS_NULL(fdObj) && IS_NULL(fd1Obj)) { - JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", + JNU_ThrowByName(env, JNU_JAVANETPKG+"SocketException", "socket already closed"); return; } if (!IS_NULL(fdObj)) { - fd = (*env)->GetIntField(env, fdObj, IO_fd_fdID); + fd = fdObj.getSocket(); } if (!IS_NULL(fd1Obj)) { - fd1 = (*env)->GetIntField(env, fd1Obj, IO_fd_fdID); + fd1 = fd1Obj.getSocket(); } - if (fd != -1) { - (*env)->SetIntField(env, fdObj, IO_fd_fdID, -1); + if (fd != null) { + fdObj.setSocket(null); NET_SocketClose(fd); } - if (fd1 != -1) { - (*env)->SetIntField(env, fd1Obj, IO_fd_fdID, -1); + if (fd1 != null) { + fd1Obj.setSocket(null); NET_SocketClose(fd1); } } @@ -833,24 +788,19 @@ Java_java_net_TwoStacksPlainSocketImpl_socketClose0(JNIEnv *env, jobject this, * Method: socketSetOption * Signature: (IZLjava/lang/Object;)V */ -JNIEXPORT void JNICALL -Java_java_net_TwoStacksPlainSocketImpl_socketSetOption(JNIEnv *env, jobject this, - jint cmd, jboolean on, - jobject value) { - int fd, fd1; - int level, optname, optlen; - union { - int i; - struct linger ling; - } optval; +static void socketSetOption(JNIEnv env, TwoStacksPlainSocketImpl _this, int cmd, boolean on, Object value) { + cli.System.Net.Sockets.Socket fd, fd1; + int[] level = new int[1]; + int[] optname = new int[1]; + Object optval; /* * Get SOCKET and check that it hasn't been closed */ - fd = getFD(env, this); - fd1 = getFD1(env, this); - if (fd < 0 && fd1 < 0) { - JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", "Socket closed"); + fd = getFD(env, _this); + fd1 = getFD1(env, _this); + if (fd == null && fd1 == null) { + JNU_ThrowByName(env, JNU_JAVANETPKG+"SocketException", "Socket closed"); return; } @@ -869,7 +819,7 @@ Java_java_net_TwoStacksPlainSocketImpl_socketSetOption(JNIEnv *env, jobject this * Don't enable the socket option on ServerSocket as it's * meaningless (we don't receive on a ServerSocket). */ - jobject ssObj = (*env)->GetObjectField(env, this, psi_serverSocketID); + Object ssObj = _this.serverSocket; if (ssObj != NULL) { return; } @@ -881,14 +831,7 @@ Java_java_net_TwoStacksPlainSocketImpl_socketSetOption(JNIEnv *env, jobject this * select() -- see SocketInputStream.socketRead. */ if (isRcvTimeoutSupported) { - jclass iCls = (*env)->FindClass(env, "java/lang/Integer"); - jfieldID i_valueID; - jint timeout; - - CHECK_NULL(iCls); - i_valueID = (*env)->GetFieldID(env, iCls, "value", "I"); - CHECK_NULL(i_valueID); - timeout = (*env)->GetIntField(env, value, i_valueID); + int timeout = ((Integer)value).intValue(); /* * Disable SO_RCVTIMEO if timeout is <= 5 second. @@ -897,17 +840,15 @@ Java_java_net_TwoStacksPlainSocketImpl_socketSetOption(JNIEnv *env, jobject this timeout = 0; } - if (setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, (char *)&timeout, - sizeof(timeout)) < 0) { + if (setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, timeout) < 0) { if (WSAGetLastError() == WSAENOPROTOOPT) { isRcvTimeoutSupported = JNI_FALSE; } else { NET_ThrowCurrent(env, "setsockopt SO_RCVTIMEO"); } } - if (fd1 != -1) { - if (setsockopt(fd1, SOL_SOCKET, SO_RCVTIMEO, (char *)&timeout, - sizeof(timeout)) < 0) { + if (fd1 != null) { + if (setsockopt(fd1, SOL_SOCKET, SO_RCVTIMEO, timeout) < 0) { NET_ThrowCurrent(env, "setsockopt SO_RCVTIMEO"); } } @@ -919,8 +860,8 @@ Java_java_net_TwoStacksPlainSocketImpl_socketSetOption(JNIEnv *env, jobject this * Map the Java level socket option to the platform specific * level */ - if (NET_MapSocketOption(cmd, &level, &optname)) { - JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", + if (NET_MapSocketOption(cmd, level, optname) != 0) { + JNU_ThrowByName(env, JNU_JAVANETPKG+"SocketException", "Invalid option"); return; } @@ -931,62 +872,43 @@ Java_java_net_TwoStacksPlainSocketImpl_socketSetOption(JNIEnv *env, jobject this case java_net_SocketOptions_SO_OOBINLINE : case java_net_SocketOptions_SO_KEEPALIVE : case java_net_SocketOptions_SO_REUSEADDR : - optval.i = (on ? 1 : 0); - optlen = sizeof(optval.i); + optval = on; break; case java_net_SocketOptions_SO_SNDBUF : case java_net_SocketOptions_SO_RCVBUF : case java_net_SocketOptions_IP_TOS : - { - jclass cls; - jfieldID fid; - - cls = (*env)->FindClass(env, "java/lang/Integer"); - CHECK_NULL(cls); - fid = (*env)->GetFieldID(env, cls, "value", "I"); - CHECK_NULL(fid); - - optval.i = (*env)->GetIntField(env, value, fid); - optlen = sizeof(optval.i); - } + optval = ((Integer)value).intValue(); break; case java_net_SocketOptions_SO_LINGER : { - jclass cls; - jfieldID fid; - - cls = (*env)->FindClass(env, "java/lang/Integer"); - CHECK_NULL(cls); - fid = (*env)->GetFieldID(env, cls, "value", "I"); - CHECK_NULL(fid); - + linger ling = new linger(); if (on) { - optval.ling.l_onoff = 1; - optval.ling.l_linger = (*env)->GetIntField(env, value, fid); + ling.l_onoff = 1; + ling.l_linger = ((Integer)value).intValue(); } else { - optval.ling.l_onoff = 0; - optval.ling.l_linger = 0; + ling.l_onoff = 0; + ling.l_linger = 0; } - optlen = sizeof(optval.ling); + optval = ling; } break; default: /* shouldn't get here */ - JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", + JNU_ThrowByName(env, JNU_JAVANETPKG+"SocketException", "Option not supported by TwoStacksPlainSocketImpl"); return; } - if (fd != -1) { - if (NET_SetSockOpt(fd, level, optname, (void *)&optval, optlen) < 0) { + if (fd != null) { + if (NET_SetSockOpt(fd, level[0], optname[0], optval) < 0) { NET_ThrowCurrent(env, "setsockopt"); } } - if (fd1 != -1) { - if (NET_SetSockOpt(fd1, level, optname, (void *)&optval, optlen) < 0) { + if (fd1 != null) { + if (NET_SetSockOpt(fd1, level[0], optname[0], optval) < 0) { NET_ThrowCurrent(env, "setsockopt"); } } @@ -998,28 +920,24 @@ Java_java_net_TwoStacksPlainSocketImpl_socketSetOption(JNIEnv *env, jobject this * Method: socketGetOption * Signature: (I)I */ -JNIEXPORT jint JNICALL -Java_java_net_TwoStacksPlainSocketImpl_socketGetOption(JNIEnv *env, jobject this, - jint opt, jobject iaContainerObj) { +static int socketGetOption(JNIEnv env, TwoStacksPlainSocketImpl _this, int opt, Object iaContainerObj) { - int fd, fd1; - int level, optname, optlen; - union { - int i; - struct linger ling; - } optval; + cli.System.Net.Sockets.Socket fd, fd1; + int[] level = new int[1]; + int[] optname = new int[1]; + Object optval; /* * Get SOCKET and check it hasn't been closed */ - fd = getFD(env, this); - fd1 = getFD1(env, this); + fd = getFD(env, _this); + fd1 = getFD1(env, _this); - if (fd < 0 && fd1 < 0) { - JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", "Socket closed"); + if (fd == null && fd1 == null) { + JNU_ThrowByName(env, JNU_JAVANETPKG+"SocketException", "Socket closed"); return -1; } - if (fd < 0) { + if (fd == null) { fd = fd1; } @@ -1029,35 +947,25 @@ Java_java_net_TwoStacksPlainSocketImpl_socketGetOption(JNIEnv *env, jobject this * SO_BINDADDR isn't a socket option */ if (opt == java_net_SocketOptions_SO_BINDADDR) { - SOCKET_ADDRESS him; - int len; - int port; - jobject iaObj; - jclass iaCntrClass; - jfieldID iaFieldID; - - len = sizeof(struct sockaddr_in); + SOCKETADDRESS him; + him = new SOCKETADDRESS(); + int[] port = { 0 }; + InetAddress iaObj; - if (fd == -1) { + if (fd == null) { /* must be an IPV6 only socket. Case where both sockets are != -1 * is handled in java */ - fd = getFD1 (env, this); - len = sizeof(struct SOCKADDR_IN6); + fd = getFD1 (env, _this); } - if (getsockname(fd, (struct sockaddr *)&him, &len) < 0) { - NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException", + if (getsockname(fd, him) < 0) { + NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG+"SocketException", "Error getting socket name"); return -1; } - iaObj = NET_SockaddrToInetAddress(env, (struct sockaddr *)&him, &port); - CHECK_NULL_RETURN(iaObj, -1); - - iaCntrClass = (*env)->GetObjectClass(env, iaContainerObj); - iaFieldID = (*env)->GetFieldID(env, iaCntrClass, "addr", "Ljava/net/InetAddress;"); - CHECK_NULL_RETURN(iaFieldID, -1); - (*env)->SetObjectField(env, iaContainerObj, iaFieldID, iaObj); + iaObj = NET_SockaddrToInetAddress(him, port); + ((InetAddressContainer)iaContainerObj).addr = iaObj; return 0; /* notice change from before */ } @@ -1065,8 +973,8 @@ Java_java_net_TwoStacksPlainSocketImpl_socketGetOption(JNIEnv *env, jobject this * Map the Java level socket option to the platform specific * level and option name. */ - if (NET_MapSocketOption(opt, &level, &optname)) { - JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", "Invalid option"); + if (NET_MapSocketOption(opt, level, optname) != 0) { + JNU_ThrowByName(env, JNU_JAVANETPKG+"SocketException", "Invalid option"); return -1; } @@ -1074,34 +982,33 @@ Java_java_net_TwoStacksPlainSocketImpl_socketGetOption(JNIEnv *env, jobject this * Args are int except for SO_LINGER */ if (opt == java_net_SocketOptions_SO_LINGER) { - optlen = sizeof(optval.ling); + optval = new linger(); } else { - optlen = sizeof(optval.i); - optval.i = 0; + optval = new int[1]; } - if (NET_GetSockOpt(fd, level, optname, (void *)&optval, &optlen) < 0) { + if (NET_GetSockOpt(fd, level[0], optname[0], optval) < 0) { NET_ThrowCurrent(env, "getsockopt"); return -1; } switch (opt) { case java_net_SocketOptions_SO_LINGER: - return (optval.ling.l_onoff ? optval.ling.l_linger: -1); + return (((linger)optval).l_onoff != 0 ? ((linger)optval).l_linger: -1); case java_net_SocketOptions_SO_SNDBUF: case java_net_SocketOptions_SO_RCVBUF: case java_net_SocketOptions_IP_TOS: - return optval.i; + return ((int[])optval)[0]; case java_net_SocketOptions_TCP_NODELAY : case java_net_SocketOptions_SO_OOBINLINE : case java_net_SocketOptions_SO_KEEPALIVE : case java_net_SocketOptions_SO_REUSEADDR : - return (optval.i == 0) ? -1 : 1; + return (((int[])optval)[0] == 0) ? -1 : 1; default: /* shouldn't get here */ - JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", + JNU_ThrowByName(env, JNU_JAVANETPKG+"SocketException", "Option not supported by TwoStacksPlainSocketImpl"); return -1; } @@ -1112,24 +1019,22 @@ Java_java_net_TwoStacksPlainSocketImpl_socketGetOption(JNIEnv *env, jobject this * Method: socketShutdown * Signature: (I)V */ -JNIEXPORT void JNICALL -Java_java_net_TwoStacksPlainSocketImpl_socketShutdown(JNIEnv *env, jobject this, - jint howto) +static void socketShutdown(JNIEnv env, TwoStacksPlainSocketImpl _this, int howto) { - jobject fdObj = (*env)->GetObjectField(env, this, psi_fdID); - jint fd; + FileDescriptor fdObj = _this.fd; + cli.System.Net.Sockets.Socket fd; /* * WARNING: THIS NEEDS LOCKING. ALSO: SHOULD WE CHECK for fd being * -1 already? */ if (IS_NULL(fdObj)) { - JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", + JNU_ThrowByName(env, JNU_JAVANETPKG+"SocketException", "socket already closed"); return; } else { - fd = (*env)->GetIntField(env, fdObj, IO_fd_fdID); + fd = fdObj.getSocket(); } shutdown(fd, howto); } @@ -1139,35 +1044,34 @@ Java_java_net_TwoStacksPlainSocketImpl_socketShutdown(JNIEnv *env, jobject this, * Method: socketSendUrgentData * Signature: (B)V */ -JNIEXPORT void JNICALL -Java_java_net_TwoStacksPlainSocketImpl_socketSendUrgentData(JNIEnv *env, jobject this, - jint data) { +static void socketSendUrgentData(JNIEnv env, TwoStacksPlainSocketImpl _this, int data) { /* The fd field */ - jobject fdObj = (*env)->GetObjectField(env, this, psi_fdID); - int n, fd; - unsigned char d = data & 0xff; + FileDescriptor fdObj = _this.fd; + int n; + cli.System.Net.Sockets.Socket fd; if (IS_NULL(fdObj)) { JNU_ThrowByName(env, "java/net/SocketException", "Socket closed"); return; } else { - fd = (*env)->GetIntField(env, fdObj, IO_fd_fdID); + fd = fdObj.getSocket(); /* Bug 4086704 - If the Socket associated with this file descriptor * was closed (sysCloseFD), the the file descriptor is set to -1. */ - if (fd == -1) { + if (fd == null) { JNU_ThrowByName(env, "java/net/SocketException", "Socket closed"); return; } } - n = send(fd, (char *)&data, 1, MSG_OOB); + n = send(fd, new byte[] { (byte)data }, 1, MSG_OOB); if (n == JVM_IO_ERR) { NET_ThrowCurrent(env, "send"); return; } if (n == JVM_IO_INTR) { - JNU_ThrowByName(env, "java/io/InterruptedIOException", 0); + JNU_ThrowByName(env, "java/io/InterruptedIOException", null); return; } } +} |