author | mbaesken |
Wed, 09 Oct 2019 09:57:33 +0200 | |
changeset 58535 | ccb7bf459cbd |
parent 55753 | b9798272720b |
child 58679 | 9c3209ff7550 |
child 58801 | 119ac9128c1b |
child 59000 | 612c58965775 |
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:
52073
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 |
||
46862
cb4b080576fa
8180003: Remove sys/ prefix from poll.h and signal.h includes
mikael
parents:
43889
diff
changeset
|
26 |
#include <poll.h> |
2 | 27 |
#include <sys/types.h> |
28 |
#include <sys/socket.h> |
|
29 |
#include <string.h> |
|
30 |
#include <netinet/in.h> |
|
31 |
#include <netinet/tcp.h> |
|
32014
262d30f45454
8132652: Java_sun_nio_ch_Net_poll passes a long to an int
bpb
parents:
32006
diff
changeset
|
32 |
#include <limits.h> |
2 | 33 |
|
34 |
#include "jni.h" |
|
35 |
#include "jni_util.h" |
|
36 |
#include "jvm.h" |
|
37 |
#include "jlong.h" |
|
38 |
#include "sun_nio_ch_Net.h" |
|
39 |
#include "net_util.h" |
|
40 |
#include "net_util_md.h" |
|
41 |
#include "nio_util.h" |
|
42 |
#include "nio.h" |
|
43 |
||
22597
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
18535
diff
changeset
|
44 |
#ifdef _AIX |
55753
b9798272720b
8227737: avoid implicit-function-declaration on AIX
mbaesken
parents:
54627
diff
changeset
|
45 |
#include <stdlib.h> |
22597
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
18535
diff
changeset
|
46 |
#include <sys/utsname.h> |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
18535
diff
changeset
|
47 |
#endif |
18535
71b74ae0ab8a
8014377: (dc) DatagramChannel should set IP_MULTICAST_ALL=0 (lnx)
alanb
parents:
18192
diff
changeset
|
48 |
|
71b74ae0ab8a
8014377: (dc) DatagramChannel should set IP_MULTICAST_ALL=0 (lnx)
alanb
parents:
18192
diff
changeset
|
49 |
/** |
71b74ae0ab8a
8014377: (dc) DatagramChannel should set IP_MULTICAST_ALL=0 (lnx)
alanb
parents:
18192
diff
changeset
|
50 |
* IP_MULTICAST_ALL supported since 2.6.31 but may not be available at |
71b74ae0ab8a
8014377: (dc) DatagramChannel should set IP_MULTICAST_ALL=0 (lnx)
alanb
parents:
18192
diff
changeset
|
51 |
* build time. |
71b74ae0ab8a
8014377: (dc) DatagramChannel should set IP_MULTICAST_ALL=0 (lnx)
alanb
parents:
18192
diff
changeset
|
52 |
*/ |
71b74ae0ab8a
8014377: (dc) DatagramChannel should set IP_MULTICAST_ALL=0 (lnx)
alanb
parents:
18192
diff
changeset
|
53 |
#ifdef __linux__ |
71b74ae0ab8a
8014377: (dc) DatagramChannel should set IP_MULTICAST_ALL=0 (lnx)
alanb
parents:
18192
diff
changeset
|
54 |
#ifndef IP_MULTICAST_ALL |
22573
8f0344f13b7f
8032451: (dc) DatagramChannel.join should support include-mode filtering on OS X
alanb
parents:
18535
diff
changeset
|
55 |
#define IP_MULTICAST_ALL 49 |
18535
71b74ae0ab8a
8014377: (dc) DatagramChannel should set IP_MULTICAST_ALL=0 (lnx)
alanb
parents:
18192
diff
changeset
|
56 |
#endif |
71b74ae0ab8a
8014377: (dc) DatagramChannel should set IP_MULTICAST_ALL=0 (lnx)
alanb
parents:
18192
diff
changeset
|
57 |
#endif |
71b74ae0ab8a
8014377: (dc) DatagramChannel should set IP_MULTICAST_ALL=0 (lnx)
alanb
parents:
18192
diff
changeset
|
58 |
|
22573
8f0344f13b7f
8032451: (dc) DatagramChannel.join should support include-mode filtering on OS X
alanb
parents:
18535
diff
changeset
|
59 |
/** |
22607 | 60 |
* IPV6_ADD_MEMBERSHIP/IPV6_DROP_MEMBERSHIP may not be defined on OSX and AIX |
22573
8f0344f13b7f
8032451: (dc) DatagramChannel.join should support include-mode filtering on OS X
alanb
parents:
18535
diff
changeset
|
61 |
*/ |
22607 | 62 |
#if defined(__APPLE__) || defined(_AIX) |
22573
8f0344f13b7f
8032451: (dc) DatagramChannel.join should support include-mode filtering on OS X
alanb
parents:
18535
diff
changeset
|
63 |
#ifndef IPV6_ADD_MEMBERSHIP |
8f0344f13b7f
8032451: (dc) DatagramChannel.join should support include-mode filtering on OS X
alanb
parents:
18535
diff
changeset
|
64 |
#define IPV6_ADD_MEMBERSHIP IPV6_JOIN_GROUP |
8f0344f13b7f
8032451: (dc) DatagramChannel.join should support include-mode filtering on OS X
alanb
parents:
18535
diff
changeset
|
65 |
#define IPV6_DROP_MEMBERSHIP IPV6_LEAVE_GROUP |
18535
71b74ae0ab8a
8014377: (dc) DatagramChannel should set IP_MULTICAST_ALL=0 (lnx)
alanb
parents:
18192
diff
changeset
|
66 |
#endif |
71b74ae0ab8a
8014377: (dc) DatagramChannel should set IP_MULTICAST_ALL=0 (lnx)
alanb
parents:
18192
diff
changeset
|
67 |
#endif |
71b74ae0ab8a
8014377: (dc) DatagramChannel should set IP_MULTICAST_ALL=0 (lnx)
alanb
parents:
18192
diff
changeset
|
68 |
|
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
69 |
#define COPY_INET6_ADDRESS(env, source, target) \ |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
70 |
(*env)->GetByteArrayRegion(env, source, 0, 16, target) |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
71 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
72 |
/* |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
73 |
* Copy IPv6 group, interface index, and IPv6 source address |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
74 |
* into group_source_req structure. |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
75 |
*/ |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
76 |
static void initGroupSourceReq(JNIEnv* env, jbyteArray group, jint index, |
43889
212e765112d4
8174834: nio (ch): Remove #ifdef AF_INET6 guards in native coding
clanger
parents:
43100
diff
changeset
|
77 |
jbyteArray source, struct group_source_req *req) |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
78 |
{ |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
79 |
struct sockaddr_in6* sin6; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
80 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
81 |
req->gsr_interface = (uint32_t)index; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
82 |
|
43889
212e765112d4
8174834: nio (ch): Remove #ifdef AF_INET6 guards in native coding
clanger
parents:
43100
diff
changeset
|
83 |
sin6 = (struct sockaddr_in6 *)&(req->gsr_group); |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
84 |
sin6->sin6_family = AF_INET6; |
43889
212e765112d4
8174834: nio (ch): Remove #ifdef AF_INET6 guards in native coding
clanger
parents:
43100
diff
changeset
|
85 |
COPY_INET6_ADDRESS(env, group, (jbyte *)&(sin6->sin6_addr)); |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
86 |
|
43889
212e765112d4
8174834: nio (ch): Remove #ifdef AF_INET6 guards in native coding
clanger
parents:
43100
diff
changeset
|
87 |
sin6 = (struct sockaddr_in6 *)&(req->gsr_source); |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
88 |
sin6->sin6_family = AF_INET6; |
43889
212e765112d4
8174834: nio (ch): Remove #ifdef AF_INET6 guards in native coding
clanger
parents:
43100
diff
changeset
|
89 |
COPY_INET6_ADDRESS(env, source, (jbyte *)&(sin6->sin6_addr)); |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
90 |
} |
2 | 91 |
|
22597
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
18535
diff
changeset
|
92 |
#ifdef _AIX |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
18535
diff
changeset
|
93 |
|
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
18535
diff
changeset
|
94 |
/* |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
18535
diff
changeset
|
95 |
* Checks whether or not "socket extensions for multicast source filters" is supported. |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
18535
diff
changeset
|
96 |
* Returns JNI_TRUE if it is supported, JNI_FALSE otherwise |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
18535
diff
changeset
|
97 |
*/ |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
18535
diff
changeset
|
98 |
static jboolean isSourceFilterSupported(){ |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
18535
diff
changeset
|
99 |
static jboolean alreadyChecked = JNI_FALSE; |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
18535
diff
changeset
|
100 |
static jboolean result = JNI_TRUE; |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
18535
diff
changeset
|
101 |
if (alreadyChecked != JNI_TRUE){ |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
18535
diff
changeset
|
102 |
struct utsname uts; |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
18535
diff
changeset
|
103 |
memset(&uts, 0, sizeof(uts)); |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
18535
diff
changeset
|
104 |
strcpy(uts.sysname, "?"); |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
18535
diff
changeset
|
105 |
const int utsRes = uname(&uts); |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
18535
diff
changeset
|
106 |
int major = -1; |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
18535
diff
changeset
|
107 |
int minor = -1; |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
18535
diff
changeset
|
108 |
major = atoi(uts.version); |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
18535
diff
changeset
|
109 |
minor = atoi(uts.release); |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
18535
diff
changeset
|
110 |
if (strcmp(uts.sysname, "AIX") == 0) { |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
18535
diff
changeset
|
111 |
if (major < 6 || (major == 6 && minor < 1)) {// unsupported on aix < 6.1 |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
18535
diff
changeset
|
112 |
result = JNI_FALSE; |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
18535
diff
changeset
|
113 |
} |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
18535
diff
changeset
|
114 |
} |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
18535
diff
changeset
|
115 |
alreadyChecked = JNI_TRUE; |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
18535
diff
changeset
|
116 |
} |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
18535
diff
changeset
|
117 |
return result; |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
18535
diff
changeset
|
118 |
} |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
18535
diff
changeset
|
119 |
|
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
18535
diff
changeset
|
120 |
#endif /* _AIX */ |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
18535
diff
changeset
|
121 |
|
54154
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
122 |
static jclass isa_class; /* java.net.InetSocketAddress */ |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
123 |
static jmethodID isa_ctorID; /* InetSocketAddress(InetAddress, int) */ |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
124 |
|
2 | 125 |
JNIEXPORT void JNICALL |
126 |
Java_sun_nio_ch_Net_initIDs(JNIEnv *env, jclass clazz) |
|
127 |
{ |
|
54154
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
128 |
jclass cls = (*env)->FindClass(env, "java/net/InetSocketAddress"); |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
129 |
CHECK_NULL(cls); |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
130 |
isa_class = (*env)->NewGlobalRef(env, cls); |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
131 |
if (isa_class == NULL) { |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
132 |
JNU_ThrowOutOfMemoryError(env, NULL); |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
133 |
return; |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
134 |
} |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
135 |
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
|
136 |
CHECK_NULL(isa_ctorID); |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
137 |
|
26207
a02f6165d5be
8055955: (ch) Remove unnecessary initialization of InetAddress from FileChannel
chegar
parents:
25859
diff
changeset
|
138 |
initInetAddressIDs(env); |
2 | 139 |
} |
140 |
||
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
141 |
JNIEXPORT jboolean JNICALL |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
142 |
Java_sun_nio_ch_Net_isIPv6Available0(JNIEnv* env, jclass cl) |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
143 |
{ |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
144 |
return (ipv6_available()) ? JNI_TRUE : JNI_FALSE; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
145 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
146 |
|
36115 | 147 |
JNIEXPORT jboolean JNICALL |
148 |
Java_sun_nio_ch_Net_isReusePortAvailable0(JNIEnv* env, jclass c1) |
|
149 |
{ |
|
150 |
return (reuseport_available()) ? JNI_TRUE : JNI_FALSE; |
|
151 |
} |
|
152 |
||
18192 | 153 |
JNIEXPORT jint JNICALL |
154 |
Java_sun_nio_ch_Net_isExclusiveBindAvailable(JNIEnv *env, jclass clazz) { |
|
155 |
return -1; |
|
156 |
} |
|
157 |
||
8788
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
7668
diff
changeset
|
158 |
JNIEXPORT jboolean JNICALL |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
7668
diff
changeset
|
159 |
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
|
160 |
{ |
22607 | 161 |
#if defined(__APPLE__) || defined(_AIX) |
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
9035
diff
changeset
|
162 |
/* for now IPv6 sockets cannot join IPv4 multicast groups */ |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
9035
diff
changeset
|
163 |
return JNI_FALSE; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
9035
diff
changeset
|
164 |
#else |
8788
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
7668
diff
changeset
|
165 |
return JNI_TRUE; |
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
9035
diff
changeset
|
166 |
#endif |
8788
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
7668
diff
changeset
|
167 |
} |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
7668
diff
changeset
|
168 |
|
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
7668
diff
changeset
|
169 |
JNIEXPORT jboolean JNICALL |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
7668
diff
changeset
|
170 |
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
|
171 |
{ |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
7668
diff
changeset
|
172 |
#ifdef __solaris__ |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
7668
diff
changeset
|
173 |
return JNI_TRUE; |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
7668
diff
changeset
|
174 |
#else |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
7668
diff
changeset
|
175 |
return JNI_FALSE; |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
7668
diff
changeset
|
176 |
#endif |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
7668
diff
changeset
|
177 |
} |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
7668
diff
changeset
|
178 |
|
32006
97c6167e698a
8132505: Signature of Java_sun_nio_ch_Net_socket0 should return jint not int
bpb
parents:
27178
diff
changeset
|
179 |
JNIEXPORT jint JNICALL |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
180 |
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
|
181 |
jboolean stream, jboolean reuse, jboolean ignored) |
2 | 182 |
{ |
183 |
int fd; |
|
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
184 |
int type = (stream ? SOCK_STREAM : SOCK_DGRAM); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
185 |
int domain = (ipv6_available() && preferIPv6) ? AF_INET6 : AF_INET; |
2 | 186 |
|
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
187 |
fd = socket(domain, type, 0); |
2 | 188 |
if (fd < 0) { |
189 |
return handleSocketError(env, errno); |
|
190 |
} |
|
6299
a44d48dbcd50
6882910: Unexplained lack of IP4 network ability when transparent IP6 to IP4 is disabled.
chegar
parents:
5506
diff
changeset
|
191 |
|
54627
22323f20401b
8222562: Don't set IPV6_V6ONLY when IPv4 is not available
aeubanks
parents:
54246
diff
changeset
|
192 |
/* |
22323f20401b
8222562: Don't set IPV6_V6ONLY when IPv4 is not available
aeubanks
parents:
54246
diff
changeset
|
193 |
* If IPv4 is available, disable IPV6_V6ONLY to ensure dual-socket support. |
22323f20401b
8222562: Don't set IPV6_V6ONLY when IPv4 is not available
aeubanks
parents:
54246
diff
changeset
|
194 |
*/ |
22323f20401b
8222562: Don't set IPV6_V6ONLY when IPv4 is not available
aeubanks
parents:
54246
diff
changeset
|
195 |
if (domain == AF_INET6 && ipv4_available()) { |
6299
a44d48dbcd50
6882910: Unexplained lack of IP4 network ability when transparent IP6 to IP4 is disabled.
chegar
parents:
5506
diff
changeset
|
196 |
int arg = 0; |
a44d48dbcd50
6882910: Unexplained lack of IP4 network ability when transparent IP6 to IP4 is disabled.
chegar
parents:
5506
diff
changeset
|
197 |
if (setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, (char*)&arg, |
a44d48dbcd50
6882910: Unexplained lack of IP4 network ability when transparent IP6 to IP4 is disabled.
chegar
parents:
5506
diff
changeset
|
198 |
sizeof(int)) < 0) { |
a44d48dbcd50
6882910: Unexplained lack of IP4 network ability when transparent IP6 to IP4 is disabled.
chegar
parents:
5506
diff
changeset
|
199 |
JNU_ThrowByNameWithLastError(env, |
a44d48dbcd50
6882910: Unexplained lack of IP4 network ability when transparent IP6 to IP4 is disabled.
chegar
parents:
5506
diff
changeset
|
200 |
JNU_JAVANETPKG "SocketException", |
18535
71b74ae0ab8a
8014377: (dc) DatagramChannel should set IP_MULTICAST_ALL=0 (lnx)
alanb
parents:
18192
diff
changeset
|
201 |
"Unable to set IPV6_V6ONLY"); |
6299
a44d48dbcd50
6882910: Unexplained lack of IP4 network ability when transparent IP6 to IP4 is disabled.
chegar
parents:
5506
diff
changeset
|
202 |
close(fd); |
a44d48dbcd50
6882910: Unexplained lack of IP4 network ability when transparent IP6 to IP4 is disabled.
chegar
parents:
5506
diff
changeset
|
203 |
return -1; |
a44d48dbcd50
6882910: Unexplained lack of IP4 network ability when transparent IP6 to IP4 is disabled.
chegar
parents:
5506
diff
changeset
|
204 |
} |
a44d48dbcd50
6882910: Unexplained lack of IP4 network ability when transparent IP6 to IP4 is disabled.
chegar
parents:
5506
diff
changeset
|
205 |
} |
a44d48dbcd50
6882910: Unexplained lack of IP4 network ability when transparent IP6 to IP4 is disabled.
chegar
parents:
5506
diff
changeset
|
206 |
|
2 | 207 |
if (reuse) { |
208 |
int arg = 1; |
|
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
209 |
if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char*)&arg, |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
210 |
sizeof(arg)) < 0) { |
2 | 211 |
JNU_ThrowByNameWithLastError(env, |
212 |
JNU_JAVANETPKG "SocketException", |
|
18535
71b74ae0ab8a
8014377: (dc) DatagramChannel should set IP_MULTICAST_ALL=0 (lnx)
alanb
parents:
18192
diff
changeset
|
213 |
"Unable to set SO_REUSEADDR"); |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
214 |
close(fd); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
215 |
return -1; |
2 | 216 |
} |
217 |
} |
|
18535
71b74ae0ab8a
8014377: (dc) DatagramChannel should set IP_MULTICAST_ALL=0 (lnx)
alanb
parents:
18192
diff
changeset
|
218 |
|
71b74ae0ab8a
8014377: (dc) DatagramChannel should set IP_MULTICAST_ALL=0 (lnx)
alanb
parents:
18192
diff
changeset
|
219 |
#if defined(__linux__) |
71b74ae0ab8a
8014377: (dc) DatagramChannel should set IP_MULTICAST_ALL=0 (lnx)
alanb
parents:
18192
diff
changeset
|
220 |
if (type == SOCK_DGRAM) { |
71b74ae0ab8a
8014377: (dc) DatagramChannel should set IP_MULTICAST_ALL=0 (lnx)
alanb
parents:
18192
diff
changeset
|
221 |
int arg = 0; |
71b74ae0ab8a
8014377: (dc) DatagramChannel should set IP_MULTICAST_ALL=0 (lnx)
alanb
parents:
18192
diff
changeset
|
222 |
int level = (domain == AF_INET6) ? IPPROTO_IPV6 : IPPROTO_IP; |
71b74ae0ab8a
8014377: (dc) DatagramChannel should set IP_MULTICAST_ALL=0 (lnx)
alanb
parents:
18192
diff
changeset
|
223 |
if ((setsockopt(fd, level, IP_MULTICAST_ALL, (char*)&arg, sizeof(arg)) < 0) && |
71b74ae0ab8a
8014377: (dc) DatagramChannel should set IP_MULTICAST_ALL=0 (lnx)
alanb
parents:
18192
diff
changeset
|
224 |
(errno != ENOPROTOOPT)) { |
71b74ae0ab8a
8014377: (dc) DatagramChannel should set IP_MULTICAST_ALL=0 (lnx)
alanb
parents:
18192
diff
changeset
|
225 |
JNU_ThrowByNameWithLastError(env, |
71b74ae0ab8a
8014377: (dc) DatagramChannel should set IP_MULTICAST_ALL=0 (lnx)
alanb
parents:
18192
diff
changeset
|
226 |
JNU_JAVANETPKG "SocketException", |
71b74ae0ab8a
8014377: (dc) DatagramChannel should set IP_MULTICAST_ALL=0 (lnx)
alanb
parents:
18192
diff
changeset
|
227 |
"Unable to set IP_MULTICAST_ALL"); |
71b74ae0ab8a
8014377: (dc) DatagramChannel should set IP_MULTICAST_ALL=0 (lnx)
alanb
parents:
18192
diff
changeset
|
228 |
close(fd); |
71b74ae0ab8a
8014377: (dc) DatagramChannel should set IP_MULTICAST_ALL=0 (lnx)
alanb
parents:
18192
diff
changeset
|
229 |
return -1; |
71b74ae0ab8a
8014377: (dc) DatagramChannel should set IP_MULTICAST_ALL=0 (lnx)
alanb
parents:
18192
diff
changeset
|
230 |
} |
71b74ae0ab8a
8014377: (dc) DatagramChannel should set IP_MULTICAST_ALL=0 (lnx)
alanb
parents:
18192
diff
changeset
|
231 |
} |
71b74ae0ab8a
8014377: (dc) DatagramChannel should set IP_MULTICAST_ALL=0 (lnx)
alanb
parents:
18192
diff
changeset
|
232 |
|
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
233 |
/* By default, Linux uses the route default */ |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
234 |
if (domain == AF_INET6 && type == SOCK_DGRAM) { |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
235 |
int arg = 1; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
236 |
if (setsockopt(fd, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, &arg, |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
237 |
sizeof(arg)) < 0) { |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
238 |
JNU_ThrowByNameWithLastError(env, |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
239 |
JNU_JAVANETPKG "SocketException", |
18535
71b74ae0ab8a
8014377: (dc) DatagramChannel should set IP_MULTICAST_ALL=0 (lnx)
alanb
parents:
18192
diff
changeset
|
240 |
"Unable to set IPV6_MULTICAST_HOPS"); |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
241 |
close(fd); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
242 |
return -1; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
243 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
244 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
245 |
#endif |
2 | 246 |
return fd; |
247 |
} |
|
248 |
||
249 |
JNIEXPORT void JNICALL |
|
18192 | 250 |
Java_sun_nio_ch_Net_bind0(JNIEnv *env, jclass clazz, jobject fdo, jboolean preferIPv6, |
251 |
jboolean useExclBind, jobject iao, int port) |
|
2 | 252 |
{ |
41380
c27cf95dd7e6
8167295: Further cleanup to the native parts of libnet/libnio
clanger
parents:
36115
diff
changeset
|
253 |
SOCKETADDRESS sa; |
43100 | 254 |
int sa_len = 0; |
2 | 255 |
int rv = 0; |
256 |
||
43100 | 257 |
if (NET_InetAddressToSockaddr(env, iao, port, &sa, &sa_len, |
41380
c27cf95dd7e6
8167295: Further cleanup to the native parts of libnet/libnio
clanger
parents:
36115
diff
changeset
|
258 |
preferIPv6) != 0) { |
c27cf95dd7e6
8167295: Further cleanup to the native parts of libnet/libnio
clanger
parents:
36115
diff
changeset
|
259 |
return; |
2 | 260 |
} |
261 |
||
43100 | 262 |
rv = NET_Bind(fdval(env, fdo), &sa, sa_len); |
2 | 263 |
if (rv != 0) { |
264 |
handleSocketError(env, errno); |
|
265 |
} |
|
266 |
} |
|
267 |
||
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
268 |
JNIEXPORT void JNICALL |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
269 |
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:
895
diff
changeset
|
270 |
{ |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
271 |
if (listen(fdval(env, fdo), backlog) < 0) |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
272 |
handleSocketError(env, errno); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
273 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
274 |
|
2 | 275 |
JNIEXPORT jint JNICALL |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
276 |
Java_sun_nio_ch_Net_connect0(JNIEnv *env, jclass clazz, jboolean preferIPv6, |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
277 |
jobject fdo, jobject iao, jint port) |
2 | 278 |
{ |
41380
c27cf95dd7e6
8167295: Further cleanup to the native parts of libnet/libnio
clanger
parents:
36115
diff
changeset
|
279 |
SOCKETADDRESS sa; |
43100 | 280 |
int sa_len = 0; |
2 | 281 |
int rv; |
282 |
||
49141
ac95c7a76132
8198928: (so) SocketChannel connect may deadlock if closed at around same time that connect fails
alanb
parents:
47216
diff
changeset
|
283 |
if (NET_InetAddressToSockaddr(env, iao, port, &sa, &sa_len, preferIPv6) != 0) { |
41380
c27cf95dd7e6
8167295: Further cleanup to the native parts of libnet/libnio
clanger
parents:
36115
diff
changeset
|
284 |
return IOS_THROWN; |
2 | 285 |
} |
286 |
||
41380
c27cf95dd7e6
8167295: Further cleanup to the native parts of libnet/libnio
clanger
parents:
36115
diff
changeset
|
287 |
rv = connect(fdval(env, fdo), &sa.sa, sa_len); |
2 | 288 |
if (rv != 0) { |
289 |
if (errno == EINPROGRESS) { |
|
290 |
return IOS_UNAVAILABLE; |
|
291 |
} else if (errno == EINTR) { |
|
292 |
return IOS_INTERRUPTED; |
|
293 |
} |
|
294 |
return handleSocketError(env, errno); |
|
295 |
} |
|
296 |
return 1; |
|
297 |
} |
|
298 |
||
299 |
JNIEXPORT jint JNICALL |
|
54154
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
300 |
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
|
301 |
jobjectArray isaa) |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
302 |
{ |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
303 |
jint fd = fdval(env, fdo); |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
304 |
jint newfd; |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
305 |
SOCKETADDRESS sa; |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
306 |
socklen_t sa_len = sizeof(SOCKETADDRESS); |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
307 |
jobject remote_ia; |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
308 |
jint remote_port = 0; |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
309 |
jobject isa; |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
310 |
|
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
311 |
/* accept connection but ignore ECONNABORTED */ |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
312 |
for (;;) { |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
313 |
newfd = accept(fd, &sa.sa, &sa_len); |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
314 |
if (newfd >= 0) { |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
315 |
break; |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
316 |
} |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
317 |
if (errno != ECONNABORTED) { |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
318 |
break; |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
319 |
} |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
320 |
/* ECONNABORTED => restart accept */ |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
321 |
} |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
322 |
|
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
323 |
if (newfd < 0) { |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
324 |
if (errno == EAGAIN || errno == EWOULDBLOCK) |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
325 |
return IOS_UNAVAILABLE; |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
326 |
if (errno == EINTR) |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
327 |
return IOS_INTERRUPTED; |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
328 |
JNU_ThrowIOExceptionWithLastError(env, "Accept failed"); |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
329 |
return IOS_THROWN; |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
330 |
} |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
331 |
|
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
332 |
setfdval(env, newfdo, newfd); |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
333 |
|
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
334 |
remote_ia = NET_SockaddrToInetAddress(env, &sa, (int *)&remote_port); |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
335 |
CHECK_NULL_RETURN(remote_ia, IOS_THROWN); |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
336 |
|
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
337 |
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
|
338 |
CHECK_NULL_RETURN(isa, IOS_THROWN); |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
339 |
(*env)->SetObjectArrayElement(env, isaa, 0, isa); |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
340 |
|
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
341 |
return 1; |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
342 |
} |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
343 |
|
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
344 |
JNIEXPORT jint JNICALL |
2 | 345 |
Java_sun_nio_ch_Net_localPort(JNIEnv *env, jclass clazz, jobject fdo) |
346 |
{ |
|
41380
c27cf95dd7e6
8167295: Further cleanup to the native parts of libnet/libnio
clanger
parents:
36115
diff
changeset
|
347 |
SOCKETADDRESS sa; |
c27cf95dd7e6
8167295: Further cleanup to the native parts of libnet/libnio
clanger
parents:
36115
diff
changeset
|
348 |
socklen_t sa_len = sizeof(SOCKETADDRESS); |
c27cf95dd7e6
8167295: Further cleanup to the native parts of libnet/libnio
clanger
parents:
36115
diff
changeset
|
349 |
if (getsockname(fdval(env, fdo), &sa.sa, &sa_len) < 0) { |
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
9035
diff
changeset
|
350 |
#ifdef _ALLBSD_SOURCE |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
9035
diff
changeset
|
351 |
/* |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
9035
diff
changeset
|
352 |
* XXXBSD: |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
9035
diff
changeset
|
353 |
* ECONNRESET is specific to the BSDs. We can not return an error, |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
9035
diff
changeset
|
354 |
* as the calling Java code with raise a java.lang.Error given the expectation |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
9035
diff
changeset
|
355 |
* that getsockname() will never fail. According to the Single UNIX Specification, |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
9035
diff
changeset
|
356 |
* it shouldn't fail. As such, we just fill in generic Linux-compatible values. |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
9035
diff
changeset
|
357 |
*/ |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
9035
diff
changeset
|
358 |
if (errno == ECONNRESET) { |
41380
c27cf95dd7e6
8167295: Further cleanup to the native parts of libnet/libnio
clanger
parents:
36115
diff
changeset
|
359 |
bzero(&sa.sa4, sizeof(sa)); |
c27cf95dd7e6
8167295: Further cleanup to the native parts of libnet/libnio
clanger
parents:
36115
diff
changeset
|
360 |
sa.sa4.sin_len = sizeof(struct sockaddr_in); |
c27cf95dd7e6
8167295: Further cleanup to the native parts of libnet/libnio
clanger
parents:
36115
diff
changeset
|
361 |
sa.sa4.sin_family = AF_INET; |
c27cf95dd7e6
8167295: Further cleanup to the native parts of libnet/libnio
clanger
parents:
36115
diff
changeset
|
362 |
sa.sa4.sin_port = htonl(0); |
c27cf95dd7e6
8167295: Further cleanup to the native parts of libnet/libnio
clanger
parents:
36115
diff
changeset
|
363 |
sa.sa4.sin_addr.s_addr = INADDR_ANY; |
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
9035
diff
changeset
|
364 |
} else { |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
9035
diff
changeset
|
365 |
handleSocketError(env, errno); |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
9035
diff
changeset
|
366 |
return -1; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
9035
diff
changeset
|
367 |
} |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
9035
diff
changeset
|
368 |
#else /* _ALLBSD_SOURCE */ |
2 | 369 |
handleSocketError(env, errno); |
370 |
return -1; |
|
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
9035
diff
changeset
|
371 |
#endif /* _ALLBSD_SOURCE */ |
2 | 372 |
} |
43100 | 373 |
return NET_GetPortFromSockaddr(&sa); |
2 | 374 |
} |
375 |
||
376 |
JNIEXPORT jobject JNICALL |
|
377 |
Java_sun_nio_ch_Net_localInetAddress(JNIEnv *env, jclass clazz, jobject fdo) |
|
378 |
{ |
|
41380
c27cf95dd7e6
8167295: Further cleanup to the native parts of libnet/libnio
clanger
parents:
36115
diff
changeset
|
379 |
SOCKETADDRESS sa; |
c27cf95dd7e6
8167295: Further cleanup to the native parts of libnet/libnio
clanger
parents:
36115
diff
changeset
|
380 |
socklen_t sa_len = sizeof(SOCKETADDRESS); |
2 | 381 |
int port; |
41380
c27cf95dd7e6
8167295: Further cleanup to the native parts of libnet/libnio
clanger
parents:
36115
diff
changeset
|
382 |
if (getsockname(fdval(env, fdo), &sa.sa, &sa_len) < 0) { |
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
9035
diff
changeset
|
383 |
#ifdef _ALLBSD_SOURCE |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
9035
diff
changeset
|
384 |
/* |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
9035
diff
changeset
|
385 |
* XXXBSD: |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
9035
diff
changeset
|
386 |
* ECONNRESET is specific to the BSDs. We can not return an error, |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
9035
diff
changeset
|
387 |
* as the calling Java code with raise a java.lang.Error with the expectation |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
9035
diff
changeset
|
388 |
* that getsockname() will never fail. According to the Single UNIX Specification, |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
9035
diff
changeset
|
389 |
* it shouldn't fail. As such, we just fill in generic Linux-compatible values. |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
9035
diff
changeset
|
390 |
*/ |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
9035
diff
changeset
|
391 |
if (errno == ECONNRESET) { |
41380
c27cf95dd7e6
8167295: Further cleanup to the native parts of libnet/libnio
clanger
parents:
36115
diff
changeset
|
392 |
bzero(&sa.sa4, sizeof(sa)); |
c27cf95dd7e6
8167295: Further cleanup to the native parts of libnet/libnio
clanger
parents:
36115
diff
changeset
|
393 |
sa.sa4.sin_len = sizeof(struct sockaddr_in); |
c27cf95dd7e6
8167295: Further cleanup to the native parts of libnet/libnio
clanger
parents:
36115
diff
changeset
|
394 |
sa.sa4.sin_family = AF_INET; |
c27cf95dd7e6
8167295: Further cleanup to the native parts of libnet/libnio
clanger
parents:
36115
diff
changeset
|
395 |
sa.sa4.sin_port = htonl(0); |
c27cf95dd7e6
8167295: Further cleanup to the native parts of libnet/libnio
clanger
parents:
36115
diff
changeset
|
396 |
sa.sa4.sin_addr.s_addr = INADDR_ANY; |
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
9035
diff
changeset
|
397 |
} else { |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
9035
diff
changeset
|
398 |
handleSocketError(env, errno); |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
9035
diff
changeset
|
399 |
return NULL; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
9035
diff
changeset
|
400 |
} |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
9035
diff
changeset
|
401 |
#else /* _ALLBSD_SOURCE */ |
2 | 402 |
handleSocketError(env, errno); |
403 |
return NULL; |
|
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
9035
diff
changeset
|
404 |
#endif /* _ALLBSD_SOURCE */ |
2 | 405 |
} |
43100 | 406 |
return NET_SockaddrToInetAddress(env, &sa, &port); |
2 | 407 |
} |
408 |
||
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
409 |
JNIEXPORT jint JNICALL |
54154
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
410 |
Java_sun_nio_ch_Net_remotePort(JNIEnv *env, jclass clazz, jobject fdo) |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
411 |
{ |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
412 |
SOCKETADDRESS sa; |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
413 |
socklen_t sa_len = sizeof(sa); |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
414 |
|
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
415 |
if (getpeername(fdval(env, fdo), &sa.sa, &sa_len) < 0) { |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
416 |
handleSocketError(env, errno); |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
417 |
return IOS_THROWN; |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
418 |
} |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
419 |
return NET_GetPortFromSockaddr(&sa); |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
420 |
} |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
421 |
|
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
422 |
JNIEXPORT jobject JNICALL |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
423 |
Java_sun_nio_ch_Net_remoteInetAddress(JNIEnv *env, jclass clazz, jobject fdo) |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
424 |
{ |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
425 |
SOCKETADDRESS sa; |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
426 |
socklen_t sa_len = sizeof(sa); |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
427 |
int port; |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
428 |
|
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
429 |
if (getpeername(fdval(env, fdo), &sa.sa, &sa_len) < 0) { |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
430 |
handleSocketError(env, errno); |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
431 |
return NULL; |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
432 |
} |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
433 |
return NET_SockaddrToInetAddress(env, &sa, &port); |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
434 |
} |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
435 |
|
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
436 |
JNIEXPORT jint JNICALL |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
437 |
Java_sun_nio_ch_Net_getIntOption0(JNIEnv *env, jclass clazz, jobject fdo, |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
438 |
jboolean mayNeedConversion, jint level, jint opt) |
2 | 439 |
{ |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
440 |
int result; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
441 |
struct linger linger; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
442 |
u_char carg; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
443 |
void *arg; |
6850
56966b0a6a0d
6989466: Miscellaneous compiler warnings in java/lang, java/util, java/io, sun/misc native code
alanb
parents:
6299
diff
changeset
|
444 |
socklen_t arglen; |
56966b0a6a0d
6989466: Miscellaneous compiler warnings in java/lang, java/util, java/io, sun/misc native code
alanb
parents:
6299
diff
changeset
|
445 |
int n; |
2 | 446 |
|
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
447 |
/* Option value is an int except for a few specific cases */ |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
448 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
449 |
arg = (void *)&result; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
450 |
arglen = sizeof(result); |
2 | 451 |
|
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
452 |
if (level == IPPROTO_IP && |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
453 |
(opt == IP_MULTICAST_TTL || opt == IP_MULTICAST_LOOP)) { |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
454 |
arg = (void*)&carg; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
455 |
arglen = sizeof(carg); |
2 | 456 |
} |
457 |
||
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
458 |
if (level == SOL_SOCKET && opt == SO_LINGER) { |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
459 |
arg = (void *)&linger; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
460 |
arglen = sizeof(linger); |
2 | 461 |
} |
462 |
||
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
463 |
if (mayNeedConversion) { |
6850
56966b0a6a0d
6989466: Miscellaneous compiler warnings in java/lang, java/util, java/io, sun/misc native code
alanb
parents:
6299
diff
changeset
|
464 |
n = NET_GetSockOpt(fdval(env, fdo), level, opt, arg, (int*)&arglen); |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
465 |
} else { |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
466 |
n = getsockopt(fdval(env, fdo), level, opt, arg, &arglen); |
2 | 467 |
} |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
468 |
if (n < 0) { |
2 | 469 |
JNU_ThrowByNameWithLastError(env, |
470 |
JNU_JAVANETPKG "SocketException", |
|
471 |
"sun.nio.ch.Net.getIntOption"); |
|
472 |
return -1; |
|
473 |
} |
|
474 |
||
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
475 |
if (level == IPPROTO_IP && |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
476 |
(opt == IP_MULTICAST_TTL || opt == IP_MULTICAST_LOOP)) |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
477 |
{ |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
478 |
return (jint)carg; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
479 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
480 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
481 |
if (level == SOL_SOCKET && opt == SO_LINGER) |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
482 |
return linger.l_onoff ? (jint)linger.l_linger : (jint)-1; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
483 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
484 |
return (jint)result; |
2 | 485 |
} |
486 |
||
487 |
JNIEXPORT void JNICALL |
|
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
488 |
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:
23016
diff
changeset
|
489 |
jboolean mayNeedConversion, jint level, |
f58832169add
8029607: Type of Service (TOS) cannot be set in IPv6 header
michaelm
parents:
23016
diff
changeset
|
490 |
jint opt, jint arg, jboolean isIPv6) |
2 | 491 |
{ |
492 |
int result; |
|
493 |
struct linger linger; |
|
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
494 |
u_char carg; |
2 | 495 |
void *parg; |
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
9035
diff
changeset
|
496 |
socklen_t arglen; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
9035
diff
changeset
|
497 |
int n; |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
498 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
499 |
/* Option value is an int except for a few specific cases */ |
2 | 500 |
|
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
501 |
parg = (void*)&arg; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
502 |
arglen = sizeof(arg); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
503 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
504 |
if (level == IPPROTO_IP && |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
505 |
(opt == IP_MULTICAST_TTL || opt == IP_MULTICAST_LOOP)) { |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
506 |
parg = (void*)&carg; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
507 |
arglen = sizeof(carg); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
508 |
carg = (u_char)arg; |
2 | 509 |
} |
510 |
||
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
511 |
if (level == SOL_SOCKET && opt == SO_LINGER) { |
2 | 512 |
parg = (void *)&linger; |
513 |
arglen = sizeof(linger); |
|
514 |
if (arg >= 0) { |
|
515 |
linger.l_onoff = 1; |
|
516 |
linger.l_linger = arg; |
|
517 |
} else { |
|
518 |
linger.l_onoff = 0; |
|
519 |
linger.l_linger = 0; |
|
520 |
} |
|
521 |
} |
|
522 |
||
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
523 |
if (mayNeedConversion) { |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
524 |
n = NET_SetSockOpt(fdval(env, fdo), level, opt, parg, arglen); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
525 |
} else { |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
526 |
n = setsockopt(fdval(env, fdo), level, opt, parg, arglen); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
527 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
528 |
if (n < 0) { |
2 | 529 |
JNU_ThrowByNameWithLastError(env, |
530 |
JNU_JAVANETPKG "SocketException", |
|
531 |
"sun.nio.ch.Net.setIntOption"); |
|
532 |
} |
|
25170
f58832169add
8029607: Type of Service (TOS) cannot be set in IPv6 header
michaelm
parents:
23016
diff
changeset
|
533 |
#ifdef __linux__ |
f58832169add
8029607: Type of Service (TOS) cannot be set in IPv6 header
michaelm
parents:
23016
diff
changeset
|
534 |
if (level == IPPROTO_IPV6 && opt == IPV6_TCLASS && isIPv6) { |
f58832169add
8029607: Type of Service (TOS) cannot be set in IPv6 header
michaelm
parents:
23016
diff
changeset
|
535 |
// set the V4 option also |
f58832169add
8029607: Type of Service (TOS) cannot be set in IPv6 header
michaelm
parents:
23016
diff
changeset
|
536 |
setsockopt(fdval(env, fdo), IPPROTO_IP, IP_TOS, parg, arglen); |
f58832169add
8029607: Type of Service (TOS) cannot be set in IPv6 header
michaelm
parents:
23016
diff
changeset
|
537 |
} |
f58832169add
8029607: Type of Service (TOS) cannot be set in IPv6 header
michaelm
parents:
23016
diff
changeset
|
538 |
#endif |
2 | 539 |
} |
540 |
||
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
541 |
JNIEXPORT jint JNICALL |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
542 |
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:
895
diff
changeset
|
543 |
jint group, jint interf, jint source) |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
544 |
{ |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
545 |
struct ip_mreq mreq; |
22573
8f0344f13b7f
8032451: (dc) DatagramChannel.join should support include-mode filtering on OS X
alanb
parents:
18535
diff
changeset
|
546 |
struct ip_mreq_source mreq_source; |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
547 |
int opt, n, optlen; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
548 |
void* optval; |
2 | 549 |
|
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
550 |
if (source == 0) { |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
551 |
mreq.imr_multiaddr.s_addr = htonl(group); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
552 |
mreq.imr_interface.s_addr = htonl(interf); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
553 |
opt = (join) ? IP_ADD_MEMBERSHIP : IP_DROP_MEMBERSHIP; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
554 |
optval = (void*)&mreq; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
555 |
optlen = sizeof(mreq); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
556 |
} else { |
22597
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
18535
diff
changeset
|
557 |
|
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
18535
diff
changeset
|
558 |
#ifdef _AIX |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
18535
diff
changeset
|
559 |
/* check AIX for support of source filtering */ |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
18535
diff
changeset
|
560 |
if (isSourceFilterSupported() != JNI_TRUE){ |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
18535
diff
changeset
|
561 |
return IOS_UNAVAILABLE; |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
18535
diff
changeset
|
562 |
} |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
18535
diff
changeset
|
563 |
#endif |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
18535
diff
changeset
|
564 |
|
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
565 |
mreq_source.imr_multiaddr.s_addr = htonl(group); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
566 |
mreq_source.imr_sourceaddr.s_addr = htonl(source); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
567 |
mreq_source.imr_interface.s_addr = htonl(interf); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
568 |
opt = (join) ? IP_ADD_SOURCE_MEMBERSHIP : IP_DROP_SOURCE_MEMBERSHIP; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
569 |
optval = (void*)&mreq_source; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
570 |
optlen = sizeof(mreq_source); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
571 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
572 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
573 |
n = setsockopt(fdval(env,fdo), IPPROTO_IP, opt, optval, optlen); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
574 |
if (n < 0) { |
22597
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
18535
diff
changeset
|
575 |
if (join && (errno == ENOPROTOOPT || errno == EOPNOTSUPP)) |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
576 |
return IOS_UNAVAILABLE; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
577 |
handleSocketError(env, errno); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
578 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
579 |
return 0; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
580 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
581 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
582 |
JNIEXPORT jint JNICALL |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
583 |
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:
895
diff
changeset
|
584 |
jint group, jint interf, jint source) |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
585 |
{ |
22573
8f0344f13b7f
8032451: (dc) DatagramChannel.join should support include-mode filtering on OS X
alanb
parents:
18535
diff
changeset
|
586 |
#ifdef __APPLE__ |
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
9035
diff
changeset
|
587 |
/* no IPv4 exclude-mode filtering for now */ |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
9035
diff
changeset
|
588 |
return IOS_UNAVAILABLE; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
9035
diff
changeset
|
589 |
#else |
22573
8f0344f13b7f
8032451: (dc) DatagramChannel.join should support include-mode filtering on OS X
alanb
parents:
18535
diff
changeset
|
590 |
struct ip_mreq_source mreq_source; |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
591 |
int n; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
592 |
int opt = (block) ? IP_BLOCK_SOURCE : IP_UNBLOCK_SOURCE; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
593 |
|
22597
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
18535
diff
changeset
|
594 |
#ifdef _AIX |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
18535
diff
changeset
|
595 |
/* check AIX for support of source filtering */ |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
18535
diff
changeset
|
596 |
if (isSourceFilterSupported() != JNI_TRUE){ |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
18535
diff
changeset
|
597 |
return IOS_UNAVAILABLE; |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
18535
diff
changeset
|
598 |
} |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
18535
diff
changeset
|
599 |
#endif |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
18535
diff
changeset
|
600 |
|
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
601 |
mreq_source.imr_multiaddr.s_addr = htonl(group); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
602 |
mreq_source.imr_sourceaddr.s_addr = htonl(source); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
603 |
mreq_source.imr_interface.s_addr = htonl(interf); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
604 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
605 |
n = setsockopt(fdval(env,fdo), IPPROTO_IP, opt, |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
606 |
(void*)&mreq_source, sizeof(mreq_source)); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
607 |
if (n < 0) { |
22597
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
18535
diff
changeset
|
608 |
if (block && (errno == ENOPROTOOPT || errno == EOPNOTSUPP)) |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
609 |
return IOS_UNAVAILABLE; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
610 |
handleSocketError(env, errno); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
611 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
612 |
return 0; |
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
9035
diff
changeset
|
613 |
#endif |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
614 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
615 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
616 |
JNIEXPORT jint JNICALL |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
617 |
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:
895
diff
changeset
|
618 |
jbyteArray group, jint index, jbyteArray source) |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
619 |
{ |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
620 |
struct ipv6_mreq mreq6; |
22573
8f0344f13b7f
8032451: (dc) DatagramChannel.join should support include-mode filtering on OS X
alanb
parents:
18535
diff
changeset
|
621 |
struct group_source_req req; |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
622 |
int opt, n, optlen; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
623 |
void* optval; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
624 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
625 |
if (source == NULL) { |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
626 |
COPY_INET6_ADDRESS(env, group, (jbyte*)&(mreq6.ipv6mr_multiaddr)); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
627 |
mreq6.ipv6mr_interface = (int)index; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
628 |
opt = (join) ? IPV6_ADD_MEMBERSHIP : IPV6_DROP_MEMBERSHIP; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
629 |
optval = (void*)&mreq6; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
630 |
optlen = sizeof(mreq6); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
631 |
} else { |
22573
8f0344f13b7f
8032451: (dc) DatagramChannel.join should support include-mode filtering on OS X
alanb
parents:
18535
diff
changeset
|
632 |
#ifdef __APPLE__ |
13363
065e0e3545a3
6633549: (dc) Include-mode filtering of IPv6 sources does not block datagrams on Linux
alanb
parents:
12047
diff
changeset
|
633 |
/* no IPv6 include-mode filtering for now */ |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
634 |
return IOS_UNAVAILABLE; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
635 |
#else |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
636 |
initGroupSourceReq(env, group, index, source, &req); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
637 |
opt = (join) ? MCAST_JOIN_SOURCE_GROUP : MCAST_LEAVE_SOURCE_GROUP; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
638 |
optval = (void*)&req; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
639 |
optlen = sizeof(req); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
640 |
#endif |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
641 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
642 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
643 |
n = setsockopt(fdval(env,fdo), IPPROTO_IPV6, opt, optval, optlen); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
644 |
if (n < 0) { |
22597
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
18535
diff
changeset
|
645 |
if (join && (errno == ENOPROTOOPT || errno == EOPNOTSUPP)) |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
646 |
return IOS_UNAVAILABLE; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
647 |
handleSocketError(env, errno); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
648 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
649 |
return 0; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
650 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
651 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
652 |
JNIEXPORT jint JNICALL |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
653 |
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:
895
diff
changeset
|
654 |
jbyteArray group, jint index, jbyteArray source) |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
655 |
{ |
43889
212e765112d4
8174834: nio (ch): Remove #ifdef AF_INET6 guards in native coding
clanger
parents:
43100
diff
changeset
|
656 |
#ifdef __APPLE__ |
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
9035
diff
changeset
|
657 |
/* no IPv6 exclude-mode filtering for now */ |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
9035
diff
changeset
|
658 |
return IOS_UNAVAILABLE; |
43889
212e765112d4
8174834: nio (ch): Remove #ifdef AF_INET6 guards in native coding
clanger
parents:
43100
diff
changeset
|
659 |
#else |
22573
8f0344f13b7f
8032451: (dc) DatagramChannel.join should support include-mode filtering on OS X
alanb
parents:
18535
diff
changeset
|
660 |
struct group_source_req req; |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
661 |
int n; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
662 |
int opt = (block) ? MCAST_BLOCK_SOURCE : MCAST_UNBLOCK_SOURCE; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
663 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
664 |
initGroupSourceReq(env, group, index, source, &req); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
665 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
666 |
n = setsockopt(fdval(env,fdo), IPPROTO_IPV6, opt, |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
667 |
(void*)&req, sizeof(req)); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
668 |
if (n < 0) { |
22597
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
18535
diff
changeset
|
669 |
if (block && (errno == ENOPROTOOPT || errno == EOPNOTSUPP)) |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
670 |
return IOS_UNAVAILABLE; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
671 |
handleSocketError(env, errno); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
672 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
673 |
return 0; |
4814 | 674 |
#endif |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
675 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
676 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
677 |
JNIEXPORT void JNICALL |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
678 |
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:
895
diff
changeset
|
679 |
{ |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
680 |
struct in_addr in; |
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
9035
diff
changeset
|
681 |
socklen_t arglen = sizeof(struct in_addr); |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
682 |
int n; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
683 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
684 |
in.s_addr = htonl(interf); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
685 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
686 |
n = setsockopt(fdval(env, fdo), IPPROTO_IP, IP_MULTICAST_IF, |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
687 |
(void*)&(in.s_addr), arglen); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
688 |
if (n < 0) { |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
689 |
handleSocketError(env, errno); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
690 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
691 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
692 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
693 |
JNIEXPORT jint JNICALL |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
694 |
Java_sun_nio_ch_Net_getInterface4(JNIEnv* env, jobject this, jobject fdo) |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
695 |
{ |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
696 |
struct in_addr in; |
6850
56966b0a6a0d
6989466: Miscellaneous compiler warnings in java/lang, java/util, java/io, sun/misc native code
alanb
parents:
6299
diff
changeset
|
697 |
socklen_t arglen = sizeof(struct in_addr); |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
698 |
int n; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
699 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
700 |
n = getsockopt(fdval(env, fdo), IPPROTO_IP, IP_MULTICAST_IF, (void*)&in, &arglen); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
701 |
if (n < 0) { |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
702 |
handleSocketError(env, errno); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
703 |
return -1; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
704 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
705 |
return ntohl(in.s_addr); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
706 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
707 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
708 |
JNIEXPORT void JNICALL |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
709 |
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:
895
diff
changeset
|
710 |
{ |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
711 |
int value = (jint)index; |
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
9035
diff
changeset
|
712 |
socklen_t arglen = sizeof(value); |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
713 |
int n; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
714 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
715 |
n = setsockopt(fdval(env, fdo), IPPROTO_IPV6, IPV6_MULTICAST_IF, |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
716 |
(void*)&(index), arglen); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
717 |
if (n < 0) { |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
718 |
handleSocketError(env, errno); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
719 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
720 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
721 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
722 |
JNIEXPORT jint JNICALL |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
723 |
Java_sun_nio_ch_Net_getInterface6(JNIEnv* env, jobject this, jobject fdo) |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
724 |
{ |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
725 |
int index; |
6850
56966b0a6a0d
6989466: Miscellaneous compiler warnings in java/lang, java/util, java/io, sun/misc native code
alanb
parents:
6299
diff
changeset
|
726 |
socklen_t arglen = sizeof(index); |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
727 |
int n; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
728 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
729 |
n = getsockopt(fdval(env, fdo), IPPROTO_IPV6, IPV6_MULTICAST_IF, (void*)&index, &arglen); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
730 |
if (n < 0) { |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
731 |
handleSocketError(env, errno); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
732 |
return -1; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
733 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
734 |
return (jint)index; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
735 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
736 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
737 |
JNIEXPORT void JNICALL |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
738 |
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:
895
diff
changeset
|
739 |
{ |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
740 |
int how = (jhow == sun_nio_ch_Net_SHUT_RD) ? SHUT_RD : |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
741 |
(jhow == sun_nio_ch_Net_SHUT_WR) ? SHUT_WR : SHUT_RDWR; |
3486
0e14ae32369e
4516760: (so) Intermittent SocketException: Transport endpoint is not connected (lnx)
alanb
parents:
1247
diff
changeset
|
742 |
if ((shutdown(fdval(env, fdo), how) < 0) && (errno != ENOTCONN)) |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
743 |
handleSocketError(env, errno); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
744 |
} |
2 | 745 |
|
14025
fbebe005a3ee
7184932: Remove the temporary Selector usage in the NIO socket adapters
robm
parents:
13363
diff
changeset
|
746 |
JNIEXPORT jint JNICALL |
53422
6f02e036630e
8217461: (ch) Add Net.available to return the number of bytes in the socket input buffer
alanb
parents:
52073
diff
changeset
|
747 |
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:
52073
diff
changeset
|
748 |
{ |
6f02e036630e
8217461: (ch) Add Net.available to return the number of bytes in the socket input buffer
alanb
parents:
52073
diff
changeset
|
749 |
int count = 0; |
6f02e036630e
8217461: (ch) Add Net.available to return the number of bytes in the socket input buffer
alanb
parents:
52073
diff
changeset
|
750 |
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:
52073
diff
changeset
|
751 |
handleSocketError(env, errno); |
6f02e036630e
8217461: (ch) Add Net.available to return the number of bytes in the socket input buffer
alanb
parents:
52073
diff
changeset
|
752 |
return IOS_THROWN; |
6f02e036630e
8217461: (ch) Add Net.available to return the number of bytes in the socket input buffer
alanb
parents:
52073
diff
changeset
|
753 |
} |
6f02e036630e
8217461: (ch) Add Net.available to return the number of bytes in the socket input buffer
alanb
parents:
52073
diff
changeset
|
754 |
return (jint) count; |
6f02e036630e
8217461: (ch) Add Net.available to return the number of bytes in the socket input buffer
alanb
parents:
52073
diff
changeset
|
755 |
} |
6f02e036630e
8217461: (ch) Add Net.available to return the number of bytes in the socket input buffer
alanb
parents:
52073
diff
changeset
|
756 |
|
6f02e036630e
8217461: (ch) Add Net.available to return the number of bytes in the socket input buffer
alanb
parents:
52073
diff
changeset
|
757 |
JNIEXPORT jint JNICALL |
14025
fbebe005a3ee
7184932: Remove the temporary Selector usage in the NIO socket adapters
robm
parents:
13363
diff
changeset
|
758 |
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:
13363
diff
changeset
|
759 |
{ |
fbebe005a3ee
7184932: Remove the temporary Selector usage in the NIO socket adapters
robm
parents:
13363
diff
changeset
|
760 |
struct pollfd pfd; |
fbebe005a3ee
7184932: Remove the temporary Selector usage in the NIO socket adapters
robm
parents:
13363
diff
changeset
|
761 |
int rv; |
fbebe005a3ee
7184932: Remove the temporary Selector usage in the NIO socket adapters
robm
parents:
13363
diff
changeset
|
762 |
pfd.fd = fdval(env, fdo); |
fbebe005a3ee
7184932: Remove the temporary Selector usage in the NIO socket adapters
robm
parents:
13363
diff
changeset
|
763 |
pfd.events = events; |
32014
262d30f45454
8132652: Java_sun_nio_ch_Net_poll passes a long to an int
bpb
parents:
32006
diff
changeset
|
764 |
if (timeout < -1) { |
262d30f45454
8132652: Java_sun_nio_ch_Net_poll passes a long to an int
bpb
parents:
32006
diff
changeset
|
765 |
timeout = -1; |
262d30f45454
8132652: Java_sun_nio_ch_Net_poll passes a long to an int
bpb
parents:
32006
diff
changeset
|
766 |
} else if (timeout > INT_MAX) { |
262d30f45454
8132652: Java_sun_nio_ch_Net_poll passes a long to an int
bpb
parents:
32006
diff
changeset
|
767 |
timeout = INT_MAX; |
262d30f45454
8132652: Java_sun_nio_ch_Net_poll passes a long to an int
bpb
parents:
32006
diff
changeset
|
768 |
} |
262d30f45454
8132652: Java_sun_nio_ch_Net_poll passes a long to an int
bpb
parents:
32006
diff
changeset
|
769 |
rv = poll(&pfd, 1, (int)timeout); |
14025
fbebe005a3ee
7184932: Remove the temporary Selector usage in the NIO socket adapters
robm
parents:
13363
diff
changeset
|
770 |
|
fbebe005a3ee
7184932: Remove the temporary Selector usage in the NIO socket adapters
robm
parents:
13363
diff
changeset
|
771 |
if (rv >= 0) { |
fbebe005a3ee
7184932: Remove the temporary Selector usage in the NIO socket adapters
robm
parents:
13363
diff
changeset
|
772 |
return pfd.revents; |
fbebe005a3ee
7184932: Remove the temporary Selector usage in the NIO socket adapters
robm
parents:
13363
diff
changeset
|
773 |
} else if (errno == EINTR) { |
49702
09c01737ad27
8201474: (so) Socket adaptor connect(InetAddress, timeout) succeeds when connection fails
alanb
parents:
49440
diff
changeset
|
774 |
// interrupted, no events to return |
09c01737ad27
8201474: (so) Socket adaptor connect(InetAddress, timeout) succeeds when connection fails
alanb
parents:
49440
diff
changeset
|
775 |
return 0; |
18535
71b74ae0ab8a
8014377: (dc) DatagramChannel should set IP_MULTICAST_ALL=0 (lnx)
alanb
parents:
18192
diff
changeset
|
776 |
} else { |
14025
fbebe005a3ee
7184932: Remove the temporary Selector usage in the NIO socket adapters
robm
parents:
13363
diff
changeset
|
777 |
handleSocketError(env, errno); |
fbebe005a3ee
7184932: Remove the temporary Selector usage in the NIO socket adapters
robm
parents:
13363
diff
changeset
|
778 |
return IOS_THROWN; |
fbebe005a3ee
7184932: Remove the temporary Selector usage in the NIO socket adapters
robm
parents:
13363
diff
changeset
|
779 |
} |
fbebe005a3ee
7184932: Remove the temporary Selector usage in the NIO socket adapters
robm
parents:
13363
diff
changeset
|
780 |
} |
fbebe005a3ee
7184932: Remove the temporary Selector usage in the NIO socket adapters
robm
parents:
13363
diff
changeset
|
781 |
|
54246
f04e3492fd88
8221252: (sc) SocketChannel and its socket adaptor need to handle connection reset
alanb
parents:
54154
diff
changeset
|
782 |
JNIEXPORT jboolean JNICALL |
53445
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
783 |
Java_sun_nio_ch_Net_pollConnect(JNIEnv *env, jobject this, jobject fdo, jlong timeout) |
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
784 |
{ |
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
785 |
jint fd = fdval(env, fdo); |
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
786 |
struct pollfd poller; |
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
787 |
int result; |
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
788 |
|
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
789 |
poller.fd = fd; |
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
790 |
poller.events = POLLOUT; |
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
791 |
poller.revents = 0; |
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
792 |
if (timeout < -1) { |
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
793 |
timeout = -1; |
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
794 |
} else if (timeout > INT_MAX) { |
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
795 |
timeout = INT_MAX; |
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
796 |
} |
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
797 |
|
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
798 |
result = poll(&poller, 1, (int)timeout); |
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
799 |
|
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
800 |
if (result > 0) { |
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
801 |
int error = 0; |
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
802 |
socklen_t n = sizeof(int); |
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
803 |
errno = 0; |
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
804 |
result = getsockopt(fd, SOL_SOCKET, SO_ERROR, &error, &n); |
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
805 |
if (result < 0) { |
54246
f04e3492fd88
8221252: (sc) SocketChannel and its socket adaptor need to handle connection reset
alanb
parents:
54154
diff
changeset
|
806 |
handleSocketError(env, errno); |
f04e3492fd88
8221252: (sc) SocketChannel and its socket adaptor need to handle connection reset
alanb
parents:
54154
diff
changeset
|
807 |
return JNI_FALSE; |
53445
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
808 |
} else if (error) { |
54246
f04e3492fd88
8221252: (sc) SocketChannel and its socket adaptor need to handle connection reset
alanb
parents:
54154
diff
changeset
|
809 |
handleSocketError(env, error); |
f04e3492fd88
8221252: (sc) SocketChannel and its socket adaptor need to handle connection reset
alanb
parents:
54154
diff
changeset
|
810 |
return JNI_FALSE; |
53445
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
811 |
} else if ((poller.revents & POLLHUP) != 0) { |
54246
f04e3492fd88
8221252: (sc) SocketChannel and its socket adaptor need to handle connection reset
alanb
parents:
54154
diff
changeset
|
812 |
handleSocketError(env, ENOTCONN); |
f04e3492fd88
8221252: (sc) SocketChannel and its socket adaptor need to handle connection reset
alanb
parents:
54154
diff
changeset
|
813 |
return JNI_FALSE; |
53445
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
814 |
} |
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
815 |
// connected |
54246
f04e3492fd88
8221252: (sc) SocketChannel and its socket adaptor need to handle connection reset
alanb
parents:
54154
diff
changeset
|
816 |
return JNI_TRUE; |
f04e3492fd88
8221252: (sc) SocketChannel and its socket adaptor need to handle connection reset
alanb
parents:
54154
diff
changeset
|
817 |
} else if (result == 0 || errno == EINTR) { |
f04e3492fd88
8221252: (sc) SocketChannel and its socket adaptor need to handle connection reset
alanb
parents:
54154
diff
changeset
|
818 |
return JNI_FALSE; |
53445
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
819 |
} else { |
54246
f04e3492fd88
8221252: (sc) SocketChannel and its socket adaptor need to handle connection reset
alanb
parents:
54154
diff
changeset
|
820 |
JNU_ThrowIOExceptionWithLastError(env, "poll failed"); |
f04e3492fd88
8221252: (sc) SocketChannel and its socket adaptor need to handle connection reset
alanb
parents:
54154
diff
changeset
|
821 |
return JNI_FALSE; |
53445
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
822 |
} |
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
823 |
} |
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
824 |
|
22604
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
22597
diff
changeset
|
825 |
JNIEXPORT jshort JNICALL |
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
22597
diff
changeset
|
826 |
Java_sun_nio_ch_Net_pollinValue(JNIEnv *env, jclass this) |
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
22597
diff
changeset
|
827 |
{ |
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
22597
diff
changeset
|
828 |
return (jshort)POLLIN; |
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
22597
diff
changeset
|
829 |
} |
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
22597
diff
changeset
|
830 |
|
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
22597
diff
changeset
|
831 |
JNIEXPORT jshort JNICALL |
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
22597
diff
changeset
|
832 |
Java_sun_nio_ch_Net_polloutValue(JNIEnv *env, jclass this) |
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
22597
diff
changeset
|
833 |
{ |
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
22597
diff
changeset
|
834 |
return (jshort)POLLOUT; |
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
22597
diff
changeset
|
835 |
} |
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
22597
diff
changeset
|
836 |
|
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
22597
diff
changeset
|
837 |
JNIEXPORT jshort JNICALL |
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
22597
diff
changeset
|
838 |
Java_sun_nio_ch_Net_pollerrValue(JNIEnv *env, jclass this) |
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
22597
diff
changeset
|
839 |
{ |
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
22597
diff
changeset
|
840 |
return (jshort)POLLERR; |
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
22597
diff
changeset
|
841 |
} |
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
22597
diff
changeset
|
842 |
|
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
22597
diff
changeset
|
843 |
JNIEXPORT jshort JNICALL |
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
22597
diff
changeset
|
844 |
Java_sun_nio_ch_Net_pollhupValue(JNIEnv *env, jclass this) |
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
22597
diff
changeset
|
845 |
{ |
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
22597
diff
changeset
|
846 |
return (jshort)POLLHUP; |
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
22597
diff
changeset
|
847 |
} |
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
22597
diff
changeset
|
848 |
|
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
22597
diff
changeset
|
849 |
JNIEXPORT jshort JNICALL |
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
22597
diff
changeset
|
850 |
Java_sun_nio_ch_Net_pollnvalValue(JNIEnv *env, jclass this) |
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
22597
diff
changeset
|
851 |
{ |
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
22597
diff
changeset
|
852 |
return (jshort)POLLNVAL; |
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
22597
diff
changeset
|
853 |
} |
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
22597
diff
changeset
|
854 |
|
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
22597
diff
changeset
|
855 |
JNIEXPORT jshort JNICALL |
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
22597
diff
changeset
|
856 |
Java_sun_nio_ch_Net_pollconnValue(JNIEnv *env, jclass this) |
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
22597
diff
changeset
|
857 |
{ |
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
22597
diff
changeset
|
858 |
return (jshort)POLLOUT; |
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
22597
diff
changeset
|
859 |
} |
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
22597
diff
changeset
|
860 |
|
53445
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
861 |
JNIEXPORT jint JNICALL |
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
862 |
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
|
863 |
{ |
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
864 |
int n = send(fdval(env, fdo), (const void*)&b, 1, MSG_OOB); |
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
865 |
return convertReturnVal(env, n, JNI_FALSE); |
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
866 |
} |
14025
fbebe005a3ee
7184932: Remove the temporary Selector usage in the NIO socket adapters
robm
parents:
13363
diff
changeset
|
867 |
|
2 | 868 |
/* Declared in nio_util.h */ |
869 |
||
52073
1c8745e31fa3
8212000: Verify exported symbols in java.base (libnet, libnio/ch)
prappo
parents:
49702
diff
changeset
|
870 |
jint handleSocketError(JNIEnv *env, jint errorValue) |
2 | 871 |
{ |
872 |
char *xn; |
|
873 |
switch (errorValue) { |
|
874 |
case EINPROGRESS: /* Non-blocking connect */ |
|
875 |
return 0; |
|
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
9035
diff
changeset
|
876 |
#ifdef EPROTO |
2 | 877 |
case EPROTO: |
878 |
xn = JNU_JAVANETPKG "ProtocolException"; |
|
879 |
break; |
|
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
9035
diff
changeset
|
880 |
#endif |
2 | 881 |
case ECONNREFUSED: |
49141
ac95c7a76132
8198928: (so) SocketChannel connect may deadlock if closed at around same time that connect fails
alanb
parents:
47216
diff
changeset
|
882 |
case ETIMEDOUT: |
ac95c7a76132
8198928: (so) SocketChannel connect may deadlock if closed at around same time that connect fails
alanb
parents:
47216
diff
changeset
|
883 |
case ENOTCONN: |
2 | 884 |
xn = JNU_JAVANETPKG "ConnectException"; |
885 |
break; |
|
49141
ac95c7a76132
8198928: (so) SocketChannel connect may deadlock if closed at around same time that connect fails
alanb
parents:
47216
diff
changeset
|
886 |
|
2 | 887 |
case EHOSTUNREACH: |
888 |
xn = JNU_JAVANETPKG "NoRouteToHostException"; |
|
889 |
break; |
|
890 |
case EADDRINUSE: /* Fall through */ |
|
891 |
case EADDRNOTAVAIL: |
|
54154
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
892 |
case EACCES: |
2 | 893 |
xn = JNU_JAVANETPKG "BindException"; |
894 |
break; |
|
895 |
default: |
|
896 |
xn = JNU_JAVANETPKG "SocketException"; |
|
897 |
break; |
|
898 |
} |
|
899 |
errno = errorValue; |
|
900 |
JNU_ThrowByNameWithLastError(env, xn, "NioSocketError"); |
|
901 |
return IOS_THROWN; |
|
902 |
} |