20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 #include <windows.h>
27 #include <winsock2.h>
28 #include <ctype.h>
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <malloc.h>
32 #include <sys/types.h>
33
34 #include "java_net_SocketOptions.h"
35 #include "java_net_TwoStacksPlainSocketImpl.h"
36 #include "java_net_InetAddress.h"
37 #include "java_io_FileDescriptor.h"
38 #include "java_lang_Integer.h"
39
40 #include "jvm.h"
41 #include "net_util.h"
42 #include "jni_util.h"
43
44 /************************************************************************
45 * TwoStacksPlainSocketImpl
46 */
47
48 static jfieldID IO_fd_fdID;
49
50 jfieldID psi_fdID;
51 jfieldID psi_fd1ID;
52 jfieldID psi_addressID;
53 jfieldID psi_portID;
54 jfieldID psi_localportID;
55 jfieldID psi_timeoutID;
56 jfieldID psi_trafficClassID;
57 jfieldID psi_serverSocketID;
58 jfieldID psi_lastfdID;
59
60 /*
456 /* socket was re-created */
457 (*env)->SetIntField(env, fdObj, IO_fd_fdID, fd);
458 }
459 }
460 if (v6bind.ipv6_fd != fd1) {
461 fd1 = v6bind.ipv6_fd;
462 if (fd1 == -1) {
463 /* socket is closed. */
464 (*env)->SetObjectField(env, this, psi_fd1ID, NULL);
465 } else {
466 /* socket was re-created */
467 (*env)->SetIntField(env, fd1Obj, IO_fd_fdID, fd1);
468 }
469 }
470 }
471 } else {
472 rv = NET_WinBind(fd, (struct sockaddr *)&him, len, exclBind);
473 }
474
475 if (rv == -1) {
476 NET_ThrowCurrent(env, "JVM_Bind");
477 return;
478 }
479
480 /* set the address */
481 (*env)->SetObjectField(env, this, psi_addressID, iaObj);
482
483 /* intialize the local port */
484 if (localport == 0) {
485 /* Now that we're a bound socket, let's extract the port number
486 * that the system chose for us and store it in the Socket object.
487 */
488 int len = SOCKETADDRESS_LEN(&him);
489 u_short port;
490 fd = him.him.sa_family == AF_INET? fd: fd1;
491
492 if (getsockname(fd, (struct sockaddr *)&him, &len) == -1) {
493 NET_ThrowCurrent(env, "getsockname in plain socketBind");
494 return;
495 }
496 port = ntohs ((u_short) GET_PORT (&him));
1145 /* The fd field */
1146 jobject fdObj = (*env)->GetObjectField(env, this, psi_fdID);
1147 int n, fd;
1148 unsigned char d = data & 0xff;
1149
1150 if (IS_NULL(fdObj)) {
1151 JNU_ThrowByName(env, "java/net/SocketException", "Socket closed");
1152 return;
1153 } else {
1154 fd = (*env)->GetIntField(env, fdObj, IO_fd_fdID);
1155 /* Bug 4086704 - If the Socket associated with this file descriptor
1156 * was closed (sysCloseFD), the the file descriptor is set to -1.
1157 */
1158 if (fd == -1) {
1159 JNU_ThrowByName(env, "java/net/SocketException", "Socket closed");
1160 return;
1161 }
1162
1163 }
1164 n = send(fd, (char *)&data, 1, MSG_OOB);
1165 if (n == JVM_IO_ERR) {
1166 NET_ThrowCurrent(env, "send");
1167 return;
1168 }
1169 if (n == JVM_IO_INTR) {
1170 JNU_ThrowByName(env, "java/io/InterruptedIOException", 0);
1171 return;
1172 }
1173 }
|
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 #include <windows.h>
27 #include <winsock2.h>
28 #include <ctype.h>
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <malloc.h>
32 #include <sys/types.h>
33
34 #include "java_net_SocketOptions.h"
35 #include "java_net_TwoStacksPlainSocketImpl.h"
36 #include "java_net_InetAddress.h"
37 #include "java_io_FileDescriptor.h"
38 #include "java_lang_Integer.h"
39
40 #include "net_util.h"
41 #include "jni_util.h"
42
43 /************************************************************************
44 * TwoStacksPlainSocketImpl
45 */
46
47 static jfieldID IO_fd_fdID;
48
49 jfieldID psi_fdID;
50 jfieldID psi_fd1ID;
51 jfieldID psi_addressID;
52 jfieldID psi_portID;
53 jfieldID psi_localportID;
54 jfieldID psi_timeoutID;
55 jfieldID psi_trafficClassID;
56 jfieldID psi_serverSocketID;
57 jfieldID psi_lastfdID;
58
59 /*
455 /* socket was re-created */
456 (*env)->SetIntField(env, fdObj, IO_fd_fdID, fd);
457 }
458 }
459 if (v6bind.ipv6_fd != fd1) {
460 fd1 = v6bind.ipv6_fd;
461 if (fd1 == -1) {
462 /* socket is closed. */
463 (*env)->SetObjectField(env, this, psi_fd1ID, NULL);
464 } else {
465 /* socket was re-created */
466 (*env)->SetIntField(env, fd1Obj, IO_fd_fdID, fd1);
467 }
468 }
469 }
470 } else {
471 rv = NET_WinBind(fd, (struct sockaddr *)&him, len, exclBind);
472 }
473
474 if (rv == -1) {
475 NET_ThrowCurrent(env, "NET_Bind");
476 return;
477 }
478
479 /* set the address */
480 (*env)->SetObjectField(env, this, psi_addressID, iaObj);
481
482 /* intialize the local port */
483 if (localport == 0) {
484 /* Now that we're a bound socket, let's extract the port number
485 * that the system chose for us and store it in the Socket object.
486 */
487 int len = SOCKETADDRESS_LEN(&him);
488 u_short port;
489 fd = him.him.sa_family == AF_INET? fd: fd1;
490
491 if (getsockname(fd, (struct sockaddr *)&him, &len) == -1) {
492 NET_ThrowCurrent(env, "getsockname in plain socketBind");
493 return;
494 }
495 port = ntohs ((u_short) GET_PORT (&him));
1144 /* The fd field */
1145 jobject fdObj = (*env)->GetObjectField(env, this, psi_fdID);
1146 int n, fd;
1147 unsigned char d = data & 0xff;
1148
1149 if (IS_NULL(fdObj)) {
1150 JNU_ThrowByName(env, "java/net/SocketException", "Socket closed");
1151 return;
1152 } else {
1153 fd = (*env)->GetIntField(env, fdObj, IO_fd_fdID);
1154 /* Bug 4086704 - If the Socket associated with this file descriptor
1155 * was closed (sysCloseFD), the the file descriptor is set to -1.
1156 */
1157 if (fd == -1) {
1158 JNU_ThrowByName(env, "java/net/SocketException", "Socket closed");
1159 return;
1160 }
1161
1162 }
1163 n = send(fd, (char *)&data, 1, MSG_OOB);
1164 if (n == -1) {
1165 NET_ThrowCurrent(env, "send");
1166 return;
1167 }
1168 }
|