author | michaelm |
Mon, 11 Nov 2019 21:17:51 +0000 | |
branch | unixdomainchannels |
changeset 59019 | dafa6389ed47 |
parent 59018 | 6d621f34e24a |
child 59082 | 5e250ee9259e |
permissions | -rw-r--r-- |
2 | 1 |
/* |
53422
6f02e036630e
8217461: (ch) Add Net.available to return the number of bytes in the socket input buffer
alanb
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 2001, 2019, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 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. |
|
2 | 24 |
*/ |
25 |
||
26 |
#include <windows.h> |
|
27 |
#include <winsock2.h> |
|
28 |
#include "jni.h" |
|
29 |
#include "jni_util.h" |
|
30 |
#include "jvm.h" |
|
31 |
#include "jlong.h" |
|
32 |
||
33 |
#include "nio.h" |
|
34 |
#include "nio_util.h" |
|
35 |
#include "net_util.h" |
|
36 |
||
37 |
#include "sun_nio_ch_Net.h" |
|
14025
fbebe005a3ee
7184932: Remove the temporary Selector usage in the NIO socket adapters
robm
parents:
9035
diff
changeset
|
38 |
#include "sun_nio_ch_PollArrayWrapper.h" |
2 | 39 |
|
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
40 |
/** |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
41 |
* Definitions to allow for building with older SDK include files. |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
42 |
*/ |
2 | 43 |
|
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
44 |
#ifndef MCAST_BLOCK_SOURCE |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
45 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
46 |
#define MCAST_BLOCK_SOURCE 43 |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
47 |
#define MCAST_UNBLOCK_SOURCE 44 |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
48 |
#define MCAST_JOIN_SOURCE_GROUP 45 |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
49 |
#define MCAST_LEAVE_SOURCE_GROUP 46 |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
50 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
51 |
#endif /* MCAST_BLOCK_SOURCE */ |
2 | 52 |
|
44208 | 53 |
struct my_ip_mreq_source { |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
54 |
IN_ADDR imr_multiaddr; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
55 |
IN_ADDR imr_sourceaddr; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
56 |
IN_ADDR imr_interface; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
57 |
}; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
58 |
|
44208 | 59 |
struct my_group_source_req { |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
60 |
ULONG gsr_interface; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
61 |
SOCKADDR_STORAGE gsr_group; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
62 |
SOCKADDR_STORAGE gsr_source; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
63 |
}; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
64 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
65 |
/** |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
66 |
* Copy IPv6 address as jbytearray to target |
2 | 67 |
*/ |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
68 |
#define COPY_INET6_ADDRESS(env, source, target) \ |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
69 |
(*env)->GetByteArrayRegion(env, source, 0, 16, target) |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
70 |
|
5777
1c86018749bd
6935563: (dc) Improve connection reset/port unreachable handling [win]
alanb
parents:
5506
diff
changeset
|
71 |
/** |
1c86018749bd
6935563: (dc) Improve connection reset/port unreachable handling [win]
alanb
parents:
5506
diff
changeset
|
72 |
* Enable or disable receipt of WSAECONNRESET errors. |
1c86018749bd
6935563: (dc) Improve connection reset/port unreachable handling [win]
alanb
parents:
5506
diff
changeset
|
73 |
*/ |
1c86018749bd
6935563: (dc) Improve connection reset/port unreachable handling [win]
alanb
parents:
5506
diff
changeset
|
74 |
static void setConnectionReset(SOCKET s, BOOL enable) { |
1c86018749bd
6935563: (dc) Improve connection reset/port unreachable handling [win]
alanb
parents:
5506
diff
changeset
|
75 |
DWORD bytesReturned = 0; |
1c86018749bd
6935563: (dc) Improve connection reset/port unreachable handling [win]
alanb
parents:
5506
diff
changeset
|
76 |
WSAIoctl(s, SIO_UDP_CONNRESET, &enable, sizeof(enable), |
1c86018749bd
6935563: (dc) Improve connection reset/port unreachable handling [win]
alanb
parents:
5506
diff
changeset
|
77 |
NULL, 0, &bytesReturned, NULL, NULL); |
1c86018749bd
6935563: (dc) Improve connection reset/port unreachable handling [win]
alanb
parents:
5506
diff
changeset
|
78 |
} |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
79 |
|
53445
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
80 |
jint handleSocketError(JNIEnv *env, int errorValue) |
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
81 |
{ |
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
82 |
NET_ThrowNew(env, errorValue, NULL); |
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
83 |
return IOS_THROWN; |
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
84 |
} |
2 | 85 |
|
54154
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
86 |
static jclass isa_class; /* java.net.InetSocketAddress */ |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
87 |
static jmethodID isa_ctorID; /* InetSocketAddress(InetAddress, int) */ |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
88 |
|
58801
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
89 |
extern jclass udsa_class; |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
90 |
extern jmethodID udsa_ctorID; |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
91 |
extern jfieldID udsa_pathID; |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
92 |
|
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
93 |
JNIEXPORT jobject JNICALL |
59018
6d621f34e24a
moved unix socket address out of SOCKETADDRESS structure
michaelm
parents:
59004
diff
changeset
|
94 |
NET_SockaddrToUnixAddress(JNIEnv *env, struct sockaddr_un *sa) { |
58801
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
95 |
|
59018
6d621f34e24a
moved unix socket address out of SOCKETADDRESS structure
michaelm
parents:
59004
diff
changeset
|
96 |
if (sa->sun_family == AF_UNIX) { |
6d621f34e24a
moved unix socket address out of SOCKETADDRESS structure
michaelm
parents:
59004
diff
changeset
|
97 |
char *name = sa->sun_path; |
58801
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
98 |
|
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
99 |
jstring nstr = JNU_NewStringPlatform(env, name); |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
100 |
return (*env)->NewObject(env, udsa_class, udsa_ctorID, nstr); |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
101 |
} |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
102 |
return NULL; |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
103 |
} |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
104 |
|
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
105 |
JNIEXPORT jint JNICALL |
59018
6d621f34e24a
moved unix socket address out of SOCKETADDRESS structure
michaelm
parents:
59004
diff
changeset
|
106 |
NET_UnixSocketAddressToSockaddr(JNIEnv *env, jobject uaddr, struct sockaddr_un *sa, int *len) |
58801
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
107 |
{ |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
108 |
jstring path = (*env)->GetObjectField(env, uaddr, udsa_pathID); |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
109 |
jboolean isCopy; |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
110 |
int ret; |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
111 |
const char* pname = JNU_GetStringPlatformChars(env, path, &isCopy); |
59018
6d621f34e24a
moved unix socket address out of SOCKETADDRESS structure
michaelm
parents:
59004
diff
changeset
|
112 |
memset(sa, 0, sizeof(struct sockaddr_un)); |
6d621f34e24a
moved unix socket address out of SOCKETADDRESS structure
michaelm
parents:
59004
diff
changeset
|
113 |
sa->sun_family = AF_UNIX; |
58801
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
114 |
size_t name_len = strlen(pname)+1; |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
115 |
if (name_len > MAX_UNIX_DOMAIN_PATH_LEN) { |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
116 |
JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", "unix domain path too long"); |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
117 |
ret = 1; |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
118 |
goto finish; |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
119 |
} |
59018
6d621f34e24a
moved unix socket address out of SOCKETADDRESS structure
michaelm
parents:
59004
diff
changeset
|
120 |
strncpy(sa->sun_path, pname, name_len); |
58801
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
121 |
*len = (int)(offsetof(struct sockaddr_un, sun_path) + name_len); |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
122 |
ret = 0; |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
123 |
finish: |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
124 |
if (isCopy) |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
125 |
JNU_ReleaseStringPlatformChars(env, path, pname); |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
126 |
return ret; |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
127 |
} |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
128 |
|
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
129 |
JNIEXPORT jboolean JNICALL |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
130 |
Java_sun_nio_ch_Net_unixDomainSocketSupported(JNIEnv *env, jclass cl) |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
131 |
{ |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
132 |
SOCKET fd = socket(PF_UNIX, SOCK_STREAM, 0); |
58939
aca099f4b3ec
Check for AF_UNIX support on Windows was not correct
michaelm
parents:
58847
diff
changeset
|
133 |
if (fd == INVALID_SOCKET) { |
58801
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
134 |
return JNI_FALSE; |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
135 |
} |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
136 |
closesocket(fd); |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
137 |
return JNI_TRUE; |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
138 |
} |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
139 |
|
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
140 |
JNIEXPORT jint JNICALL |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
141 |
Java_sun_nio_ch_Net_unixDomainSocket0(JNIEnv *env, jclass cl) |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
142 |
{ |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
143 |
SOCKET fd = socket(PF_UNIX, SOCK_STREAM, 0); |
58981 | 144 |
if (fd == INVALID_SOCKET) { |
58801
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
145 |
return handleSocketError(env, errno); |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
146 |
} |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
147 |
return (int)fd; |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
148 |
} |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
149 |
|
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
150 |
JNIEXPORT void JNICALL |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
151 |
Java_sun_nio_ch_Net_unixDomainBind(JNIEnv *env, jclass clazz, jobject fdo, jobject uaddr) |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
152 |
{ |
59018
6d621f34e24a
moved unix socket address out of SOCKETADDRESS structure
michaelm
parents:
59004
diff
changeset
|
153 |
struct sockaddr_un sa; |
58801
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
154 |
int sa_len = 0; |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
155 |
int rv = 0; |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
156 |
|
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
157 |
if (NET_UnixSocketAddressToSockaddr(env, uaddr, &sa, &sa_len) != 0) |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
158 |
return; |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
159 |
|
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
160 |
int fd = fdval(env, fdo); |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
161 |
|
59018
6d621f34e24a
moved unix socket address out of SOCKETADDRESS structure
michaelm
parents:
59004
diff
changeset
|
162 |
rv = bind(fdval(env, fdo), (struct sockaddr *)&sa, sa_len); |
58801
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
163 |
if (rv != 0) { |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
164 |
int err = WSAGetLastError(); |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
165 |
NET_ThrowNew(env, err, "bind"); |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
166 |
} |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
167 |
} |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
168 |
|
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
169 |
JNIEXPORT jint JNICALL |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
170 |
Java_sun_nio_ch_Net_unixDomainConnect(JNIEnv *env, jclass clazz, jobject fdo, jobject usa) |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
171 |
{ |
59018
6d621f34e24a
moved unix socket address out of SOCKETADDRESS structure
michaelm
parents:
59004
diff
changeset
|
172 |
struct sockaddr_un sa; |
58801
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
173 |
int sa_len = 0; |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
174 |
int rv; |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
175 |
|
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
176 |
if (NET_UnixSocketAddressToSockaddr(env, usa, &sa, &sa_len) != 0) { |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
177 |
return IOS_THROWN; |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
178 |
} |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
179 |
|
59018
6d621f34e24a
moved unix socket address out of SOCKETADDRESS structure
michaelm
parents:
59004
diff
changeset
|
180 |
rv = connect(fdval(env, fdo), (const struct sockaddr *)&sa, sa_len); |
58801
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
181 |
if (rv != 0) { |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
182 |
int err = WSAGetLastError(); |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
183 |
if (err == WSAEINPROGRESS || err == WSAEWOULDBLOCK) { |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
184 |
return IOS_UNAVAILABLE; |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
185 |
} |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
186 |
NET_ThrowNew(env, err, "connect"); |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
187 |
return IOS_THROWN; |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
188 |
} |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
189 |
return 1; |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
190 |
} |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
191 |
|
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
192 |
JNIEXPORT jint JNICALL |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
193 |
Java_sun_nio_ch_Net_unixDomainAccept(JNIEnv *env, jclass clazz, jobject fdo, jobject newfdo, |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
194 |
jobjectArray usaa) |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
195 |
{ |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
196 |
jint fd = fdval(env, fdo); |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
197 |
jint newfd; |
59018
6d621f34e24a
moved unix socket address out of SOCKETADDRESS structure
michaelm
parents:
59004
diff
changeset
|
198 |
struct sockaddr_un sa; |
6d621f34e24a
moved unix socket address out of SOCKETADDRESS structure
michaelm
parents:
59004
diff
changeset
|
199 |
socklen_t sa_len = sizeof(sa); |
58801
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
200 |
jobject usa; |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
201 |
|
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
202 |
/* accept connection but ignore ECONNABORTED */ |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
203 |
for (;;) { |
59019 | 204 |
newfd = (jint)accept(fd, (struct sockaddr *)&sa, &sa_len); |
58801
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
205 |
if (newfd >= 0) { |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
206 |
break; |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
207 |
} |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
208 |
if (errno != ECONNABORTED) { |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
209 |
break; |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
210 |
} |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
211 |
/* ECONNABORTED => restart accept */ |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
212 |
} |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
213 |
|
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
214 |
if (newfd < 0) { |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
215 |
if (errno == EAGAIN || errno == EWOULDBLOCK) |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
216 |
return IOS_UNAVAILABLE; |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
217 |
if (errno == EINTR) |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
218 |
return IOS_INTERRUPTED; |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
219 |
JNU_ThrowIOExceptionWithLastError(env, "Accept failed"); |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
220 |
return IOS_THROWN; |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
221 |
} |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
222 |
|
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
223 |
setfdval(env, newfdo, newfd); |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
224 |
|
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
225 |
usa = NET_SockaddrToUnixAddress(env, &sa); |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
226 |
CHECK_NULL_RETURN(usa, IOS_THROWN); |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
227 |
|
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
228 |
(*env)->SetObjectArrayElement(env, usaa, 0, usa); |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
229 |
|
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
230 |
return 1; |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
231 |
} |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
232 |
|
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
233 |
JNIEXPORT jobject JNICALL |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
234 |
Java_sun_nio_ch_Net_localUnixAddress(JNIEnv *env, jclass clazz, jobject fdo) |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
235 |
{ |
59018
6d621f34e24a
moved unix socket address out of SOCKETADDRESS structure
michaelm
parents:
59004
diff
changeset
|
236 |
struct sockaddr_un sa; |
6d621f34e24a
moved unix socket address out of SOCKETADDRESS structure
michaelm
parents:
59004
diff
changeset
|
237 |
socklen_t sa_len = sizeof(sa); |
59019 | 238 |
if (getsockname(fdval(env, fdo), (struct sockaddr *)&sa, &sa_len) < 0) { |
58801
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
239 |
handleSocketError(env, errno); |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
240 |
return NULL; |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
241 |
} |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
242 |
return NET_SockaddrToUnixAddress(env, &sa); |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
243 |
} |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
57649
diff
changeset
|
244 |
|
2 | 245 |
JNIEXPORT void JNICALL |
246 |
Java_sun_nio_ch_Net_initIDs(JNIEnv *env, jclass clazz) |
|
247 |
{ |
|
54154
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
248 |
jclass cls = (*env)->FindClass(env, "java/net/InetSocketAddress"); |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
249 |
CHECK_NULL(cls); |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
250 |
isa_class = (*env)->NewGlobalRef(env, cls); |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
251 |
if (isa_class == NULL) { |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
252 |
JNU_ThrowOutOfMemoryError(env, NULL); |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
253 |
return; |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
254 |
} |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
255 |
isa_ctorID = (*env)->GetMethodID(env, cls, "<init>", "(Ljava/net/InetAddress;I)V"); |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
256 |
CHECK_NULL(isa_ctorID); |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
257 |
|
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
258 |
initInetAddressIDs(env); |
2 | 259 |
} |
260 |
||
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
261 |
JNIEXPORT jboolean JNICALL |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
262 |
Java_sun_nio_ch_Net_isIPv6Available0(JNIEnv* env, jclass cl) |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
263 |
{ |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
264 |
/* |
32232 | 265 |
* Return true if IPv6 is configured |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
266 |
*/ |
32232 | 267 |
return ipv6_available() ? JNI_TRUE : JNI_FALSE; |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
268 |
} |
2 | 269 |
|
36115 | 270 |
JNIEXPORT jboolean JNICALL |
271 |
Java_sun_nio_ch_Net_isReusePortAvailable0(JNIEnv* env, jclass c1) |
|
272 |
{ |
|
273 |
// SO_REUSEPORT is not supported on Windows |
|
274 |
return JNI_FALSE; |
|
275 |
} |
|
276 |
||
18192 | 277 |
JNIEXPORT jint JNICALL |
278 |
Java_sun_nio_ch_Net_isExclusiveBindAvailable(JNIEnv *env, jclass clazz) { |
|
32232 | 279 |
return 1; |
18192 | 280 |
} |
281 |
||
282 |
||
8788
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
7668
diff
changeset
|
283 |
JNIEXPORT jboolean JNICALL |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
7668
diff
changeset
|
284 |
Java_sun_nio_ch_Net_canIPv6SocketJoinIPv4Group0(JNIEnv* env, jclass cl) |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
7668
diff
changeset
|
285 |
{ |
59000
612c58965775
8233435: (dc) DatagramChannel should allow IPv6 socket join IPv4 multicast groups (macOS, win)
alanb
parents:
57649
diff
changeset
|
286 |
/* IPv6 sockets can join IPv4 multicast groups */ |
612c58965775
8233435: (dc) DatagramChannel should allow IPv6 socket join IPv4 multicast groups (macOS, win)
alanb
parents:
57649
diff
changeset
|
287 |
return JNI_TRUE; |
8788
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
7668
diff
changeset
|
288 |
} |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
7668
diff
changeset
|
289 |
|
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
7668
diff
changeset
|
290 |
JNIEXPORT jboolean JNICALL |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
7668
diff
changeset
|
291 |
Java_sun_nio_ch_Net_canJoin6WithIPv4Group0(JNIEnv* env, jclass cl) |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
7668
diff
changeset
|
292 |
{ |
59000
612c58965775
8233435: (dc) DatagramChannel should allow IPv6 socket join IPv4 multicast groups (macOS, win)
alanb
parents:
57649
diff
changeset
|
293 |
/* IPV6_ADD_MEMBERSHIP cannot be used to join IPv4 multicast groups */ |
612c58965775
8233435: (dc) DatagramChannel should allow IPv6 socket join IPv4 multicast groups (macOS, win)
alanb
parents:
57649
diff
changeset
|
294 |
return JNI_FALSE; |
612c58965775
8233435: (dc) DatagramChannel should allow IPv6 socket join IPv4 multicast groups (macOS, win)
alanb
parents:
57649
diff
changeset
|
295 |
} |
612c58965775
8233435: (dc) DatagramChannel should allow IPv6 socket join IPv4 multicast groups (macOS, win)
alanb
parents:
57649
diff
changeset
|
296 |
|
612c58965775
8233435: (dc) DatagramChannel should allow IPv6 socket join IPv4 multicast groups (macOS, win)
alanb
parents:
57649
diff
changeset
|
297 |
JNIEXPORT jboolean JNICALL |
612c58965775
8233435: (dc) DatagramChannel should allow IPv6 socket join IPv4 multicast groups (macOS, win)
alanb
parents:
57649
diff
changeset
|
298 |
Java_sun_nio_ch_Net_canUseIPv6OptionsWithIPv4LocalAddress0(JNIEnv* env, jclass cl) |
612c58965775
8233435: (dc) DatagramChannel should allow IPv6 socket join IPv4 multicast groups (macOS, win)
alanb
parents:
57649
diff
changeset
|
299 |
{ |
612c58965775
8233435: (dc) DatagramChannel should allow IPv6 socket join IPv4 multicast groups (macOS, win)
alanb
parents:
57649
diff
changeset
|
300 |
/* IPV6_XXX socket options cannot be used on IPv6 sockets bound to IPv4 address */ |
8788
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
7668
diff
changeset
|
301 |
return JNI_FALSE; |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
7668
diff
changeset
|
302 |
} |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
7668
diff
changeset
|
303 |
|
2 | 304 |
JNIEXPORT jint JNICALL |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
305 |
Java_sun_nio_ch_Net_socket0(JNIEnv *env, jclass cl, jboolean preferIPv6, |
27178
885f4428b501
8060170: Support SIO_LOOPBACK_FAST_PATH option on Windows
alanb
parents:
26207
diff
changeset
|
306 |
jboolean stream, jboolean reuse, jboolean fastLoopback) |
2 | 307 |
{ |
308 |
SOCKET s; |
|
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
309 |
int domain = (preferIPv6) ? AF_INET6 : AF_INET; |
2 | 310 |
|
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
311 |
s = socket(domain, (stream ? SOCK_STREAM : SOCK_DGRAM), 0); |
2 | 312 |
if (s != INVALID_SOCKET) { |
313 |
SetHandleInformation((HANDLE)s, HANDLE_FLAG_INHERIT, 0); |
|
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
314 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
315 |
/* IPV6_V6ONLY is true by default */ |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
316 |
if (domain == AF_INET6) { |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
317 |
int opt = 0; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
318 |
setsockopt(s, IPPROTO_IPV6, IPV6_V6ONLY, |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
319 |
(const char *)&opt, sizeof(opt)); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
320 |
} |
5777
1c86018749bd
6935563: (dc) Improve connection reset/port unreachable handling [win]
alanb
parents:
5506
diff
changeset
|
321 |
|
1c86018749bd
6935563: (dc) Improve connection reset/port unreachable handling [win]
alanb
parents:
5506
diff
changeset
|
322 |
/* Disable WSAECONNRESET errors for initially unconnected UDP sockets */ |
1c86018749bd
6935563: (dc) Improve connection reset/port unreachable handling [win]
alanb
parents:
5506
diff
changeset
|
323 |
if (!stream) { |
1c86018749bd
6935563: (dc) Improve connection reset/port unreachable handling [win]
alanb
parents:
5506
diff
changeset
|
324 |
setConnectionReset(s, FALSE); |
1c86018749bd
6935563: (dc) Improve connection reset/port unreachable handling [win]
alanb
parents:
5506
diff
changeset
|
325 |
} |
1c86018749bd
6935563: (dc) Improve connection reset/port unreachable handling [win]
alanb
parents:
5506
diff
changeset
|
326 |
|
2 | 327 |
} else { |
328 |
NET_ThrowNew(env, WSAGetLastError(), "socket"); |
|
329 |
} |
|
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
330 |
|
27178
885f4428b501
8060170: Support SIO_LOOPBACK_FAST_PATH option on Windows
alanb
parents:
26207
diff
changeset
|
331 |
if (stream && fastLoopback) { |
885f4428b501
8060170: Support SIO_LOOPBACK_FAST_PATH option on Windows
alanb
parents:
26207
diff
changeset
|
332 |
static int loopback_available = 1; |
885f4428b501
8060170: Support SIO_LOOPBACK_FAST_PATH option on Windows
alanb
parents:
26207
diff
changeset
|
333 |
if (loopback_available) { |
885f4428b501
8060170: Support SIO_LOOPBACK_FAST_PATH option on Windows
alanb
parents:
26207
diff
changeset
|
334 |
int rv = NET_EnableFastTcpLoopback((jint)s); |
885f4428b501
8060170: Support SIO_LOOPBACK_FAST_PATH option on Windows
alanb
parents:
26207
diff
changeset
|
335 |
if (rv) { |
885f4428b501
8060170: Support SIO_LOOPBACK_FAST_PATH option on Windows
alanb
parents:
26207
diff
changeset
|
336 |
if (rv == WSAEOPNOTSUPP) { |
885f4428b501
8060170: Support SIO_LOOPBACK_FAST_PATH option on Windows
alanb
parents:
26207
diff
changeset
|
337 |
loopback_available = 0; |
885f4428b501
8060170: Support SIO_LOOPBACK_FAST_PATH option on Windows
alanb
parents:
26207
diff
changeset
|
338 |
} else { |
885f4428b501
8060170: Support SIO_LOOPBACK_FAST_PATH option on Windows
alanb
parents:
26207
diff
changeset
|
339 |
NET_ThrowNew(env, rv, "fastLoopback"); |
885f4428b501
8060170: Support SIO_LOOPBACK_FAST_PATH option on Windows
alanb
parents:
26207
diff
changeset
|
340 |
} |
885f4428b501
8060170: Support SIO_LOOPBACK_FAST_PATH option on Windows
alanb
parents:
26207
diff
changeset
|
341 |
} |
885f4428b501
8060170: Support SIO_LOOPBACK_FAST_PATH option on Windows
alanb
parents:
26207
diff
changeset
|
342 |
} |
885f4428b501
8060170: Support SIO_LOOPBACK_FAST_PATH option on Windows
alanb
parents:
26207
diff
changeset
|
343 |
} |
885f4428b501
8060170: Support SIO_LOOPBACK_FAST_PATH option on Windows
alanb
parents:
26207
diff
changeset
|
344 |
|
2 | 345 |
return (jint)s; |
346 |
} |
|
347 |
||
348 |
JNIEXPORT void JNICALL |
|
18192 | 349 |
Java_sun_nio_ch_Net_bind0(JNIEnv *env, jclass clazz, jobject fdo, jboolean preferIPv6, |
350 |
jboolean isExclBind, jobject iao, jint port) |
|
2 | 351 |
{ |
352 |
SOCKETADDRESS sa; |
|
353 |
int rv; |
|
43100 | 354 |
int sa_len = 0; |
2 | 355 |
|
43100 | 356 |
if (NET_InetAddressToSockaddr(env, iao, port, &sa, &sa_len, preferIPv6) != 0) { |
357 |
return; |
|
2 | 358 |
} |
359 |
||
43100 | 360 |
rv = NET_WinBind(fdval(env, fdo), &sa, sa_len, isExclBind); |
2 | 361 |
if (rv == SOCKET_ERROR) |
362 |
NET_ThrowNew(env, WSAGetLastError(), "bind"); |
|
363 |
} |
|
364 |
||
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
365 |
JNIEXPORT void JNICALL |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
366 |
Java_sun_nio_ch_Net_listen(JNIEnv *env, jclass cl, jobject fdo, jint backlog) |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
367 |
{ |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
368 |
if (listen(fdval(env,fdo), backlog) == SOCKET_ERROR) { |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
369 |
NET_ThrowNew(env, WSAGetLastError(), "listen"); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
370 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
371 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
372 |
|
2 | 373 |
JNIEXPORT jint JNICALL |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
374 |
Java_sun_nio_ch_Net_connect0(JNIEnv *env, jclass clazz, jboolean preferIPv6, jobject fdo, |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
375 |
jobject iao, jint port) |
2 | 376 |
{ |
377 |
SOCKETADDRESS sa; |
|
378 |
int rv; |
|
43100 | 379 |
int sa_len = 0; |
5777
1c86018749bd
6935563: (dc) Improve connection reset/port unreachable handling [win]
alanb
parents:
5506
diff
changeset
|
380 |
SOCKET s = (SOCKET)fdval(env, fdo); |
2 | 381 |
|
43100 | 382 |
if (NET_InetAddressToSockaddr(env, iao, port, &sa, &sa_len, preferIPv6) != 0) { |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
383 |
return IOS_THROWN; |
2 | 384 |
} |
385 |
||
43100 | 386 |
rv = connect(s, &sa.sa, sa_len); |
2 | 387 |
if (rv != 0) { |
388 |
int err = WSAGetLastError(); |
|
389 |
if (err == WSAEINPROGRESS || err == WSAEWOULDBLOCK) { |
|
390 |
return IOS_UNAVAILABLE; |
|
391 |
} |
|
392 |
NET_ThrowNew(env, err, "connect"); |
|
393 |
return IOS_THROWN; |
|
5777
1c86018749bd
6935563: (dc) Improve connection reset/port unreachable handling [win]
alanb
parents:
5506
diff
changeset
|
394 |
} else { |
1c86018749bd
6935563: (dc) Improve connection reset/port unreachable handling [win]
alanb
parents:
5506
diff
changeset
|
395 |
/* Enable WSAECONNRESET errors when a UDP socket is connected */ |
1c86018749bd
6935563: (dc) Improve connection reset/port unreachable handling [win]
alanb
parents:
5506
diff
changeset
|
396 |
int type = 0, optlen = sizeof(type); |
1c86018749bd
6935563: (dc) Improve connection reset/port unreachable handling [win]
alanb
parents:
5506
diff
changeset
|
397 |
rv = getsockopt(s, SOL_SOCKET, SO_TYPE, (char*)&type, &optlen); |
1c86018749bd
6935563: (dc) Improve connection reset/port unreachable handling [win]
alanb
parents:
5506
diff
changeset
|
398 |
if (rv == 0 && type == SOCK_DGRAM) { |
1c86018749bd
6935563: (dc) Improve connection reset/port unreachable handling [win]
alanb
parents:
5506
diff
changeset
|
399 |
setConnectionReset(s, TRUE); |
1c86018749bd
6935563: (dc) Improve connection reset/port unreachable handling [win]
alanb
parents:
5506
diff
changeset
|
400 |
} |
2 | 401 |
} |
402 |
return 1; |
|
403 |
} |
|
404 |
||
405 |
JNIEXPORT jint JNICALL |
|
54154
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
406 |
Java_sun_nio_ch_Net_accept(JNIEnv *env, jclass clazz, jobject fdo, jobject newfdo, |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
407 |
jobjectArray isaa) |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
408 |
{ |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
409 |
jint fd = fdval(env,fdo); |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
410 |
jint newfd; |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
411 |
SOCKETADDRESS sa; |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
412 |
int addrlen = sizeof(sa); |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
413 |
jobject remote_ia; |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
414 |
jint remote_port = 0; |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
415 |
jobject isa; |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
416 |
|
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
417 |
memset((char *)&sa, 0, sizeof(sa)); |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
418 |
newfd = (jint) accept(fd, &sa.sa, &addrlen); |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
419 |
if (newfd == INVALID_SOCKET) { |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
420 |
int theErr = (jint)WSAGetLastError(); |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
421 |
if (theErr == WSAEWOULDBLOCK) { |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
422 |
return IOS_UNAVAILABLE; |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
423 |
} |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
424 |
JNU_ThrowIOExceptionWithLastError(env, "Accept failed"); |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
425 |
return IOS_THROWN; |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
426 |
} |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
427 |
|
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
428 |
SetHandleInformation((HANDLE)(UINT_PTR)newfd, HANDLE_FLAG_INHERIT, 0); |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
429 |
setfdval(env, newfdo, newfd); |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
430 |
|
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
431 |
remote_ia = NET_SockaddrToInetAddress(env, &sa, (int *)&remote_port); |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
432 |
CHECK_NULL_RETURN(remote_ia, IOS_THROWN); |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
433 |
|
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
434 |
isa = (*env)->NewObject(env, isa_class, isa_ctorID, remote_ia, remote_port); |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
435 |
CHECK_NULL_RETURN(isa, IOS_THROWN); |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
436 |
(*env)->SetObjectArrayElement(env, isaa, 0, isa); |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
437 |
|
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
438 |
return 1; |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
439 |
} |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
440 |
|
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
441 |
JNIEXPORT jint JNICALL |
2 | 442 |
Java_sun_nio_ch_Net_localPort(JNIEnv *env, jclass clazz, jobject fdo) |
443 |
{ |
|
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
444 |
SOCKETADDRESS sa; |
2 | 445 |
int sa_len = sizeof(sa); |
446 |
||
59000
612c58965775
8233435: (dc) DatagramChannel should allow IPv6 socket join IPv4 multicast groups (macOS, win)
alanb
parents:
57649
diff
changeset
|
447 |
if (getsockname(fdval(env, fdo), &sa.sa, &sa_len) == SOCKET_ERROR) { |
2 | 448 |
int error = WSAGetLastError(); |
449 |
if (error == WSAEINVAL) { |
|
450 |
return 0; |
|
451 |
} |
|
452 |
NET_ThrowNew(env, error, "getsockname"); |
|
453 |
return IOS_THROWN; |
|
454 |
} |
|
43100 | 455 |
return NET_GetPortFromSockaddr(&sa); |
2 | 456 |
} |
457 |
||
458 |
JNIEXPORT jobject JNICALL |
|
459 |
Java_sun_nio_ch_Net_localInetAddress(JNIEnv *env, jclass clazz, jobject fdo) |
|
460 |
{ |
|
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
461 |
SOCKETADDRESS sa; |
2 | 462 |
int sa_len = sizeof(sa); |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
463 |
int port; |
2 | 464 |
|
59000
612c58965775
8233435: (dc) DatagramChannel should allow IPv6 socket join IPv4 multicast groups (macOS, win)
alanb
parents:
57649
diff
changeset
|
465 |
if (getsockname(fdval(env, fdo), &sa.sa, &sa_len) == SOCKET_ERROR) { |
2 | 466 |
NET_ThrowNew(env, WSAGetLastError(), "getsockname"); |
467 |
return NULL; |
|
468 |
} |
|
43100 | 469 |
return NET_SockaddrToInetAddress(env, &sa, &port); |
2 | 470 |
} |
471 |
||
472 |
JNIEXPORT jint JNICALL |
|
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
473 |
Java_sun_nio_ch_Net_remotePort(JNIEnv *env, jclass clazz, jobject fdo) |
2 | 474 |
{ |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
475 |
SOCKETADDRESS sa; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
476 |
int sa_len = sizeof(sa); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
477 |
|
59000
612c58965775
8233435: (dc) DatagramChannel should allow IPv6 socket join IPv4 multicast groups (macOS, win)
alanb
parents:
57649
diff
changeset
|
478 |
if (getpeername(fdval(env, fdo), &sa.sa, &sa_len) == SOCKET_ERROR) { |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
479 |
int error = WSAGetLastError(); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
480 |
if (error == WSAEINVAL) { |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
481 |
return 0; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
482 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
483 |
NET_ThrowNew(env, error, "getsockname"); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
484 |
return IOS_THROWN; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
485 |
} |
43100 | 486 |
return NET_GetPortFromSockaddr(&sa); |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
487 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
488 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
489 |
JNIEXPORT jobject JNICALL |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
490 |
Java_sun_nio_ch_Net_remoteInetAddress(JNIEnv *env, jclass clazz, jobject fdo) |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
491 |
{ |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
492 |
SOCKETADDRESS sa; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
493 |
int sa_len = sizeof(sa); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
494 |
int port; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
495 |
|
59000
612c58965775
8233435: (dc) DatagramChannel should allow IPv6 socket join IPv4 multicast groups (macOS, win)
alanb
parents:
57649
diff
changeset
|
496 |
if (getpeername(fdval(env, fdo), &sa.sa, &sa_len) == SOCKET_ERROR) { |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
497 |
NET_ThrowNew(env, WSAGetLastError(), "getsockname"); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
498 |
return NULL; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
499 |
} |
43100 | 500 |
return NET_SockaddrToInetAddress(env, &sa, &port); |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
501 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
502 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
503 |
JNIEXPORT jint JNICALL |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
504 |
Java_sun_nio_ch_Net_getIntOption0(JNIEnv *env, jclass clazz, jobject fdo, |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
505 |
jboolean mayNeedConversion, jint level, jint opt) |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
506 |
{ |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
507 |
int result = 0; |
2 | 508 |
struct linger linger; |
509 |
char *arg; |
|
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
510 |
int arglen, n; |
2 | 511 |
|
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
512 |
if (level == SOL_SOCKET && opt == SO_LINGER) { |
2 | 513 |
arg = (char *)&linger; |
514 |
arglen = sizeof(linger); |
|
515 |
} else { |
|
516 |
arg = (char *)&result; |
|
517 |
arglen = sizeof(result); |
|
518 |
} |
|
519 |
||
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
520 |
/** |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
521 |
* HACK: IP_TOS is deprecated on Windows and querying the option |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
522 |
* returns a protocol error. NET_GetSockOpt handles this and uses |
25388
65f81ea02187
8048212: Two tests failed with "java.net.SocketException: Bad protocol option" on Windows after 8029607
michaelm
parents:
25170
diff
changeset
|
523 |
* a fallback mechanism. Same applies to IPV6_TCLASS |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
524 |
*/ |
25388
65f81ea02187
8048212: Two tests failed with "java.net.SocketException: Bad protocol option" on Windows after 8029607
michaelm
parents:
25170
diff
changeset
|
525 |
if ((level == IPPROTO_IP && opt == IP_TOS) || (level == IPPROTO_IPV6 && opt == IPV6_TCLASS)) { |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
526 |
mayNeedConversion = JNI_TRUE; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
527 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
528 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
529 |
if (mayNeedConversion) { |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
530 |
n = NET_GetSockOpt(fdval(env, fdo), level, opt, arg, &arglen); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
531 |
} else { |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
532 |
n = getsockopt(fdval(env, fdo), level, opt, arg, &arglen); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
533 |
} |
59000
612c58965775
8233435: (dc) DatagramChannel should allow IPv6 socket join IPv4 multicast groups (macOS, win)
alanb
parents:
57649
diff
changeset
|
534 |
if (n == SOCKET_ERROR) { |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
535 |
handleSocketError(env, WSAGetLastError()); |
2 | 536 |
return IOS_THROWN; |
537 |
} |
|
538 |
||
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
539 |
if (level == SOL_SOCKET && opt == SO_LINGER) |
2 | 540 |
return linger.l_onoff ? linger.l_linger : -1; |
541 |
else |
|
542 |
return result; |
|
543 |
} |
|
544 |
||
545 |
JNIEXPORT void JNICALL |
|
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
546 |
Java_sun_nio_ch_Net_setIntOption0(JNIEnv *env, jclass clazz, jobject fdo, |
25170
f58832169add
8029607: Type of Service (TOS) cannot be set in IPv6 header
michaelm
parents:
23010
diff
changeset
|
547 |
jboolean mayNeedConversion, jint level, jint opt, jint arg, jboolean ipv6) |
2 | 548 |
{ |
549 |
struct linger linger; |
|
550 |
char *parg; |
|
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
551 |
int arglen, n; |
2 | 552 |
|
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
553 |
if (level == SOL_SOCKET && opt == SO_LINGER) { |
2 | 554 |
parg = (char *)&linger; |
555 |
arglen = sizeof(linger); |
|
556 |
if (arg >= 0) { |
|
557 |
linger.l_onoff = 1; |
|
558 |
linger.l_linger = (unsigned short)arg; |
|
559 |
} else { |
|
560 |
linger.l_onoff = 0; |
|
561 |
linger.l_linger = 0; |
|
562 |
} |
|
563 |
} else { |
|
564 |
parg = (char *)&arg; |
|
565 |
arglen = sizeof(arg); |
|
566 |
} |
|
567 |
||
25388
65f81ea02187
8048212: Two tests failed with "java.net.SocketException: Bad protocol option" on Windows after 8029607
michaelm
parents:
25170
diff
changeset
|
568 |
if (level == IPPROTO_IPV6 && opt == IPV6_TCLASS) { |
65f81ea02187
8048212: Two tests failed with "java.net.SocketException: Bad protocol option" on Windows after 8029607
michaelm
parents:
25170
diff
changeset
|
569 |
/* No op */ |
65f81ea02187
8048212: Two tests failed with "java.net.SocketException: Bad protocol option" on Windows after 8029607
michaelm
parents:
25170
diff
changeset
|
570 |
return; |
65f81ea02187
8048212: Two tests failed with "java.net.SocketException: Bad protocol option" on Windows after 8029607
michaelm
parents:
25170
diff
changeset
|
571 |
} |
65f81ea02187
8048212: Two tests failed with "java.net.SocketException: Bad protocol option" on Windows after 8029607
michaelm
parents:
25170
diff
changeset
|
572 |
|
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
573 |
if (mayNeedConversion) { |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
574 |
n = NET_SetSockOpt(fdval(env, fdo), level, opt, parg, arglen); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
575 |
} else { |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
576 |
n = setsockopt(fdval(env, fdo), level, opt, parg, arglen); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
577 |
} |
59000
612c58965775
8233435: (dc) DatagramChannel should allow IPv6 socket join IPv4 multicast groups (macOS, win)
alanb
parents:
57649
diff
changeset
|
578 |
if (n == SOCKET_ERROR) |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
579 |
handleSocketError(env, WSAGetLastError()); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
580 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
581 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
582 |
JNIEXPORT jint JNICALL |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
583 |
Java_sun_nio_ch_Net_joinOrDrop4(JNIEnv *env, jobject this, jboolean join, jobject fdo, |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
584 |
jint group, jint interf, jint source) |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
585 |
{ |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
586 |
struct ip_mreq mreq; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
587 |
struct my_ip_mreq_source mreq_source; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
588 |
int opt, n, optlen; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
589 |
void* optval; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
590 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
591 |
if (source == 0) { |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
592 |
mreq.imr_multiaddr.s_addr = htonl(group); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
593 |
mreq.imr_interface.s_addr = htonl(interf); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
594 |
opt = (join) ? IP_ADD_MEMBERSHIP : IP_DROP_MEMBERSHIP; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
595 |
optval = (void*)&mreq; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
596 |
optlen = sizeof(mreq); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
597 |
} else { |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
598 |
mreq_source.imr_multiaddr.s_addr = htonl(group); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
599 |
mreq_source.imr_sourceaddr.s_addr = htonl(source); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
600 |
mreq_source.imr_interface.s_addr = htonl(interf); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
601 |
opt = (join) ? IP_ADD_SOURCE_MEMBERSHIP : IP_DROP_SOURCE_MEMBERSHIP; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
602 |
optval = (void*)&mreq_source; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
603 |
optlen = sizeof(mreq_source); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
604 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
605 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
606 |
n = setsockopt(fdval(env,fdo), IPPROTO_IP, opt, optval, optlen); |
59000
612c58965775
8233435: (dc) DatagramChannel should allow IPv6 socket join IPv4 multicast groups (macOS, win)
alanb
parents:
57649
diff
changeset
|
607 |
if (n == SOCKET_ERROR) { |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
608 |
if (join && (WSAGetLastError() == WSAENOPROTOOPT)) |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
609 |
return IOS_UNAVAILABLE; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
610 |
handleSocketError(env, WSAGetLastError()); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
611 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
612 |
return 0; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
613 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
614 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
615 |
JNIEXPORT jint JNICALL |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
616 |
Java_sun_nio_ch_Net_blockOrUnblock4(JNIEnv *env, jobject this, jboolean block, jobject fdo, |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
617 |
jint group, jint interf, jint source) |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
618 |
{ |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
619 |
struct my_ip_mreq_source mreq_source; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
620 |
int n; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
621 |
int opt = (block) ? IP_BLOCK_SOURCE : IP_UNBLOCK_SOURCE; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
622 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
623 |
mreq_source.imr_multiaddr.s_addr = htonl(group); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
624 |
mreq_source.imr_sourceaddr.s_addr = htonl(source); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
625 |
mreq_source.imr_interface.s_addr = htonl(interf); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
626 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
627 |
n = setsockopt(fdval(env,fdo), IPPROTO_IP, opt, |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
628 |
(void*)&mreq_source, sizeof(mreq_source)); |
59000
612c58965775
8233435: (dc) DatagramChannel should allow IPv6 socket join IPv4 multicast groups (macOS, win)
alanb
parents:
57649
diff
changeset
|
629 |
if (n == SOCKET_ERROR) { |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
630 |
if (block && (WSAGetLastError() == WSAENOPROTOOPT)) |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
631 |
return IOS_UNAVAILABLE; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
632 |
handleSocketError(env, WSAGetLastError()); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
633 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
634 |
return 0; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
635 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
636 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
637 |
/** |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
638 |
* Call setsockopt with a IPPROTO_IPV6 level socket option |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
639 |
* and a group_source_req structure as the option value. The |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
640 |
* given IPv6 group, interface index, and IPv6 source address |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
641 |
* are copied into the structure. |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
642 |
*/ |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
643 |
static int setGroupSourceReqOption(JNIEnv* env, |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
644 |
jobject fdo, |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
645 |
int opt, |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
646 |
jbyteArray group, |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
647 |
jint index, |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
648 |
jbyteArray source) |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
649 |
{ |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
650 |
struct my_group_source_req req; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
651 |
struct sockaddr_in6* sin6; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
652 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
653 |
req.gsr_interface = (ULONG)index; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
654 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
655 |
sin6 = (struct sockaddr_in6*)&(req.gsr_group); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
656 |
sin6->sin6_family = AF_INET6; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
657 |
COPY_INET6_ADDRESS(env, group, (jbyte*)&(sin6->sin6_addr)); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
658 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
659 |
sin6 = (struct sockaddr_in6*)&(req.gsr_source); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
660 |
sin6->sin6_family = AF_INET6; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
661 |
COPY_INET6_ADDRESS(env, source, (jbyte*)&(sin6->sin6_addr)); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
662 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
663 |
return setsockopt(fdval(env,fdo), IPPROTO_IPV6, opt, (void*)&req, sizeof(req)); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
664 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
665 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
666 |
JNIEXPORT jint JNICALL |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
667 |
Java_sun_nio_ch_Net_joinOrDrop6(JNIEnv *env, jobject this, jboolean join, jobject fdo, |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
668 |
jbyteArray group, jint index, jbyteArray source) |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
669 |
{ |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
670 |
struct ipv6_mreq mreq6; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
671 |
int n; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
672 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
673 |
if (source == NULL) { |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
674 |
int opt = (join) ? IPV6_ADD_MEMBERSHIP : IPV6_DROP_MEMBERSHIP; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
675 |
COPY_INET6_ADDRESS(env, group, (jbyte*)&(mreq6.ipv6mr_multiaddr)); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
676 |
mreq6.ipv6mr_interface = (int)index; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
677 |
n = setsockopt(fdval(env,fdo), IPPROTO_IPV6, opt, |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
678 |
(void*)&mreq6, sizeof(mreq6)); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
679 |
} else { |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
680 |
int opt = (join) ? MCAST_JOIN_SOURCE_GROUP : MCAST_LEAVE_SOURCE_GROUP; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
681 |
n = setGroupSourceReqOption(env, fdo, opt, group, index, source); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
682 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
683 |
|
59000
612c58965775
8233435: (dc) DatagramChannel should allow IPv6 socket join IPv4 multicast groups (macOS, win)
alanb
parents:
57649
diff
changeset
|
684 |
if (n == SOCKET_ERROR) { |
612c58965775
8233435: (dc) DatagramChannel should allow IPv6 socket join IPv4 multicast groups (macOS, win)
alanb
parents:
57649
diff
changeset
|
685 |
handleSocketError(env, WSAGetLastError()); |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
686 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
687 |
return 0; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
688 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
689 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
690 |
JNIEXPORT jint JNICALL |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
691 |
Java_sun_nio_ch_Net_blockOrUnblock6(JNIEnv *env, jobject this, jboolean block, jobject fdo, |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
692 |
jbyteArray group, jint index, jbyteArray source) |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
693 |
{ |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
694 |
int opt = (block) ? MCAST_BLOCK_SOURCE : MCAST_UNBLOCK_SOURCE; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
695 |
int n = setGroupSourceReqOption(env, fdo, opt, group, index, source); |
59000
612c58965775
8233435: (dc) DatagramChannel should allow IPv6 socket join IPv4 multicast groups (macOS, win)
alanb
parents:
57649
diff
changeset
|
696 |
if (n == SOCKET_ERROR) { |
612c58965775
8233435: (dc) DatagramChannel should allow IPv6 socket join IPv4 multicast groups (macOS, win)
alanb
parents:
57649
diff
changeset
|
697 |
handleSocketError(env, WSAGetLastError()); |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
698 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
699 |
return 0; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
700 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
701 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
702 |
JNIEXPORT void JNICALL |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
703 |
Java_sun_nio_ch_Net_setInterface4(JNIEnv* env, jobject this, jobject fdo, jint interf) |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
704 |
{ |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
705 |
struct in_addr in; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
706 |
int arglen = sizeof(struct in_addr); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
707 |
int n; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
708 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
709 |
in.s_addr = htonl(interf); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
710 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
711 |
n = setsockopt(fdval(env, fdo), IPPROTO_IP, IP_MULTICAST_IF, |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
712 |
(void*)&(in.s_addr), arglen); |
59000
612c58965775
8233435: (dc) DatagramChannel should allow IPv6 socket join IPv4 multicast groups (macOS, win)
alanb
parents:
57649
diff
changeset
|
713 |
if (n == SOCKET_ERROR) { |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
714 |
handleSocketError(env, WSAGetLastError()); |
2 | 715 |
} |
716 |
} |
|
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
717 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
718 |
JNIEXPORT jint JNICALL |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
719 |
Java_sun_nio_ch_Net_getInterface4(JNIEnv* env, jobject this, jobject fdo) |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
720 |
{ |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
721 |
struct in_addr in; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
722 |
int arglen = sizeof(struct in_addr); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
723 |
int n; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
724 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
725 |
n = getsockopt(fdval(env, fdo), IPPROTO_IP, IP_MULTICAST_IF, (void*)&in, &arglen); |
59000
612c58965775
8233435: (dc) DatagramChannel should allow IPv6 socket join IPv4 multicast groups (macOS, win)
alanb
parents:
57649
diff
changeset
|
726 |
if (n == SOCKET_ERROR) { |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
727 |
handleSocketError(env, WSAGetLastError()); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
728 |
return IOS_THROWN; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
729 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
730 |
return ntohl(in.s_addr); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
731 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
732 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
733 |
JNIEXPORT void JNICALL |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
734 |
Java_sun_nio_ch_Net_setInterface6(JNIEnv* env, jobject this, jobject fdo, jint index) |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
735 |
{ |
59000
612c58965775
8233435: (dc) DatagramChannel should allow IPv6 socket join IPv4 multicast groups (macOS, win)
alanb
parents:
57649
diff
changeset
|
736 |
DWORD value = (jint)index; |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
737 |
int arglen = sizeof(value); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
738 |
int n; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
739 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
740 |
n = setsockopt(fdval(env, fdo), IPPROTO_IPV6, IPV6_MULTICAST_IF, |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
741 |
(void*)&(index), arglen); |
59000
612c58965775
8233435: (dc) DatagramChannel should allow IPv6 socket join IPv4 multicast groups (macOS, win)
alanb
parents:
57649
diff
changeset
|
742 |
if (n == SOCKET_ERROR) { |
612c58965775
8233435: (dc) DatagramChannel should allow IPv6 socket join IPv4 multicast groups (macOS, win)
alanb
parents:
57649
diff
changeset
|
743 |
handleSocketError(env, WSAGetLastError()); |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
744 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
745 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
746 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
747 |
JNIEXPORT jint JNICALL |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
748 |
Java_sun_nio_ch_Net_getInterface6(JNIEnv* env, jobject this, jobject fdo) |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
749 |
{ |
59000
612c58965775
8233435: (dc) DatagramChannel should allow IPv6 socket join IPv4 multicast groups (macOS, win)
alanb
parents:
57649
diff
changeset
|
750 |
DWORD index; |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
751 |
int arglen = sizeof(index); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
752 |
int n; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
753 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
754 |
n = getsockopt(fdval(env, fdo), IPPROTO_IPV6, IPV6_MULTICAST_IF, (void*)&index, &arglen); |
59000
612c58965775
8233435: (dc) DatagramChannel should allow IPv6 socket join IPv4 multicast groups (macOS, win)
alanb
parents:
57649
diff
changeset
|
755 |
if (n == SOCKET_ERROR) { |
612c58965775
8233435: (dc) DatagramChannel should allow IPv6 socket join IPv4 multicast groups (macOS, win)
alanb
parents:
57649
diff
changeset
|
756 |
handleSocketError(env, WSAGetLastError()); |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
757 |
return -1; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
758 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
759 |
return (jint)index; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
760 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
761 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
762 |
JNIEXPORT void JNICALL |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
763 |
Java_sun_nio_ch_Net_shutdown(JNIEnv *env, jclass cl, jobject fdo, jint jhow) { |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
764 |
int how = (jhow == sun_nio_ch_Net_SHUT_RD) ? SD_RECEIVE : |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
765 |
(jhow == sun_nio_ch_Net_SHUT_WR) ? SD_SEND : SD_BOTH; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
766 |
if (shutdown(fdval(env, fdo), how) == SOCKET_ERROR) { |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
767 |
NET_ThrowNew(env, WSAGetLastError(), "shutdown"); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
768 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
769 |
} |
14025
fbebe005a3ee
7184932: Remove the temporary Selector usage in the NIO socket adapters
robm
parents:
9035
diff
changeset
|
770 |
|
fbebe005a3ee
7184932: Remove the temporary Selector usage in the NIO socket adapters
robm
parents:
9035
diff
changeset
|
771 |
JNIEXPORT jint JNICALL |
53422
6f02e036630e
8217461: (ch) Add Net.available to return the number of bytes in the socket input buffer
alanb
parents:
47216
diff
changeset
|
772 |
Java_sun_nio_ch_Net_available(JNIEnv *env, jclass cl, jobject fdo) |
6f02e036630e
8217461: (ch) Add Net.available to return the number of bytes in the socket input buffer
alanb
parents:
47216
diff
changeset
|
773 |
{ |
6f02e036630e
8217461: (ch) Add Net.available to return the number of bytes in the socket input buffer
alanb
parents:
47216
diff
changeset
|
774 |
int count = 0; |
6f02e036630e
8217461: (ch) Add Net.available to return the number of bytes in the socket input buffer
alanb
parents:
47216
diff
changeset
|
775 |
if (NET_SocketAvailable(fdval(env, fdo), &count) != 0) { |
6f02e036630e
8217461: (ch) Add Net.available to return the number of bytes in the socket input buffer
alanb
parents:
47216
diff
changeset
|
776 |
handleSocketError(env, WSAGetLastError()); |
6f02e036630e
8217461: (ch) Add Net.available to return the number of bytes in the socket input buffer
alanb
parents:
47216
diff
changeset
|
777 |
return IOS_THROWN; |
6f02e036630e
8217461: (ch) Add Net.available to return the number of bytes in the socket input buffer
alanb
parents:
47216
diff
changeset
|
778 |
} |
6f02e036630e
8217461: (ch) Add Net.available to return the number of bytes in the socket input buffer
alanb
parents:
47216
diff
changeset
|
779 |
return (jint) count; |
6f02e036630e
8217461: (ch) Add Net.available to return the number of bytes in the socket input buffer
alanb
parents:
47216
diff
changeset
|
780 |
} |
6f02e036630e
8217461: (ch) Add Net.available to return the number of bytes in the socket input buffer
alanb
parents:
47216
diff
changeset
|
781 |
|
6f02e036630e
8217461: (ch) Add Net.available to return the number of bytes in the socket input buffer
alanb
parents:
47216
diff
changeset
|
782 |
JNIEXPORT jint JNICALL |
14025
fbebe005a3ee
7184932: Remove the temporary Selector usage in the NIO socket adapters
robm
parents:
9035
diff
changeset
|
783 |
Java_sun_nio_ch_Net_poll(JNIEnv* env, jclass this, jobject fdo, jint events, jlong timeout) |
fbebe005a3ee
7184932: Remove the temporary Selector usage in the NIO socket adapters
robm
parents:
9035
diff
changeset
|
784 |
{ |
fbebe005a3ee
7184932: Remove the temporary Selector usage in the NIO socket adapters
robm
parents:
9035
diff
changeset
|
785 |
int rv; |
fbebe005a3ee
7184932: Remove the temporary Selector usage in the NIO socket adapters
robm
parents:
9035
diff
changeset
|
786 |
int revents = 0; |
fbebe005a3ee
7184932: Remove the temporary Selector usage in the NIO socket adapters
robm
parents:
9035
diff
changeset
|
787 |
struct timeval t; |
fbebe005a3ee
7184932: Remove the temporary Selector usage in the NIO socket adapters
robm
parents:
9035
diff
changeset
|
788 |
fd_set rd, wr, ex; |
fbebe005a3ee
7184932: Remove the temporary Selector usage in the NIO socket adapters
robm
parents:
9035
diff
changeset
|
789 |
jint fd = fdval(env, fdo); |
fbebe005a3ee
7184932: Remove the temporary Selector usage in the NIO socket adapters
robm
parents:
9035
diff
changeset
|
790 |
|
fbebe005a3ee
7184932: Remove the temporary Selector usage in the NIO socket adapters
robm
parents:
9035
diff
changeset
|
791 |
FD_ZERO(&rd); |
fbebe005a3ee
7184932: Remove the temporary Selector usage in the NIO socket adapters
robm
parents:
9035
diff
changeset
|
792 |
FD_ZERO(&wr); |
fbebe005a3ee
7184932: Remove the temporary Selector usage in the NIO socket adapters
robm
parents:
9035
diff
changeset
|
793 |
FD_ZERO(&ex); |
22604
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
18192
diff
changeset
|
794 |
if (events & POLLIN) { |
14025
fbebe005a3ee
7184932: Remove the temporary Selector usage in the NIO socket adapters
robm
parents:
9035
diff
changeset
|
795 |
FD_SET(fd, &rd); |
fbebe005a3ee
7184932: Remove the temporary Selector usage in the NIO socket adapters
robm
parents:
9035
diff
changeset
|
796 |
} |
22604
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
18192
diff
changeset
|
797 |
if (events & POLLOUT || |
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
18192
diff
changeset
|
798 |
events & POLLCONN) { |
14025
fbebe005a3ee
7184932: Remove the temporary Selector usage in the NIO socket adapters
robm
parents:
9035
diff
changeset
|
799 |
FD_SET(fd, &wr); |
fbebe005a3ee
7184932: Remove the temporary Selector usage in the NIO socket adapters
robm
parents:
9035
diff
changeset
|
800 |
} |
fbebe005a3ee
7184932: Remove the temporary Selector usage in the NIO socket adapters
robm
parents:
9035
diff
changeset
|
801 |
FD_SET(fd, &ex); |
fbebe005a3ee
7184932: Remove the temporary Selector usage in the NIO socket adapters
robm
parents:
9035
diff
changeset
|
802 |
|
57649
b2fde6701654
8229018: Switching to an infinite socket timeout on Windows leads to high CPU load
michaelm
parents:
54902
diff
changeset
|
803 |
if (timeout >= 0) { |
b2fde6701654
8229018: Switching to an infinite socket timeout on Windows leads to high CPU load
michaelm
parents:
54902
diff
changeset
|
804 |
t.tv_sec = (long)(timeout / 1000); |
b2fde6701654
8229018: Switching to an infinite socket timeout on Windows leads to high CPU load
michaelm
parents:
54902
diff
changeset
|
805 |
t.tv_usec = (timeout % 1000) * 1000; |
b2fde6701654
8229018: Switching to an infinite socket timeout on Windows leads to high CPU load
michaelm
parents:
54902
diff
changeset
|
806 |
} |
b2fde6701654
8229018: Switching to an infinite socket timeout on Windows leads to high CPU load
michaelm
parents:
54902
diff
changeset
|
807 |
|
b2fde6701654
8229018: Switching to an infinite socket timeout on Windows leads to high CPU load
michaelm
parents:
54902
diff
changeset
|
808 |
rv = select(fd+1, &rd, &wr, &ex, (timeout >= 0) ? &t : NULL); |
14025
fbebe005a3ee
7184932: Remove the temporary Selector usage in the NIO socket adapters
robm
parents:
9035
diff
changeset
|
809 |
|
fbebe005a3ee
7184932: Remove the temporary Selector usage in the NIO socket adapters
robm
parents:
9035
diff
changeset
|
810 |
/* save last winsock error */ |
fbebe005a3ee
7184932: Remove the temporary Selector usage in the NIO socket adapters
robm
parents:
9035
diff
changeset
|
811 |
if (rv == SOCKET_ERROR) { |
54902
d1717e05e51c
8223442: java/nio/channels/SocketChannel/AdaptorStreams.java testConcurrentTimedReadWrite3(): failure
alanb
parents:
54246
diff
changeset
|
812 |
handleSocketError(env, WSAGetLastError()); |
14025
fbebe005a3ee
7184932: Remove the temporary Selector usage in the NIO socket adapters
robm
parents:
9035
diff
changeset
|
813 |
return IOS_THROWN; |
fbebe005a3ee
7184932: Remove the temporary Selector usage in the NIO socket adapters
robm
parents:
9035
diff
changeset
|
814 |
} else if (rv >= 0) { |
fbebe005a3ee
7184932: Remove the temporary Selector usage in the NIO socket adapters
robm
parents:
9035
diff
changeset
|
815 |
rv = 0; |
fbebe005a3ee
7184932: Remove the temporary Selector usage in the NIO socket adapters
robm
parents:
9035
diff
changeset
|
816 |
if (FD_ISSET(fd, &rd)) { |
22604
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
18192
diff
changeset
|
817 |
rv |= POLLIN; |
14025
fbebe005a3ee
7184932: Remove the temporary Selector usage in the NIO socket adapters
robm
parents:
9035
diff
changeset
|
818 |
} |
fbebe005a3ee
7184932: Remove the temporary Selector usage in the NIO socket adapters
robm
parents:
9035
diff
changeset
|
819 |
if (FD_ISSET(fd, &wr)) { |
22604
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
18192
diff
changeset
|
820 |
rv |= POLLOUT; |
14025
fbebe005a3ee
7184932: Remove the temporary Selector usage in the NIO socket adapters
robm
parents:
9035
diff
changeset
|
821 |
} |
fbebe005a3ee
7184932: Remove the temporary Selector usage in the NIO socket adapters
robm
parents:
9035
diff
changeset
|
822 |
if (FD_ISSET(fd, &ex)) { |
22604
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
18192
diff
changeset
|
823 |
rv |= POLLERR; |
14025
fbebe005a3ee
7184932: Remove the temporary Selector usage in the NIO socket adapters
robm
parents:
9035
diff
changeset
|
824 |
} |
fbebe005a3ee
7184932: Remove the temporary Selector usage in the NIO socket adapters
robm
parents:
9035
diff
changeset
|
825 |
} |
fbebe005a3ee
7184932: Remove the temporary Selector usage in the NIO socket adapters
robm
parents:
9035
diff
changeset
|
826 |
return rv; |
fbebe005a3ee
7184932: Remove the temporary Selector usage in the NIO socket adapters
robm
parents:
9035
diff
changeset
|
827 |
} |
22604
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
18192
diff
changeset
|
828 |
|
54246
f04e3492fd88
8221252: (sc) SocketChannel and its socket adaptor need to handle connection reset
alanb
parents:
54154
diff
changeset
|
829 |
JNIEXPORT jboolean JNICALL |
53445
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
830 |
Java_sun_nio_ch_Net_pollConnect(JNIEnv* env, jclass this, jobject fdo, jlong timeout) |
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
831 |
{ |
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
832 |
int optError = 0; |
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
833 |
int result; |
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
834 |
int n = sizeof(int); |
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
835 |
jint fd = fdval(env, fdo); |
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
836 |
fd_set wr, ex; |
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
837 |
struct timeval t; |
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
838 |
|
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
839 |
FD_ZERO(&wr); |
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
840 |
FD_ZERO(&ex); |
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
841 |
FD_SET((u_int)fd, &wr); |
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
842 |
FD_SET((u_int)fd, &ex); |
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
843 |
|
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
844 |
if (timeout >= 0) { |
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
845 |
t.tv_sec = (long)(timeout / 1000); |
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
846 |
t.tv_usec = (timeout % 1000) * 1000; |
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
847 |
} |
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
848 |
|
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
849 |
result = select(fd+1, 0, &wr, &ex, (timeout >= 0) ? &t : NULL); |
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
850 |
|
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
851 |
if (result == SOCKET_ERROR) { |
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
852 |
handleSocketError(env, WSAGetLastError()); |
54246
f04e3492fd88
8221252: (sc) SocketChannel and its socket adaptor need to handle connection reset
alanb
parents:
54154
diff
changeset
|
853 |
return JNI_FALSE; |
53445
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
854 |
} else if (result == 0) { |
54246
f04e3492fd88
8221252: (sc) SocketChannel and its socket adaptor need to handle connection reset
alanb
parents:
54154
diff
changeset
|
855 |
return JNI_FALSE; |
53445
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
856 |
} else { |
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
857 |
// connection established if writable and no error to check |
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
858 |
if (FD_ISSET(fd, &wr) && !FD_ISSET(fd, &ex)) { |
54246
f04e3492fd88
8221252: (sc) SocketChannel and its socket adaptor need to handle connection reset
alanb
parents:
54154
diff
changeset
|
859 |
return JNI_TRUE; |
53445
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
860 |
} |
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
861 |
result = getsockopt((SOCKET)fd, |
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
862 |
SOL_SOCKET, |
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
863 |
SO_ERROR, |
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
864 |
(char *)&optError, |
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
865 |
&n); |
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
866 |
if (result == SOCKET_ERROR) { |
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
867 |
int lastError = WSAGetLastError(); |
54246
f04e3492fd88
8221252: (sc) SocketChannel and its socket adaptor need to handle connection reset
alanb
parents:
54154
diff
changeset
|
868 |
if (lastError != WSAEINPROGRESS) { |
f04e3492fd88
8221252: (sc) SocketChannel and its socket adaptor need to handle connection reset
alanb
parents:
54154
diff
changeset
|
869 |
NET_ThrowNew(env, lastError, "getsockopt"); |
53445
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
870 |
} |
54246
f04e3492fd88
8221252: (sc) SocketChannel and its socket adaptor need to handle connection reset
alanb
parents:
54154
diff
changeset
|
871 |
} else if (optError != NO_ERROR) { |
f04e3492fd88
8221252: (sc) SocketChannel and its socket adaptor need to handle connection reset
alanb
parents:
54154
diff
changeset
|
872 |
handleSocketError(env, optError); |
53445
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
873 |
} |
54246
f04e3492fd88
8221252: (sc) SocketChannel and its socket adaptor need to handle connection reset
alanb
parents:
54154
diff
changeset
|
874 |
return JNI_FALSE; |
53445
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
875 |
} |
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
876 |
} |
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
877 |
|
22604
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
18192
diff
changeset
|
878 |
JNIEXPORT jshort JNICALL |
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
18192
diff
changeset
|
879 |
Java_sun_nio_ch_Net_pollinValue(JNIEnv *env, jclass this) |
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
18192
diff
changeset
|
880 |
{ |
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
18192
diff
changeset
|
881 |
return (jshort)POLLIN; |
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
18192
diff
changeset
|
882 |
} |
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
18192
diff
changeset
|
883 |
|
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
18192
diff
changeset
|
884 |
JNIEXPORT jshort JNICALL |
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
18192
diff
changeset
|
885 |
Java_sun_nio_ch_Net_polloutValue(JNIEnv *env, jclass this) |
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
18192
diff
changeset
|
886 |
{ |
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
18192
diff
changeset
|
887 |
return (jshort)POLLOUT; |
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
18192
diff
changeset
|
888 |
} |
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
18192
diff
changeset
|
889 |
|
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
18192
diff
changeset
|
890 |
JNIEXPORT jshort JNICALL |
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
18192
diff
changeset
|
891 |
Java_sun_nio_ch_Net_pollerrValue(JNIEnv *env, jclass this) |
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
18192
diff
changeset
|
892 |
{ |
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
18192
diff
changeset
|
893 |
return (jshort)POLLERR; |
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
18192
diff
changeset
|
894 |
} |
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
18192
diff
changeset
|
895 |
|
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
18192
diff
changeset
|
896 |
JNIEXPORT jshort JNICALL |
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
18192
diff
changeset
|
897 |
Java_sun_nio_ch_Net_pollhupValue(JNIEnv *env, jclass this) |
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
18192
diff
changeset
|
898 |
{ |
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
18192
diff
changeset
|
899 |
return (jshort)POLLHUP; |
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
18192
diff
changeset
|
900 |
} |
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
18192
diff
changeset
|
901 |
|
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
18192
diff
changeset
|
902 |
JNIEXPORT jshort JNICALL |
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
18192
diff
changeset
|
903 |
Java_sun_nio_ch_Net_pollnvalValue(JNIEnv *env, jclass this) |
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
18192
diff
changeset
|
904 |
{ |
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
18192
diff
changeset
|
905 |
return (jshort)POLLNVAL; |
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
18192
diff
changeset
|
906 |
} |
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
18192
diff
changeset
|
907 |
|
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
18192
diff
changeset
|
908 |
JNIEXPORT jshort JNICALL |
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
18192
diff
changeset
|
909 |
Java_sun_nio_ch_Net_pollconnValue(JNIEnv *env, jclass this) |
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
18192
diff
changeset
|
910 |
{ |
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
18192
diff
changeset
|
911 |
return (jshort)POLLCONN; |
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
18192
diff
changeset
|
912 |
} |
53445
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
913 |
|
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
914 |
JNIEXPORT jint JNICALL |
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
915 |
Java_sun_nio_ch_Net_sendOOB(JNIEnv* env, jclass this, jobject fdo, jbyte b) |
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
916 |
{ |
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
917 |
int n = send(fdval(env, fdo), (const char*)&b, 1, MSG_OOB); |
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
918 |
if (n == SOCKET_ERROR) { |
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
919 |
if (WSAGetLastError() == WSAEWOULDBLOCK) { |
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
920 |
return IOS_UNAVAILABLE; |
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
921 |
} else { |
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
922 |
JNU_ThrowIOExceptionWithLastError(env, "send failed"); |
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
923 |
return IOS_THROWN; |
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
924 |
} |
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
925 |
} else { |
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
926 |
return n; |
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
927 |
} |
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
928 |
} |