author | ohair |
Tue, 28 Dec 2010 15:53:50 -0800 | |
changeset 7668 | d4a77089c587 |
parent 6850 | 56966b0a6a0d |
child 8788 | b98f18278dc4 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
7668 | 2 |
* Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
#include <sys/types.h> |
|
27 |
#include <sys/socket.h> |
|
28 |
#include <string.h> |
|
29 |
#include <netinet/in.h> |
|
30 |
#include <netinet/tcp.h> |
|
31 |
||
32 |
#include "jni.h" |
|
33 |
#include "jni_util.h" |
|
34 |
#include "jvm.h" |
|
35 |
#include "jlong.h" |
|
36 |
#include "sun_nio_ch_Net.h" |
|
37 |
#include "net_util.h" |
|
38 |
#include "net_util_md.h" |
|
39 |
#include "nio_util.h" |
|
40 |
#include "nio.h" |
|
41 |
||
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
42 |
/** |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
43 |
* Definitions for source-specific multicast to allow for building |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
44 |
* with older header files. |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
45 |
*/ |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
46 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
47 |
#ifdef __solaris__ |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
48 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
49 |
#ifndef IP_BLOCK_SOURCE |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
50 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
51 |
#define IP_BLOCK_SOURCE 0x15 |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
52 |
#define IP_UNBLOCK_SOURCE 0x16 |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
53 |
#define IP_ADD_SOURCE_MEMBERSHIP 0x17 |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
54 |
#define IP_DROP_SOURCE_MEMBERSHIP 0x18 |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
55 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
56 |
#define MCAST_BLOCK_SOURCE 0x2b |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
57 |
#define MCAST_UNBLOCK_SOURCE 0x2c |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
58 |
#define MCAST_JOIN_SOURCE_GROUP 0x2d |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
59 |
#define MCAST_LEAVE_SOURCE_GROUP 0x2e |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
60 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
61 |
#endif /* IP_BLOCK_SOURCE */ |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
62 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
63 |
struct my_ip_mreq_source { |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
64 |
struct in_addr imr_multiaddr; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
65 |
struct in_addr imr_sourceaddr; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
66 |
struct in_addr imr_interface; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
67 |
}; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
68 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
69 |
/* |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
70 |
* Use #pragma pack() construct to force 32-bit alignment on amd64. |
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 |
#if defined(amd64) |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
73 |
#pragma pack(4) |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
74 |
#endif |
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 |
struct my_group_source_req { |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
77 |
uint32_t gsr_interface; /* interface index */ |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
78 |
struct sockaddr_storage gsr_group; /* group address */ |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
79 |
struct sockaddr_storage gsr_source; /* source address */ |
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 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
82 |
#if defined(amd64) |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
83 |
#pragma pack() |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
84 |
#endif |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
85 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
86 |
#endif /* __solaris__ */ |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
87 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
88 |
|
2 | 89 |
#ifdef __linux__ |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
90 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
91 |
#ifndef IP_BLOCK_SOURCE |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
92 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
93 |
#define IP_BLOCK_SOURCE 38 |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
94 |
#define IP_UNBLOCK_SOURCE 37 |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
95 |
#define IP_ADD_SOURCE_MEMBERSHIP 39 |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
96 |
#define IP_DROP_SOURCE_MEMBERSHIP 40 |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
97 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
98 |
#define MCAST_BLOCK_SOURCE 43 |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
99 |
#define MCAST_UNBLOCK_SOURCE 44 |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
100 |
#define MCAST_JOIN_SOURCE_GROUP 42 |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
101 |
#define MCAST_LEAVE_SOURCE_GROUP 45 |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
102 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
103 |
#endif /* IP_BLOCK_SOURCE */ |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
104 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
105 |
struct my_ip_mreq_source { |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
106 |
struct in_addr imr_multiaddr; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
107 |
struct in_addr imr_interface; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
108 |
struct in_addr imr_sourceaddr; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
109 |
}; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
110 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
111 |
struct my_group_source_req { |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
112 |
uint32_t gsr_interface; /* interface index */ |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
113 |
struct sockaddr_storage gsr_group; /* group address */ |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
114 |
struct sockaddr_storage gsr_source; /* source address */ |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
115 |
}; |
2 | 116 |
|
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
117 |
#endif /* __linux__ */ |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
118 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
119 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
120 |
#define COPY_INET6_ADDRESS(env, source, target) \ |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
121 |
(*env)->GetByteArrayRegion(env, source, 0, 16, target) |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
122 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
123 |
/* |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
124 |
* Copy IPv6 group, interface index, and IPv6 source address |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
125 |
* into group_source_req structure. |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
126 |
*/ |
4814 | 127 |
#ifdef AF_INET6 |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
128 |
static void initGroupSourceReq(JNIEnv* env, jbyteArray group, jint index, |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
129 |
jbyteArray source, struct my_group_source_req* req) |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
130 |
{ |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
131 |
struct sockaddr_in6* sin6; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
132 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
133 |
req->gsr_interface = (uint32_t)index; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
134 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
135 |
sin6 = (struct sockaddr_in6*)&(req->gsr_group); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
136 |
sin6->sin6_family = AF_INET6; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
137 |
COPY_INET6_ADDRESS(env, group, (jbyte*)&(sin6->sin6_addr)); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
138 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
139 |
sin6 = (struct sockaddr_in6*)&(req->gsr_source); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
140 |
sin6->sin6_family = AF_INET6; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
141 |
COPY_INET6_ADDRESS(env, source, (jbyte*)&(sin6->sin6_addr)); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
142 |
} |
4814 | 143 |
#endif |
2 | 144 |
|
145 |
JNIEXPORT void JNICALL |
|
146 |
Java_sun_nio_ch_Net_initIDs(JNIEnv *env, jclass clazz) |
|
147 |
{ |
|
148 |
/* Here because Windows native code does need to init IDs */ |
|
149 |
} |
|
150 |
||
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
151 |
JNIEXPORT jboolean JNICALL |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
152 |
Java_sun_nio_ch_Net_isIPv6Available0(JNIEnv* env, jclass cl) |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
153 |
{ |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
154 |
return (ipv6_available()) ? JNI_TRUE : JNI_FALSE; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
155 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
156 |
|
2 | 157 |
JNIEXPORT int JNICALL |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
158 |
Java_sun_nio_ch_Net_socket0(JNIEnv *env, jclass cl, jboolean preferIPv6, |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
159 |
jboolean stream, jboolean reuse) |
2 | 160 |
{ |
161 |
int fd; |
|
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
162 |
int type = (stream ? SOCK_STREAM : SOCK_DGRAM); |
4814 | 163 |
#ifdef AF_INET6 |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
164 |
int domain = (ipv6_available() && preferIPv6) ? AF_INET6 : AF_INET; |
4814 | 165 |
#else |
166 |
int domain = AF_INET; |
|
167 |
#endif |
|
2 | 168 |
|
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
169 |
fd = socket(domain, type, 0); |
2 | 170 |
if (fd < 0) { |
171 |
return handleSocketError(env, errno); |
|
172 |
} |
|
6299
a44d48dbcd50
6882910: Unexplained lack of IP4 network ability when transparent IP6 to IP4 is disabled.
chegar
parents:
5506
diff
changeset
|
173 |
|
a44d48dbcd50
6882910: Unexplained lack of IP4 network ability when transparent IP6 to IP4 is disabled.
chegar
parents:
5506
diff
changeset
|
174 |
#ifdef AF_INET6 |
a44d48dbcd50
6882910: Unexplained lack of IP4 network ability when transparent IP6 to IP4 is disabled.
chegar
parents:
5506
diff
changeset
|
175 |
/* Disable IPV6_V6ONLY to ensure dual-socket support */ |
a44d48dbcd50
6882910: Unexplained lack of IP4 network ability when transparent IP6 to IP4 is disabled.
chegar
parents:
5506
diff
changeset
|
176 |
if (domain == AF_INET6) { |
a44d48dbcd50
6882910: Unexplained lack of IP4 network ability when transparent IP6 to IP4 is disabled.
chegar
parents:
5506
diff
changeset
|
177 |
int arg = 0; |
a44d48dbcd50
6882910: Unexplained lack of IP4 network ability when transparent IP6 to IP4 is disabled.
chegar
parents:
5506
diff
changeset
|
178 |
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
|
179 |
sizeof(int)) < 0) { |
a44d48dbcd50
6882910: Unexplained lack of IP4 network ability when transparent IP6 to IP4 is disabled.
chegar
parents:
5506
diff
changeset
|
180 |
JNU_ThrowByNameWithLastError(env, |
a44d48dbcd50
6882910: Unexplained lack of IP4 network ability when transparent IP6 to IP4 is disabled.
chegar
parents:
5506
diff
changeset
|
181 |
JNU_JAVANETPKG "SocketException", |
a44d48dbcd50
6882910: Unexplained lack of IP4 network ability when transparent IP6 to IP4 is disabled.
chegar
parents:
5506
diff
changeset
|
182 |
"sun.nio.ch.Net.setIntOption"); |
a44d48dbcd50
6882910: Unexplained lack of IP4 network ability when transparent IP6 to IP4 is disabled.
chegar
parents:
5506
diff
changeset
|
183 |
close(fd); |
a44d48dbcd50
6882910: Unexplained lack of IP4 network ability when transparent IP6 to IP4 is disabled.
chegar
parents:
5506
diff
changeset
|
184 |
return -1; |
a44d48dbcd50
6882910: Unexplained lack of IP4 network ability when transparent IP6 to IP4 is disabled.
chegar
parents:
5506
diff
changeset
|
185 |
} |
a44d48dbcd50
6882910: Unexplained lack of IP4 network ability when transparent IP6 to IP4 is disabled.
chegar
parents:
5506
diff
changeset
|
186 |
} |
a44d48dbcd50
6882910: Unexplained lack of IP4 network ability when transparent IP6 to IP4 is disabled.
chegar
parents:
5506
diff
changeset
|
187 |
#endif |
a44d48dbcd50
6882910: Unexplained lack of IP4 network ability when transparent IP6 to IP4 is disabled.
chegar
parents:
5506
diff
changeset
|
188 |
|
2 | 189 |
if (reuse) { |
190 |
int arg = 1; |
|
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
191 |
if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char*)&arg, |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
192 |
sizeof(arg)) < 0) { |
2 | 193 |
JNU_ThrowByNameWithLastError(env, |
194 |
JNU_JAVANETPKG "SocketException", |
|
195 |
"sun.nio.ch.Net.setIntOption"); |
|
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
196 |
close(fd); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
197 |
return -1; |
2 | 198 |
} |
199 |
} |
|
4814 | 200 |
#if defined(__linux__) && defined(AF_INET6) |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
201 |
/* By default, Linux uses the route default */ |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
202 |
if (domain == AF_INET6 && type == SOCK_DGRAM) { |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
203 |
int arg = 1; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
204 |
if (setsockopt(fd, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, &arg, |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
205 |
sizeof(arg)) < 0) { |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
206 |
JNU_ThrowByNameWithLastError(env, |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
207 |
JNU_JAVANETPKG "SocketException", |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
208 |
"sun.nio.ch.Net.setIntOption"); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
209 |
close(fd); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
210 |
return -1; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
211 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
212 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
213 |
#endif |
2 | 214 |
return fd; |
215 |
} |
|
216 |
||
217 |
JNIEXPORT void JNICALL |
|
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
218 |
Java_sun_nio_ch_Net_bind0(JNIEnv *env, jclass clazz, jboolean preferIPv6, |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
219 |
jobject fdo, jobject iao, int port) |
2 | 220 |
{ |
221 |
SOCKADDR sa; |
|
222 |
int sa_len = SOCKADDR_LEN; |
|
223 |
int rv = 0; |
|
224 |
||
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
225 |
if (NET_InetAddressToSockaddr(env, iao, port, (struct sockaddr *)&sa, &sa_len, preferIPv6) != 0) { |
2 | 226 |
return; |
227 |
} |
|
228 |
||
229 |
rv = NET_Bind(fdval(env, fdo), (struct sockaddr *)&sa, sa_len); |
|
230 |
if (rv != 0) { |
|
231 |
handleSocketError(env, errno); |
|
232 |
} |
|
233 |
} |
|
234 |
||
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
235 |
JNIEXPORT void JNICALL |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
236 |
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
|
237 |
{ |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
238 |
if (listen(fdval(env, fdo), backlog) < 0) |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
239 |
handleSocketError(env, errno); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
240 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
241 |
|
2 | 242 |
JNIEXPORT jint JNICALL |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
243 |
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
|
244 |
jobject fdo, jobject iao, jint port) |
2 | 245 |
{ |
246 |
SOCKADDR sa; |
|
247 |
int sa_len = SOCKADDR_LEN; |
|
248 |
int rv; |
|
249 |
||
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
250 |
if (NET_InetAddressToSockaddr(env, iao, port, (struct sockaddr *) &sa, |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
251 |
&sa_len, preferIPv6) != 0) |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
252 |
{ |
2 | 253 |
return IOS_THROWN; |
254 |
} |
|
255 |
||
256 |
rv = connect(fdval(env, fdo), (struct sockaddr *)&sa, sa_len); |
|
257 |
if (rv != 0) { |
|
258 |
if (errno == EINPROGRESS) { |
|
259 |
return IOS_UNAVAILABLE; |
|
260 |
} else if (errno == EINTR) { |
|
261 |
return IOS_INTERRUPTED; |
|
262 |
} |
|
263 |
return handleSocketError(env, errno); |
|
264 |
} |
|
265 |
return 1; |
|
266 |
} |
|
267 |
||
268 |
JNIEXPORT jint JNICALL |
|
269 |
Java_sun_nio_ch_Net_localPort(JNIEnv *env, jclass clazz, jobject fdo) |
|
270 |
{ |
|
271 |
SOCKADDR sa; |
|
895 | 272 |
socklen_t sa_len = SOCKADDR_LEN; |
2 | 273 |
if (getsockname(fdval(env, fdo), (struct sockaddr *)&sa, &sa_len) < 0) { |
274 |
handleSocketError(env, errno); |
|
275 |
return -1; |
|
276 |
} |
|
277 |
return NET_GetPortFromSockaddr((struct sockaddr *)&sa); |
|
278 |
} |
|
279 |
||
280 |
JNIEXPORT jobject JNICALL |
|
281 |
Java_sun_nio_ch_Net_localInetAddress(JNIEnv *env, jclass clazz, jobject fdo) |
|
282 |
{ |
|
283 |
SOCKADDR sa; |
|
895 | 284 |
socklen_t sa_len = SOCKADDR_LEN; |
2 | 285 |
int port; |
286 |
if (getsockname(fdval(env, fdo), (struct sockaddr *)&sa, &sa_len) < 0) { |
|
287 |
handleSocketError(env, errno); |
|
288 |
return NULL; |
|
289 |
} |
|
290 |
return NET_SockaddrToInetAddress(env, (struct sockaddr *)&sa, &port); |
|
291 |
} |
|
292 |
||
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
293 |
JNIEXPORT jint JNICALL |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
294 |
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
|
295 |
jboolean mayNeedConversion, jint level, jint opt) |
2 | 296 |
{ |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
297 |
int result; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
298 |
struct linger linger; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
299 |
u_char carg; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
300 |
void *arg; |
6850
56966b0a6a0d
6989466: Miscellaneous compiler warnings in java/lang, java/util, java/io, sun/misc native code
alanb
parents:
6299
diff
changeset
|
301 |
socklen_t arglen; |
56966b0a6a0d
6989466: Miscellaneous compiler warnings in java/lang, java/util, java/io, sun/misc native code
alanb
parents:
6299
diff
changeset
|
302 |
int n; |
2 | 303 |
|
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
304 |
/* 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
|
305 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
306 |
arg = (void *)&result; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
307 |
arglen = sizeof(result); |
2 | 308 |
|
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
309 |
if (level == IPPROTO_IP && |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
310 |
(opt == IP_MULTICAST_TTL || opt == IP_MULTICAST_LOOP)) { |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
311 |
arg = (void*)&carg; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
312 |
arglen = sizeof(carg); |
2 | 313 |
} |
314 |
||
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
315 |
if (level == SOL_SOCKET && opt == SO_LINGER) { |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
316 |
arg = (void *)&linger; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
317 |
arglen = sizeof(linger); |
2 | 318 |
} |
319 |
||
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
320 |
if (mayNeedConversion) { |
6850
56966b0a6a0d
6989466: Miscellaneous compiler warnings in java/lang, java/util, java/io, sun/misc native code
alanb
parents:
6299
diff
changeset
|
321 |
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
|
322 |
} else { |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
323 |
n = getsockopt(fdval(env, fdo), level, opt, arg, &arglen); |
2 | 324 |
} |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
325 |
if (n < 0) { |
2 | 326 |
JNU_ThrowByNameWithLastError(env, |
327 |
JNU_JAVANETPKG "SocketException", |
|
328 |
"sun.nio.ch.Net.getIntOption"); |
|
329 |
return -1; |
|
330 |
} |
|
331 |
||
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
332 |
if (level == IPPROTO_IP && |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
333 |
(opt == IP_MULTICAST_TTL || opt == IP_MULTICAST_LOOP)) |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
334 |
{ |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
335 |
return (jint)carg; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
336 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
337 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
338 |
if (level == SOL_SOCKET && opt == SO_LINGER) |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
339 |
return linger.l_onoff ? (jint)linger.l_linger : (jint)-1; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
340 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
341 |
return (jint)result; |
2 | 342 |
} |
343 |
||
344 |
JNIEXPORT void JNICALL |
|
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
345 |
Java_sun_nio_ch_Net_setIntOption0(JNIEnv *env, jclass clazz, jobject fdo, |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
346 |
jboolean mayNeedConversion, jint level, jint opt, jint arg) |
2 | 347 |
{ |
348 |
int result; |
|
349 |
struct linger linger; |
|
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
350 |
u_char carg; |
2 | 351 |
void *parg; |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
352 |
int arglen, n; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
353 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
354 |
/* Option value is an int except for a few specific cases */ |
2 | 355 |
|
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
356 |
parg = (void*)&arg; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
357 |
arglen = sizeof(arg); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
358 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
359 |
if (level == IPPROTO_IP && |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
360 |
(opt == IP_MULTICAST_TTL || opt == IP_MULTICAST_LOOP)) { |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
361 |
parg = (void*)&carg; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
362 |
arglen = sizeof(carg); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
363 |
carg = (u_char)arg; |
2 | 364 |
} |
365 |
||
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
366 |
if (level == SOL_SOCKET && opt == SO_LINGER) { |
2 | 367 |
parg = (void *)&linger; |
368 |
arglen = sizeof(linger); |
|
369 |
if (arg >= 0) { |
|
370 |
linger.l_onoff = 1; |
|
371 |
linger.l_linger = arg; |
|
372 |
} else { |
|
373 |
linger.l_onoff = 0; |
|
374 |
linger.l_linger = 0; |
|
375 |
} |
|
376 |
} |
|
377 |
||
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
378 |
if (mayNeedConversion) { |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
379 |
n = NET_SetSockOpt(fdval(env, fdo), level, opt, parg, arglen); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
380 |
} else { |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
381 |
n = setsockopt(fdval(env, fdo), level, opt, parg, arglen); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
382 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
383 |
if (n < 0) { |
2 | 384 |
JNU_ThrowByNameWithLastError(env, |
385 |
JNU_JAVANETPKG "SocketException", |
|
386 |
"sun.nio.ch.Net.setIntOption"); |
|
387 |
} |
|
388 |
} |
|
389 |
||
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
390 |
JNIEXPORT jint JNICALL |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
391 |
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
|
392 |
jint group, jint interf, jint source) |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
393 |
{ |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
394 |
struct ip_mreq mreq; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
395 |
struct my_ip_mreq_source mreq_source; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
396 |
int opt, n, optlen; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
397 |
void* optval; |
2 | 398 |
|
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
399 |
if (source == 0) { |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
400 |
mreq.imr_multiaddr.s_addr = htonl(group); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
401 |
mreq.imr_interface.s_addr = htonl(interf); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
402 |
opt = (join) ? IP_ADD_MEMBERSHIP : IP_DROP_MEMBERSHIP; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
403 |
optval = (void*)&mreq; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
404 |
optlen = sizeof(mreq); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
405 |
} else { |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
406 |
mreq_source.imr_multiaddr.s_addr = htonl(group); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
407 |
mreq_source.imr_sourceaddr.s_addr = htonl(source); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
408 |
mreq_source.imr_interface.s_addr = htonl(interf); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
409 |
opt = (join) ? IP_ADD_SOURCE_MEMBERSHIP : IP_DROP_SOURCE_MEMBERSHIP; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
410 |
optval = (void*)&mreq_source; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
411 |
optlen = sizeof(mreq_source); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
412 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
413 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
414 |
n = setsockopt(fdval(env,fdo), IPPROTO_IP, opt, optval, optlen); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
415 |
if (n < 0) { |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
416 |
if (join && (errno == ENOPROTOOPT)) |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
417 |
return IOS_UNAVAILABLE; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
418 |
handleSocketError(env, errno); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
419 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
420 |
return 0; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
421 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
422 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
423 |
JNIEXPORT jint JNICALL |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
424 |
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
|
425 |
jint group, jint interf, jint source) |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
426 |
{ |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
427 |
struct my_ip_mreq_source mreq_source; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
428 |
int n; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
429 |
int opt = (block) ? IP_BLOCK_SOURCE : IP_UNBLOCK_SOURCE; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
430 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
431 |
mreq_source.imr_multiaddr.s_addr = htonl(group); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
432 |
mreq_source.imr_sourceaddr.s_addr = htonl(source); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
433 |
mreq_source.imr_interface.s_addr = htonl(interf); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
434 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
435 |
n = setsockopt(fdval(env,fdo), IPPROTO_IP, opt, |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
436 |
(void*)&mreq_source, sizeof(mreq_source)); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
437 |
if (n < 0) { |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
438 |
if (block && (errno == ENOPROTOOPT)) |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
439 |
return IOS_UNAVAILABLE; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
440 |
handleSocketError(env, errno); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
441 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
442 |
return 0; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
443 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
444 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
445 |
JNIEXPORT jint JNICALL |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
446 |
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
|
447 |
jbyteArray group, jint index, jbyteArray source) |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
448 |
{ |
4814 | 449 |
#ifdef AF_INET6 |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
450 |
struct ipv6_mreq mreq6; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
451 |
struct my_group_source_req req; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
452 |
int opt, n, optlen; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
453 |
void* optval; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
454 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
455 |
if (source == NULL) { |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
456 |
COPY_INET6_ADDRESS(env, group, (jbyte*)&(mreq6.ipv6mr_multiaddr)); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
457 |
mreq6.ipv6mr_interface = (int)index; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
458 |
opt = (join) ? IPV6_ADD_MEMBERSHIP : IPV6_DROP_MEMBERSHIP; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
459 |
optval = (void*)&mreq6; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
460 |
optlen = sizeof(mreq6); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
461 |
} else { |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
462 |
#ifdef __linux__ |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
463 |
/* Include-mode filtering broken on Linux at least to 2.6.24 */ |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
464 |
return IOS_UNAVAILABLE; |
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 |
initGroupSourceReq(env, group, index, source, &req); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
467 |
opt = (join) ? MCAST_JOIN_SOURCE_GROUP : MCAST_LEAVE_SOURCE_GROUP; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
468 |
optval = (void*)&req; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
469 |
optlen = sizeof(req); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
470 |
#endif |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
471 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
472 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
473 |
n = setsockopt(fdval(env,fdo), IPPROTO_IPV6, opt, optval, optlen); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
474 |
if (n < 0) { |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
475 |
if (join && (errno == ENOPROTOOPT)) |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
476 |
return IOS_UNAVAILABLE; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
477 |
handleSocketError(env, errno); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
478 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
479 |
return 0; |
4814 | 480 |
#else |
481 |
JNU_ThrowInternalError(env, "Should not get here"); |
|
482 |
return IOS_THROWN; |
|
483 |
#endif /* AF_INET6 */ |
|
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
484 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
485 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
486 |
JNIEXPORT jint JNICALL |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
487 |
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
|
488 |
jbyteArray group, jint index, jbyteArray source) |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
489 |
{ |
4814 | 490 |
#ifdef AF_INET6 |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
491 |
struct my_group_source_req req; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
492 |
int n; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
493 |
int opt = (block) ? MCAST_BLOCK_SOURCE : MCAST_UNBLOCK_SOURCE; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
494 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
495 |
initGroupSourceReq(env, group, index, source, &req); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
496 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
497 |
n = setsockopt(fdval(env,fdo), IPPROTO_IPV6, opt, |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
498 |
(void*)&req, sizeof(req)); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
499 |
if (n < 0) { |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
500 |
if (block && (errno == ENOPROTOOPT)) |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
501 |
return IOS_UNAVAILABLE; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
502 |
handleSocketError(env, errno); |
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 |
return 0; |
4814 | 505 |
#else |
506 |
JNU_ThrowInternalError(env, "Should not get here"); |
|
507 |
return IOS_THROWN; |
|
508 |
#endif |
|
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
509 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
510 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
511 |
JNIEXPORT void JNICALL |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
512 |
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
|
513 |
{ |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
514 |
struct in_addr in; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
515 |
int arglen = sizeof(struct in_addr); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
516 |
int n; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
517 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
518 |
in.s_addr = htonl(interf); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
519 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
520 |
n = setsockopt(fdval(env, fdo), IPPROTO_IP, IP_MULTICAST_IF, |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
521 |
(void*)&(in.s_addr), arglen); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
522 |
if (n < 0) { |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
523 |
handleSocketError(env, errno); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
524 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
525 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
526 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
527 |
JNIEXPORT jint JNICALL |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
528 |
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
|
529 |
{ |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
530 |
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
|
531 |
socklen_t arglen = sizeof(struct in_addr); |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
532 |
int n; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
533 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
534 |
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
|
535 |
if (n < 0) { |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
536 |
handleSocketError(env, errno); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
537 |
return -1; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
538 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
539 |
return ntohl(in.s_addr); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
540 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
541 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
542 |
JNIEXPORT void JNICALL |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
543 |
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
|
544 |
{ |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
545 |
int value = (jint)index; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
546 |
int arglen = sizeof(value); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
547 |
int n; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
548 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
549 |
n = setsockopt(fdval(env, fdo), IPPROTO_IPV6, IPV6_MULTICAST_IF, |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
550 |
(void*)&(index), arglen); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
551 |
if (n < 0) { |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
552 |
handleSocketError(env, errno); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
553 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
554 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
555 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
556 |
JNIEXPORT jint JNICALL |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
557 |
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
|
558 |
{ |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
559 |
int index; |
6850
56966b0a6a0d
6989466: Miscellaneous compiler warnings in java/lang, java/util, java/io, sun/misc native code
alanb
parents:
6299
diff
changeset
|
560 |
socklen_t arglen = sizeof(index); |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
561 |
int n; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
562 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
563 |
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
|
564 |
if (n < 0) { |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
565 |
handleSocketError(env, errno); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
566 |
return -1; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
567 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
568 |
return (jint)index; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
569 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
570 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
571 |
JNIEXPORT void JNICALL |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
572 |
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
|
573 |
{ |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
574 |
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
|
575 |
(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
|
576 |
if ((shutdown(fdval(env, fdo), how) < 0) && (errno != ENOTCONN)) |
1152
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 |
} |
2 | 579 |
|
580 |
/* Declared in nio_util.h */ |
|
581 |
||
582 |
jint |
|
583 |
handleSocketError(JNIEnv *env, jint errorValue) |
|
584 |
{ |
|
585 |
char *xn; |
|
586 |
switch (errorValue) { |
|
587 |
case EINPROGRESS: /* Non-blocking connect */ |
|
588 |
return 0; |
|
589 |
case EPROTO: |
|
590 |
xn = JNU_JAVANETPKG "ProtocolException"; |
|
591 |
break; |
|
592 |
case ECONNREFUSED: |
|
593 |
xn = JNU_JAVANETPKG "ConnectException"; |
|
594 |
break; |
|
595 |
case ETIMEDOUT: |
|
596 |
xn = JNU_JAVANETPKG "ConnectException"; |
|
597 |
break; |
|
598 |
case EHOSTUNREACH: |
|
599 |
xn = JNU_JAVANETPKG "NoRouteToHostException"; |
|
600 |
break; |
|
601 |
case EADDRINUSE: /* Fall through */ |
|
602 |
case EADDRNOTAVAIL: |
|
603 |
xn = JNU_JAVANETPKG "BindException"; |
|
604 |
break; |
|
605 |
default: |
|
606 |
xn = JNU_JAVANETPKG "SocketException"; |
|
607 |
break; |
|
608 |
} |
|
609 |
errno = errorValue; |
|
610 |
JNU_ThrowByNameWithLastError(env, xn, "NioSocketError"); |
|
611 |
return IOS_THROWN; |
|
612 |
} |