author | michaelm |
Thu, 14 Nov 2019 15:01:49 +0000 | |
branch | unixdomainchannels |
changeset 59082 | 5e250ee9259e |
parent 59076 | 998df1368cca |
child 59090 | fb91b01624be |
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 |
|
58801
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
49 |
|
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
50 |
extern jclass udsa_class; |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
51 |
extern jmethodID udsa_ctorID; |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
52 |
extern jfieldID udsa_pathID; |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
53 |
|
59082
5e250ee9259e
unixdomainchannels: fix some sockaddr_un address handling
michaelm
parents:
59076
diff
changeset
|
54 |
#define PATHLEN(len) (len - offsetof(struct sockaddr_un, sun_path)) |
5e250ee9259e
unixdomainchannels: fix some sockaddr_un address handling
michaelm
parents:
59076
diff
changeset
|
55 |
|
58801
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
56 |
JNIEXPORT jobject JNICALL |
59082
5e250ee9259e
unixdomainchannels: fix some sockaddr_un address handling
michaelm
parents:
59076
diff
changeset
|
57 |
NET_SockaddrToUnixAddress(JNIEnv *env, struct sockaddr_un *sa, socklen_t len) { |
58801
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
58 |
|
59018
6d621f34e24a
moved unix socket address out of SOCKETADDRESS structure
michaelm
parents:
59004
diff
changeset
|
59 |
if (sa->sun_family == AF_UNIX) { |
59082
5e250ee9259e
unixdomainchannels: fix some sockaddr_un address handling
michaelm
parents:
59076
diff
changeset
|
60 |
char *name; |
58801
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
61 |
|
59082
5e250ee9259e
unixdomainchannels: fix some sockaddr_un address handling
michaelm
parents:
59076
diff
changeset
|
62 |
if (PATHLEN(len) == 0) { |
5e250ee9259e
unixdomainchannels: fix some sockaddr_un address handling
michaelm
parents:
59076
diff
changeset
|
63 |
name = ""; |
5e250ee9259e
unixdomainchannels: fix some sockaddr_un address handling
michaelm
parents:
59076
diff
changeset
|
64 |
} else { |
5e250ee9259e
unixdomainchannels: fix some sockaddr_un address handling
michaelm
parents:
59076
diff
changeset
|
65 |
name = sa->sun_path; |
5e250ee9259e
unixdomainchannels: fix some sockaddr_un address handling
michaelm
parents:
59076
diff
changeset
|
66 |
} |
58801
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
67 |
jstring nstr = JNU_NewStringPlatform(env, name); |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
68 |
return (*env)->NewObject(env, udsa_class, udsa_ctorID, nstr); |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
69 |
} |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
70 |
return NULL; |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
71 |
} |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
72 |
|
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
73 |
JNIEXPORT jint JNICALL |
59018
6d621f34e24a
moved unix socket address out of SOCKETADDRESS structure
michaelm
parents:
59004
diff
changeset
|
74 |
NET_UnixSocketAddressToSockaddr(JNIEnv *env, jobject uaddr, struct sockaddr_un *sa, int *len) |
58801
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
75 |
{ |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
76 |
jstring path = (*env)->GetObjectField(env, uaddr, udsa_pathID); |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
77 |
jboolean isCopy; |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
78 |
int ret; |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
79 |
const char* pname = JNU_GetStringPlatformChars(env, path, &isCopy); |
59018
6d621f34e24a
moved unix socket address out of SOCKETADDRESS structure
michaelm
parents:
59004
diff
changeset
|
80 |
memset(sa, 0, sizeof(struct sockaddr_un)); |
6d621f34e24a
moved unix socket address out of SOCKETADDRESS structure
michaelm
parents:
59004
diff
changeset
|
81 |
sa->sun_family = AF_UNIX; |
58801
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
82 |
int name_len = strlen(pname) + 1; /* includes null termination */ |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
83 |
if (name_len > MAX_UNIX_DOMAIN_PATH_LEN) { |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
84 |
JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", "unix domain path too long"); |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
85 |
ret = 1; |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
86 |
goto finish; |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
87 |
} |
59018
6d621f34e24a
moved unix socket address out of SOCKETADDRESS structure
michaelm
parents:
59004
diff
changeset
|
88 |
strncpy(&sa->sun_path[0], pname, name_len); |
58801
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
89 |
*len = offsetof(struct sockaddr_un, sun_path) + name_len; |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
90 |
ret = 0; |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
91 |
finish: |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
92 |
if (isCopy) |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
93 |
JNU_ReleaseStringPlatformChars(env, path, pname); |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
94 |
return ret; |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
95 |
} |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
96 |
|
58847 | 97 |
JNIEXPORT jboolean JNICALL |
98 |
Java_sun_nio_ch_Net_unixDomainSocketSupported(JNIEnv *env, jclass cl) |
|
99 |
{ |
|
100 |
return JNI_TRUE; |
|
101 |
} |
|
102 |
||
58801
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
103 |
JNIEXPORT jint JNICALL |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
104 |
Java_sun_nio_ch_Net_unixDomainSocket0(JNIEnv *env, jclass cl) |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
105 |
{ |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
106 |
int fd = socket(PF_UNIX, SOCK_STREAM, 0); |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
107 |
if (fd < 0) { |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
108 |
return handleSocketError(env, errno); |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
109 |
} |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
110 |
return fd; |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
111 |
} |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
112 |
|
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
113 |
JNIEXPORT void JNICALL |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
114 |
Java_sun_nio_ch_Net_unixDomainBind(JNIEnv *env, jclass clazz, jobject fdo, jobject uaddr) |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
115 |
{ |
59018
6d621f34e24a
moved unix socket address out of SOCKETADDRESS structure
michaelm
parents:
59004
diff
changeset
|
116 |
struct sockaddr_un sa; |
58801
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
117 |
int sa_len = 0; |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
118 |
int rv = 0; |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
119 |
|
59082
5e250ee9259e
unixdomainchannels: fix some sockaddr_un address handling
michaelm
parents:
59076
diff
changeset
|
120 |
if (uaddr == NULL) |
5e250ee9259e
unixdomainchannels: fix some sockaddr_un address handling
michaelm
parents:
59076
diff
changeset
|
121 |
return; /* Rely on implicit bind */ |
59076 | 122 |
|
58801
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
123 |
if (NET_UnixSocketAddressToSockaddr(env, uaddr, &sa, &sa_len) != 0) |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
124 |
return; |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
125 |
|
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
126 |
int fd = fdval(env, fdo); |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
127 |
|
59018
6d621f34e24a
moved unix socket address out of SOCKETADDRESS structure
michaelm
parents:
59004
diff
changeset
|
128 |
rv = bind(fdval(env, fdo), (struct sockaddr *)&sa, sa_len); |
58801
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
129 |
if (rv != 0) { |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
130 |
handleSocketError(env, errno); |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
131 |
} |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
132 |
} |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
133 |
|
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
134 |
JNIEXPORT jint JNICALL |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
135 |
Java_sun_nio_ch_Net_unixDomainConnect(JNIEnv *env, jclass clazz, jobject fdo, jobject usa) |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
136 |
{ |
59018
6d621f34e24a
moved unix socket address out of SOCKETADDRESS structure
michaelm
parents:
59004
diff
changeset
|
137 |
struct sockaddr_un sa; |
58801
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
138 |
int sa_len = 0; |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
139 |
int rv; |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
140 |
|
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
141 |
if (NET_UnixSocketAddressToSockaddr(env, usa, &sa, &sa_len) != 0) { |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
142 |
return IOS_THROWN; |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
143 |
} |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
144 |
|
59018
6d621f34e24a
moved unix socket address out of SOCKETADDRESS structure
michaelm
parents:
59004
diff
changeset
|
145 |
rv = connect(fdval(env, fdo), (struct sockaddr *)&sa, sa_len); |
58801
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
146 |
if (rv != 0) { |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
147 |
if (errno == EINPROGRESS) { |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
148 |
return IOS_UNAVAILABLE; |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
149 |
} else if (errno == EINTR) { |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
150 |
return IOS_INTERRUPTED; |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
151 |
} |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
152 |
return handleSocketError(env, errno); |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
153 |
} |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
154 |
return 1; |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
155 |
} |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
156 |
|
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
157 |
JNIEXPORT jint JNICALL |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
158 |
Java_sun_nio_ch_Net_unixDomainAccept(JNIEnv *env, jclass clazz, jobject fdo, jobject newfdo, |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
159 |
jobjectArray usaa) |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
160 |
{ |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
161 |
jint fd = fdval(env, fdo); |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
162 |
jint newfd; |
59018
6d621f34e24a
moved unix socket address out of SOCKETADDRESS structure
michaelm
parents:
59004
diff
changeset
|
163 |
struct sockaddr_un sa; |
6d621f34e24a
moved unix socket address out of SOCKETADDRESS structure
michaelm
parents:
59004
diff
changeset
|
164 |
socklen_t sa_len = sizeof(struct sockaddr_un); |
58801
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
165 |
jobject usa; |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
166 |
|
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
167 |
/* accept connection but ignore ECONNABORTED */ |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
168 |
for (;;) { |
59018
6d621f34e24a
moved unix socket address out of SOCKETADDRESS structure
michaelm
parents:
59004
diff
changeset
|
169 |
newfd = accept(fd, (struct sockaddr *)&sa, &sa_len); |
58801
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
170 |
if (newfd >= 0) { |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
171 |
break; |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
172 |
} |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
173 |
if (errno != ECONNABORTED) { |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
174 |
break; |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
175 |
} |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
176 |
/* ECONNABORTED => restart accept */ |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
177 |
} |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
178 |
|
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
179 |
if (newfd < 0) { |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
180 |
if (errno == EAGAIN || errno == EWOULDBLOCK) |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
181 |
return IOS_UNAVAILABLE; |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
182 |
if (errno == EINTR) |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
183 |
return IOS_INTERRUPTED; |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
184 |
JNU_ThrowIOExceptionWithLastError(env, "Accept failed"); |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
185 |
return IOS_THROWN; |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
186 |
} |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
187 |
|
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
188 |
setfdval(env, newfdo, newfd); |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
189 |
|
59082
5e250ee9259e
unixdomainchannels: fix some sockaddr_un address handling
michaelm
parents:
59076
diff
changeset
|
190 |
usa = NET_SockaddrToUnixAddress(env, &sa, sa_len); |
58801
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
191 |
CHECK_NULL_RETURN(usa, IOS_THROWN); |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
192 |
|
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
193 |
(*env)->SetObjectArrayElement(env, usaa, 0, usa); |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
194 |
|
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
195 |
return 1; |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
196 |
} |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
197 |
|
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
198 |
JNIEXPORT jobject JNICALL |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
199 |
Java_sun_nio_ch_Net_localUnixAddress(JNIEnv *env, jclass clazz, jobject fdo) |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
200 |
{ |
59018
6d621f34e24a
moved unix socket address out of SOCKETADDRESS structure
michaelm
parents:
59004
diff
changeset
|
201 |
struct sockaddr_un sa; |
6d621f34e24a
moved unix socket address out of SOCKETADDRESS structure
michaelm
parents:
59004
diff
changeset
|
202 |
socklen_t sa_len = sizeof(struct sockaddr_un); |
58801
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
203 |
int port; |
59018
6d621f34e24a
moved unix socket address out of SOCKETADDRESS structure
michaelm
parents:
59004
diff
changeset
|
204 |
if (getsockname(fdval(env, fdo), (struct sockaddr *)&sa, &sa_len) < 0) { |
58801
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
205 |
handleSocketError(env, errno); |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
206 |
return NULL; |
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
207 |
} |
59082
5e250ee9259e
unixdomainchannels: fix some sockaddr_un address handling
michaelm
parents:
59076
diff
changeset
|
208 |
return NET_SockaddrToUnixAddress(env, &sa, sa_len); |
58801
119ac9128c1b
Initial implementation of unix domain channels. See j.n.c.{Server}SocketChannel apidoc
michaelm
parents:
58535
diff
changeset
|
209 |
} |
58847 | 210 |
|
18535
71b74ae0ab8a
8014377: (dc) DatagramChannel should set IP_MULTICAST_ALL=0 (lnx)
alanb
parents:
18192
diff
changeset
|
211 |
/** |
71b74ae0ab8a
8014377: (dc) DatagramChannel should set IP_MULTICAST_ALL=0 (lnx)
alanb
parents:
18192
diff
changeset
|
212 |
* 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
|
213 |
* build time. |
71b74ae0ab8a
8014377: (dc) DatagramChannel should set IP_MULTICAST_ALL=0 (lnx)
alanb
parents:
18192
diff
changeset
|
214 |
*/ |
71b74ae0ab8a
8014377: (dc) DatagramChannel should set IP_MULTICAST_ALL=0 (lnx)
alanb
parents:
18192
diff
changeset
|
215 |
#ifdef __linux__ |
71b74ae0ab8a
8014377: (dc) DatagramChannel should set IP_MULTICAST_ALL=0 (lnx)
alanb
parents:
18192
diff
changeset
|
216 |
#ifndef IP_MULTICAST_ALL |
22573
8f0344f13b7f
8032451: (dc) DatagramChannel.join should support include-mode filtering on OS X
alanb
parents:
18535
diff
changeset
|
217 |
#define IP_MULTICAST_ALL 49 |
18535
71b74ae0ab8a
8014377: (dc) DatagramChannel should set IP_MULTICAST_ALL=0 (lnx)
alanb
parents:
18192
diff
changeset
|
218 |
#endif |
71b74ae0ab8a
8014377: (dc) DatagramChannel should set IP_MULTICAST_ALL=0 (lnx)
alanb
parents:
18192
diff
changeset
|
219 |
#endif |
71b74ae0ab8a
8014377: (dc) DatagramChannel should set IP_MULTICAST_ALL=0 (lnx)
alanb
parents:
18192
diff
changeset
|
220 |
|
22573
8f0344f13b7f
8032451: (dc) DatagramChannel.join should support include-mode filtering on OS X
alanb
parents:
18535
diff
changeset
|
221 |
/** |
22607 | 222 |
* 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
|
223 |
*/ |
22607 | 224 |
#if defined(__APPLE__) || defined(_AIX) |
22573
8f0344f13b7f
8032451: (dc) DatagramChannel.join should support include-mode filtering on OS X
alanb
parents:
18535
diff
changeset
|
225 |
#ifndef IPV6_ADD_MEMBERSHIP |
8f0344f13b7f
8032451: (dc) DatagramChannel.join should support include-mode filtering on OS X
alanb
parents:
18535
diff
changeset
|
226 |
#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
|
227 |
#define IPV6_DROP_MEMBERSHIP IPV6_LEAVE_GROUP |
18535
71b74ae0ab8a
8014377: (dc) DatagramChannel should set IP_MULTICAST_ALL=0 (lnx)
alanb
parents:
18192
diff
changeset
|
228 |
#endif |
71b74ae0ab8a
8014377: (dc) DatagramChannel should set IP_MULTICAST_ALL=0 (lnx)
alanb
parents:
18192
diff
changeset
|
229 |
#endif |
71b74ae0ab8a
8014377: (dc) DatagramChannel should set IP_MULTICAST_ALL=0 (lnx)
alanb
parents:
18192
diff
changeset
|
230 |
|
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
231 |
#define COPY_INET6_ADDRESS(env, source, target) \ |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
232 |
(*env)->GetByteArrayRegion(env, source, 0, 16, target) |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
233 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
234 |
/* |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
235 |
* Copy IPv6 group, interface index, and IPv6 source address |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
236 |
* into group_source_req structure. |
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 |
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
|
239 |
jbyteArray source, struct group_source_req *req) |
1152
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 |
struct sockaddr_in6* sin6; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
242 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
243 |
req->gsr_interface = (uint32_t)index; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
244 |
|
43889
212e765112d4
8174834: nio (ch): Remove #ifdef AF_INET6 guards in native coding
clanger
parents:
43100
diff
changeset
|
245 |
sin6 = (struct sockaddr_in6 *)&(req->gsr_group); |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
246 |
sin6->sin6_family = AF_INET6; |
43889
212e765112d4
8174834: nio (ch): Remove #ifdef AF_INET6 guards in native coding
clanger
parents:
43100
diff
changeset
|
247 |
COPY_INET6_ADDRESS(env, group, (jbyte *)&(sin6->sin6_addr)); |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
248 |
|
43889
212e765112d4
8174834: nio (ch): Remove #ifdef AF_INET6 guards in native coding
clanger
parents:
43100
diff
changeset
|
249 |
sin6 = (struct sockaddr_in6 *)&(req->gsr_source); |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
250 |
sin6->sin6_family = AF_INET6; |
43889
212e765112d4
8174834: nio (ch): Remove #ifdef AF_INET6 guards in native coding
clanger
parents:
43100
diff
changeset
|
251 |
COPY_INET6_ADDRESS(env, source, (jbyte *)&(sin6->sin6_addr)); |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
252 |
} |
2 | 253 |
|
22597
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
18535
diff
changeset
|
254 |
#ifdef _AIX |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
18535
diff
changeset
|
255 |
|
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
18535
diff
changeset
|
256 |
/* |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
18535
diff
changeset
|
257 |
* 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
|
258 |
* 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
|
259 |
*/ |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
18535
diff
changeset
|
260 |
static jboolean isSourceFilterSupported(){ |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
18535
diff
changeset
|
261 |
static jboolean alreadyChecked = JNI_FALSE; |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
18535
diff
changeset
|
262 |
static jboolean result = JNI_TRUE; |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
18535
diff
changeset
|
263 |
if (alreadyChecked != JNI_TRUE){ |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
18535
diff
changeset
|
264 |
struct utsname uts; |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
18535
diff
changeset
|
265 |
memset(&uts, 0, sizeof(uts)); |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
18535
diff
changeset
|
266 |
strcpy(uts.sysname, "?"); |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
18535
diff
changeset
|
267 |
const int utsRes = uname(&uts); |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
18535
diff
changeset
|
268 |
int major = -1; |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
18535
diff
changeset
|
269 |
int minor = -1; |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
18535
diff
changeset
|
270 |
major = atoi(uts.version); |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
18535
diff
changeset
|
271 |
minor = atoi(uts.release); |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
18535
diff
changeset
|
272 |
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
|
273 |
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
|
274 |
result = JNI_FALSE; |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
18535
diff
changeset
|
275 |
} |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
18535
diff
changeset
|
276 |
} |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
18535
diff
changeset
|
277 |
alreadyChecked = JNI_TRUE; |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
18535
diff
changeset
|
278 |
} |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
18535
diff
changeset
|
279 |
return result; |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
18535
diff
changeset
|
280 |
} |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
18535
diff
changeset
|
281 |
|
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
18535
diff
changeset
|
282 |
#endif /* _AIX */ |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
18535
diff
changeset
|
283 |
|
54154
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
284 |
static jclass isa_class; /* java.net.InetSocketAddress */ |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
285 |
static jmethodID isa_ctorID; /* InetSocketAddress(InetAddress, int) */ |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
286 |
|
2 | 287 |
JNIEXPORT void JNICALL |
288 |
Java_sun_nio_ch_Net_initIDs(JNIEnv *env, jclass clazz) |
|
289 |
{ |
|
54154
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
290 |
jclass cls = (*env)->FindClass(env, "java/net/InetSocketAddress"); |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
291 |
CHECK_NULL(cls); |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
292 |
isa_class = (*env)->NewGlobalRef(env, cls); |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
293 |
if (isa_class == NULL) { |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
294 |
JNU_ThrowOutOfMemoryError(env, NULL); |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
295 |
return; |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
296 |
} |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
297 |
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
|
298 |
CHECK_NULL(isa_ctorID); |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
299 |
|
26207
a02f6165d5be
8055955: (ch) Remove unnecessary initialization of InetAddress from FileChannel
chegar
parents:
25859
diff
changeset
|
300 |
initInetAddressIDs(env); |
2 | 301 |
} |
302 |
||
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
303 |
JNIEXPORT jboolean JNICALL |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
304 |
Java_sun_nio_ch_Net_isIPv6Available0(JNIEnv* env, jclass cl) |
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 |
return (ipv6_available()) ? JNI_TRUE : JNI_FALSE; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
307 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
308 |
|
36115 | 309 |
JNIEXPORT jboolean JNICALL |
310 |
Java_sun_nio_ch_Net_isReusePortAvailable0(JNIEnv* env, jclass c1) |
|
311 |
{ |
|
312 |
return (reuseport_available()) ? JNI_TRUE : JNI_FALSE; |
|
313 |
} |
|
314 |
||
18192 | 315 |
JNIEXPORT jint JNICALL |
316 |
Java_sun_nio_ch_Net_isExclusiveBindAvailable(JNIEnv *env, jclass clazz) { |
|
317 |
return -1; |
|
318 |
} |
|
319 |
||
8788
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
7668
diff
changeset
|
320 |
JNIEXPORT jboolean JNICALL |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
7668
diff
changeset
|
321 |
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
|
322 |
{ |
59000
612c58965775
8233435: (dc) DatagramChannel should allow IPv6 socket join IPv4 multicast groups (macOS, win)
alanb
parents:
58535
diff
changeset
|
323 |
#if defined(__linux__) || defined(__APPLE__) || defined(__solaris__) |
612c58965775
8233435: (dc) DatagramChannel should allow IPv6 socket join IPv4 multicast groups (macOS, win)
alanb
parents:
58535
diff
changeset
|
324 |
/* IPv6 sockets can join IPv4 multicast groups */ |
612c58965775
8233435: (dc) DatagramChannel should allow IPv6 socket join IPv4 multicast groups (macOS, win)
alanb
parents:
58535
diff
changeset
|
325 |
return JNI_TRUE; |
612c58965775
8233435: (dc) DatagramChannel should allow IPv6 socket join IPv4 multicast groups (macOS, win)
alanb
parents:
58535
diff
changeset
|
326 |
#else |
612c58965775
8233435: (dc) DatagramChannel should allow IPv6 socket join IPv4 multicast groups (macOS, win)
alanb
parents:
58535
diff
changeset
|
327 |
/* IPv6 sockets cannot join IPv4 multicast groups */ |
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
9035
diff
changeset
|
328 |
return JNI_FALSE; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
9035
diff
changeset
|
329 |
#endif |
8788
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
7668
diff
changeset
|
330 |
} |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
7668
diff
changeset
|
331 |
|
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
7668
diff
changeset
|
332 |
JNIEXPORT jboolean JNICALL |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
7668
diff
changeset
|
333 |
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
|
334 |
{ |
59000
612c58965775
8233435: (dc) DatagramChannel should allow IPv6 socket join IPv4 multicast groups (macOS, win)
alanb
parents:
58535
diff
changeset
|
335 |
#if defined(__APPLE__) || defined(__solaris__) |
612c58965775
8233435: (dc) DatagramChannel should allow IPv6 socket join IPv4 multicast groups (macOS, win)
alanb
parents:
58535
diff
changeset
|
336 |
/* IPV6_ADD_MEMBERSHIP can be used to join IPv4 multicast groups */ |
8788
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
7668
diff
changeset
|
337 |
return JNI_TRUE; |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
7668
diff
changeset
|
338 |
#else |
59000
612c58965775
8233435: (dc) DatagramChannel should allow IPv6 socket join IPv4 multicast groups (macOS, win)
alanb
parents:
58535
diff
changeset
|
339 |
/* IPV6_ADD_MEMBERSHIP cannot be used to join IPv4 multicast groups */ |
8788
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
7668
diff
changeset
|
340 |
return JNI_FALSE; |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
7668
diff
changeset
|
341 |
#endif |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
7668
diff
changeset
|
342 |
} |
b98f18278dc4
7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents:
7668
diff
changeset
|
343 |
|
59000
612c58965775
8233435: (dc) DatagramChannel should allow IPv6 socket join IPv4 multicast groups (macOS, win)
alanb
parents:
58535
diff
changeset
|
344 |
JNIEXPORT jboolean JNICALL |
612c58965775
8233435: (dc) DatagramChannel should allow IPv6 socket join IPv4 multicast groups (macOS, win)
alanb
parents:
58535
diff
changeset
|
345 |
Java_sun_nio_ch_Net_canUseIPv6OptionsWithIPv4LocalAddress0(JNIEnv* env, jclass cl) |
612c58965775
8233435: (dc) DatagramChannel should allow IPv6 socket join IPv4 multicast groups (macOS, win)
alanb
parents:
58535
diff
changeset
|
346 |
{ |
612c58965775
8233435: (dc) DatagramChannel should allow IPv6 socket join IPv4 multicast groups (macOS, win)
alanb
parents:
58535
diff
changeset
|
347 |
/* IPV6_XXX socket options can be used on IPv6 sockets bound to IPv4 address */ |
612c58965775
8233435: (dc) DatagramChannel should allow IPv6 socket join IPv4 multicast groups (macOS, win)
alanb
parents:
58535
diff
changeset
|
348 |
return JNI_TRUE; |
612c58965775
8233435: (dc) DatagramChannel should allow IPv6 socket join IPv4 multicast groups (macOS, win)
alanb
parents:
58535
diff
changeset
|
349 |
} |
612c58965775
8233435: (dc) DatagramChannel should allow IPv6 socket join IPv4 multicast groups (macOS, win)
alanb
parents:
58535
diff
changeset
|
350 |
|
32006
97c6167e698a
8132505: Signature of Java_sun_nio_ch_Net_socket0 should return jint not int
bpb
parents:
27178
diff
changeset
|
351 |
JNIEXPORT jint JNICALL |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
352 |
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
|
353 |
jboolean stream, jboolean reuse, jboolean ignored) |
2 | 354 |
{ |
355 |
int fd; |
|
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
356 |
int type = (stream ? SOCK_STREAM : SOCK_DGRAM); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
357 |
int domain = (ipv6_available() && preferIPv6) ? AF_INET6 : AF_INET; |
2 | 358 |
|
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
359 |
fd = socket(domain, type, 0); |
2 | 360 |
if (fd < 0) { |
361 |
return handleSocketError(env, errno); |
|
362 |
} |
|
6299
a44d48dbcd50
6882910: Unexplained lack of IP4 network ability when transparent IP6 to IP4 is disabled.
chegar
parents:
5506
diff
changeset
|
363 |
|
54627
22323f20401b
8222562: Don't set IPV6_V6ONLY when IPv4 is not available
aeubanks
parents:
54246
diff
changeset
|
364 |
/* |
22323f20401b
8222562: Don't set IPV6_V6ONLY when IPv4 is not available
aeubanks
parents:
54246
diff
changeset
|
365 |
* 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
|
366 |
*/ |
22323f20401b
8222562: Don't set IPV6_V6ONLY when IPv4 is not available
aeubanks
parents:
54246
diff
changeset
|
367 |
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
|
368 |
int arg = 0; |
a44d48dbcd50
6882910: Unexplained lack of IP4 network ability when transparent IP6 to IP4 is disabled.
chegar
parents:
5506
diff
changeset
|
369 |
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
|
370 |
sizeof(int)) < 0) { |
a44d48dbcd50
6882910: Unexplained lack of IP4 network ability when transparent IP6 to IP4 is disabled.
chegar
parents:
5506
diff
changeset
|
371 |
JNU_ThrowByNameWithLastError(env, |
a44d48dbcd50
6882910: Unexplained lack of IP4 network ability when transparent IP6 to IP4 is disabled.
chegar
parents:
5506
diff
changeset
|
372 |
JNU_JAVANETPKG "SocketException", |
18535
71b74ae0ab8a
8014377: (dc) DatagramChannel should set IP_MULTICAST_ALL=0 (lnx)
alanb
parents:
18192
diff
changeset
|
373 |
"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
|
374 |
close(fd); |
a44d48dbcd50
6882910: Unexplained lack of IP4 network ability when transparent IP6 to IP4 is disabled.
chegar
parents:
5506
diff
changeset
|
375 |
return -1; |
a44d48dbcd50
6882910: Unexplained lack of IP4 network ability when transparent IP6 to IP4 is disabled.
chegar
parents:
5506
diff
changeset
|
376 |
} |
a44d48dbcd50
6882910: Unexplained lack of IP4 network ability when transparent IP6 to IP4 is disabled.
chegar
parents:
5506
diff
changeset
|
377 |
} |
a44d48dbcd50
6882910: Unexplained lack of IP4 network ability when transparent IP6 to IP4 is disabled.
chegar
parents:
5506
diff
changeset
|
378 |
|
2 | 379 |
if (reuse) { |
380 |
int arg = 1; |
|
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
381 |
if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char*)&arg, |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
382 |
sizeof(arg)) < 0) { |
2 | 383 |
JNU_ThrowByNameWithLastError(env, |
384 |
JNU_JAVANETPKG "SocketException", |
|
18535
71b74ae0ab8a
8014377: (dc) DatagramChannel should set IP_MULTICAST_ALL=0 (lnx)
alanb
parents:
18192
diff
changeset
|
385 |
"Unable to set SO_REUSEADDR"); |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
386 |
close(fd); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
387 |
return -1; |
2 | 388 |
} |
389 |
} |
|
18535
71b74ae0ab8a
8014377: (dc) DatagramChannel should set IP_MULTICAST_ALL=0 (lnx)
alanb
parents:
18192
diff
changeset
|
390 |
|
71b74ae0ab8a
8014377: (dc) DatagramChannel should set IP_MULTICAST_ALL=0 (lnx)
alanb
parents:
18192
diff
changeset
|
391 |
#if defined(__linux__) |
71b74ae0ab8a
8014377: (dc) DatagramChannel should set IP_MULTICAST_ALL=0 (lnx)
alanb
parents:
18192
diff
changeset
|
392 |
if (type == SOCK_DGRAM) { |
71b74ae0ab8a
8014377: (dc) DatagramChannel should set IP_MULTICAST_ALL=0 (lnx)
alanb
parents:
18192
diff
changeset
|
393 |
int arg = 0; |
71b74ae0ab8a
8014377: (dc) DatagramChannel should set IP_MULTICAST_ALL=0 (lnx)
alanb
parents:
18192
diff
changeset
|
394 |
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
|
395 |
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
|
396 |
(errno != ENOPROTOOPT)) { |
71b74ae0ab8a
8014377: (dc) DatagramChannel should set IP_MULTICAST_ALL=0 (lnx)
alanb
parents:
18192
diff
changeset
|
397 |
JNU_ThrowByNameWithLastError(env, |
71b74ae0ab8a
8014377: (dc) DatagramChannel should set IP_MULTICAST_ALL=0 (lnx)
alanb
parents:
18192
diff
changeset
|
398 |
JNU_JAVANETPKG "SocketException", |
71b74ae0ab8a
8014377: (dc) DatagramChannel should set IP_MULTICAST_ALL=0 (lnx)
alanb
parents:
18192
diff
changeset
|
399 |
"Unable to set IP_MULTICAST_ALL"); |
71b74ae0ab8a
8014377: (dc) DatagramChannel should set IP_MULTICAST_ALL=0 (lnx)
alanb
parents:
18192
diff
changeset
|
400 |
close(fd); |
71b74ae0ab8a
8014377: (dc) DatagramChannel should set IP_MULTICAST_ALL=0 (lnx)
alanb
parents:
18192
diff
changeset
|
401 |
return -1; |
71b74ae0ab8a
8014377: (dc) DatagramChannel should set IP_MULTICAST_ALL=0 (lnx)
alanb
parents:
18192
diff
changeset
|
402 |
} |
71b74ae0ab8a
8014377: (dc) DatagramChannel should set IP_MULTICAST_ALL=0 (lnx)
alanb
parents:
18192
diff
changeset
|
403 |
} |
71b74ae0ab8a
8014377: (dc) DatagramChannel should set IP_MULTICAST_ALL=0 (lnx)
alanb
parents:
18192
diff
changeset
|
404 |
|
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
405 |
/* By default, Linux uses the route default */ |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
406 |
if (domain == AF_INET6 && type == SOCK_DGRAM) { |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
407 |
int arg = 1; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
408 |
if (setsockopt(fd, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, &arg, |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
409 |
sizeof(arg)) < 0) { |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
410 |
JNU_ThrowByNameWithLastError(env, |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
411 |
JNU_JAVANETPKG "SocketException", |
18535
71b74ae0ab8a
8014377: (dc) DatagramChannel should set IP_MULTICAST_ALL=0 (lnx)
alanb
parents:
18192
diff
changeset
|
412 |
"Unable to set IPV6_MULTICAST_HOPS"); |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
413 |
close(fd); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
414 |
return -1; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
415 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
416 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
417 |
#endif |
2 | 418 |
return fd; |
419 |
} |
|
420 |
||
421 |
JNIEXPORT void JNICALL |
|
18192 | 422 |
Java_sun_nio_ch_Net_bind0(JNIEnv *env, jclass clazz, jobject fdo, jboolean preferIPv6, |
423 |
jboolean useExclBind, jobject iao, int port) |
|
2 | 424 |
{ |
41380
c27cf95dd7e6
8167295: Further cleanup to the native parts of libnet/libnio
clanger
parents:
36115
diff
changeset
|
425 |
SOCKETADDRESS sa; |
43100 | 426 |
int sa_len = 0; |
2 | 427 |
int rv = 0; |
428 |
||
43100 | 429 |
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
|
430 |
preferIPv6) != 0) { |
c27cf95dd7e6
8167295: Further cleanup to the native parts of libnet/libnio
clanger
parents:
36115
diff
changeset
|
431 |
return; |
2 | 432 |
} |
433 |
||
43100 | 434 |
rv = NET_Bind(fdval(env, fdo), &sa, sa_len); |
2 | 435 |
if (rv != 0) { |
436 |
handleSocketError(env, errno); |
|
437 |
} |
|
438 |
} |
|
439 |
||
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
440 |
JNIEXPORT void JNICALL |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
441 |
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
|
442 |
{ |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
443 |
if (listen(fdval(env, fdo), backlog) < 0) |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
444 |
handleSocketError(env, errno); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
445 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
446 |
|
2 | 447 |
JNIEXPORT jint JNICALL |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
448 |
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
|
449 |
jobject fdo, jobject iao, jint port) |
2 | 450 |
{ |
41380
c27cf95dd7e6
8167295: Further cleanup to the native parts of libnet/libnio
clanger
parents:
36115
diff
changeset
|
451 |
SOCKETADDRESS sa; |
43100 | 452 |
int sa_len = 0; |
2 | 453 |
int rv; |
454 |
||
49141
ac95c7a76132
8198928: (so) SocketChannel connect may deadlock if closed at around same time that connect fails
alanb
parents:
47216
diff
changeset
|
455 |
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
|
456 |
return IOS_THROWN; |
2 | 457 |
} |
458 |
||
41380
c27cf95dd7e6
8167295: Further cleanup to the native parts of libnet/libnio
clanger
parents:
36115
diff
changeset
|
459 |
rv = connect(fdval(env, fdo), &sa.sa, sa_len); |
2 | 460 |
if (rv != 0) { |
461 |
if (errno == EINPROGRESS) { |
|
462 |
return IOS_UNAVAILABLE; |
|
463 |
} else if (errno == EINTR) { |
|
464 |
return IOS_INTERRUPTED; |
|
465 |
} |
|
466 |
return handleSocketError(env, errno); |
|
467 |
} |
|
468 |
return 1; |
|
469 |
} |
|
470 |
||
471 |
JNIEXPORT jint JNICALL |
|
54154
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
472 |
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
|
473 |
jobjectArray isaa) |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
474 |
{ |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
475 |
jint fd = fdval(env, fdo); |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
476 |
jint newfd; |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
477 |
SOCKETADDRESS sa; |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
478 |
socklen_t sa_len = sizeof(SOCKETADDRESS); |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
479 |
jobject remote_ia; |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
480 |
jint remote_port = 0; |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
481 |
jobject isa; |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
482 |
|
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
483 |
/* accept connection but ignore ECONNABORTED */ |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
484 |
for (;;) { |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
485 |
newfd = accept(fd, &sa.sa, &sa_len); |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
486 |
if (newfd >= 0) { |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
487 |
break; |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
488 |
} |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
489 |
if (errno != ECONNABORTED) { |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
490 |
break; |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
491 |
} |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
492 |
/* ECONNABORTED => restart accept */ |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
493 |
} |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
494 |
|
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
495 |
if (newfd < 0) { |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
496 |
if (errno == EAGAIN || errno == EWOULDBLOCK) |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
497 |
return IOS_UNAVAILABLE; |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
498 |
if (errno == EINTR) |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
499 |
return IOS_INTERRUPTED; |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
500 |
JNU_ThrowIOExceptionWithLastError(env, "Accept failed"); |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
501 |
return IOS_THROWN; |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
502 |
} |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
503 |
|
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
504 |
setfdval(env, newfdo, newfd); |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
505 |
|
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
506 |
remote_ia = NET_SockaddrToInetAddress(env, &sa, (int *)&remote_port); |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
507 |
CHECK_NULL_RETURN(remote_ia, IOS_THROWN); |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
508 |
|
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
509 |
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
|
510 |
CHECK_NULL_RETURN(isa, IOS_THROWN); |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
511 |
(*env)->SetObjectArrayElement(env, isaa, 0, isa); |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
512 |
|
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
513 |
return 1; |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
514 |
} |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
515 |
|
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
516 |
JNIEXPORT jint JNICALL |
2 | 517 |
Java_sun_nio_ch_Net_localPort(JNIEnv *env, jclass clazz, jobject fdo) |
518 |
{ |
|
41380
c27cf95dd7e6
8167295: Further cleanup to the native parts of libnet/libnio
clanger
parents:
36115
diff
changeset
|
519 |
SOCKETADDRESS sa; |
c27cf95dd7e6
8167295: Further cleanup to the native parts of libnet/libnio
clanger
parents:
36115
diff
changeset
|
520 |
socklen_t sa_len = sizeof(SOCKETADDRESS); |
c27cf95dd7e6
8167295: Further cleanup to the native parts of libnet/libnio
clanger
parents:
36115
diff
changeset
|
521 |
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
|
522 |
#ifdef _ALLBSD_SOURCE |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
9035
diff
changeset
|
523 |
/* |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
9035
diff
changeset
|
524 |
* XXXBSD: |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
9035
diff
changeset
|
525 |
* 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
|
526 |
* 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
|
527 |
* 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
|
528 |
* 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
|
529 |
*/ |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
9035
diff
changeset
|
530 |
if (errno == ECONNRESET) { |
41380
c27cf95dd7e6
8167295: Further cleanup to the native parts of libnet/libnio
clanger
parents:
36115
diff
changeset
|
531 |
bzero(&sa.sa4, sizeof(sa)); |
c27cf95dd7e6
8167295: Further cleanup to the native parts of libnet/libnio
clanger
parents:
36115
diff
changeset
|
532 |
sa.sa4.sin_len = sizeof(struct sockaddr_in); |
c27cf95dd7e6
8167295: Further cleanup to the native parts of libnet/libnio
clanger
parents:
36115
diff
changeset
|
533 |
sa.sa4.sin_family = AF_INET; |
c27cf95dd7e6
8167295: Further cleanup to the native parts of libnet/libnio
clanger
parents:
36115
diff
changeset
|
534 |
sa.sa4.sin_port = htonl(0); |
c27cf95dd7e6
8167295: Further cleanup to the native parts of libnet/libnio
clanger
parents:
36115
diff
changeset
|
535 |
sa.sa4.sin_addr.s_addr = INADDR_ANY; |
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
9035
diff
changeset
|
536 |
} else { |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
9035
diff
changeset
|
537 |
handleSocketError(env, errno); |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
9035
diff
changeset
|
538 |
return -1; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
9035
diff
changeset
|
539 |
} |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
9035
diff
changeset
|
540 |
#else /* _ALLBSD_SOURCE */ |
2 | 541 |
handleSocketError(env, errno); |
542 |
return -1; |
|
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
9035
diff
changeset
|
543 |
#endif /* _ALLBSD_SOURCE */ |
2 | 544 |
} |
43100 | 545 |
return NET_GetPortFromSockaddr(&sa); |
2 | 546 |
} |
547 |
||
548 |
JNIEXPORT jobject JNICALL |
|
549 |
Java_sun_nio_ch_Net_localInetAddress(JNIEnv *env, jclass clazz, jobject fdo) |
|
550 |
{ |
|
41380
c27cf95dd7e6
8167295: Further cleanup to the native parts of libnet/libnio
clanger
parents:
36115
diff
changeset
|
551 |
SOCKETADDRESS sa; |
c27cf95dd7e6
8167295: Further cleanup to the native parts of libnet/libnio
clanger
parents:
36115
diff
changeset
|
552 |
socklen_t sa_len = sizeof(SOCKETADDRESS); |
2 | 553 |
int port; |
41380
c27cf95dd7e6
8167295: Further cleanup to the native parts of libnet/libnio
clanger
parents:
36115
diff
changeset
|
554 |
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
|
555 |
#ifdef _ALLBSD_SOURCE |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
9035
diff
changeset
|
556 |
/* |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
9035
diff
changeset
|
557 |
* XXXBSD: |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
9035
diff
changeset
|
558 |
* 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
|
559 |
* 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
|
560 |
* 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
|
561 |
* 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
|
562 |
*/ |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
9035
diff
changeset
|
563 |
if (errno == ECONNRESET) { |
41380
c27cf95dd7e6
8167295: Further cleanup to the native parts of libnet/libnio
clanger
parents:
36115
diff
changeset
|
564 |
bzero(&sa.sa4, sizeof(sa)); |
c27cf95dd7e6
8167295: Further cleanup to the native parts of libnet/libnio
clanger
parents:
36115
diff
changeset
|
565 |
sa.sa4.sin_len = sizeof(struct sockaddr_in); |
c27cf95dd7e6
8167295: Further cleanup to the native parts of libnet/libnio
clanger
parents:
36115
diff
changeset
|
566 |
sa.sa4.sin_family = AF_INET; |
c27cf95dd7e6
8167295: Further cleanup to the native parts of libnet/libnio
clanger
parents:
36115
diff
changeset
|
567 |
sa.sa4.sin_port = htonl(0); |
c27cf95dd7e6
8167295: Further cleanup to the native parts of libnet/libnio
clanger
parents:
36115
diff
changeset
|
568 |
sa.sa4.sin_addr.s_addr = INADDR_ANY; |
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
9035
diff
changeset
|
569 |
} else { |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
9035
diff
changeset
|
570 |
handleSocketError(env, errno); |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
9035
diff
changeset
|
571 |
return NULL; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
9035
diff
changeset
|
572 |
} |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
9035
diff
changeset
|
573 |
#else /* _ALLBSD_SOURCE */ |
2 | 574 |
handleSocketError(env, errno); |
575 |
return NULL; |
|
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
9035
diff
changeset
|
576 |
#endif /* _ALLBSD_SOURCE */ |
2 | 577 |
} |
43100 | 578 |
return NET_SockaddrToInetAddress(env, &sa, &port); |
2 | 579 |
} |
580 |
||
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
581 |
JNIEXPORT jint JNICALL |
54154
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
582 |
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
|
583 |
{ |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
584 |
SOCKETADDRESS sa; |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
585 |
socklen_t sa_len = sizeof(sa); |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
586 |
|
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
587 |
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
|
588 |
handleSocketError(env, errno); |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
589 |
return IOS_THROWN; |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
590 |
} |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
591 |
return NET_GetPortFromSockaddr(&sa); |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
592 |
} |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
593 |
|
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
594 |
JNIEXPORT jobject JNICALL |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
595 |
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
|
596 |
{ |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
597 |
SOCKETADDRESS sa; |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
598 |
socklen_t sa_len = sizeof(sa); |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
599 |
int port; |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
600 |
|
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
601 |
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
|
602 |
handleSocketError(env, errno); |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
603 |
return NULL; |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
604 |
} |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
605 |
return NET_SockaddrToInetAddress(env, &sa, &port); |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
606 |
} |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
607 |
|
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
608 |
JNIEXPORT jint JNICALL |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
609 |
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
|
610 |
jboolean mayNeedConversion, jint level, jint opt) |
2 | 611 |
{ |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
612 |
int result; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
613 |
struct linger linger; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
614 |
u_char carg; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
615 |
void *arg; |
6850
56966b0a6a0d
6989466: Miscellaneous compiler warnings in java/lang, java/util, java/io, sun/misc native code
alanb
parents:
6299
diff
changeset
|
616 |
socklen_t arglen; |
56966b0a6a0d
6989466: Miscellaneous compiler warnings in java/lang, java/util, java/io, sun/misc native code
alanb
parents:
6299
diff
changeset
|
617 |
int n; |
2 | 618 |
|
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
619 |
/* 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
|
620 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
621 |
arg = (void *)&result; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
622 |
arglen = sizeof(result); |
2 | 623 |
|
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
624 |
if (level == IPPROTO_IP && |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
625 |
(opt == IP_MULTICAST_TTL || opt == IP_MULTICAST_LOOP)) { |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
626 |
arg = (void*)&carg; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
627 |
arglen = sizeof(carg); |
2 | 628 |
} |
629 |
||
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
630 |
if (level == SOL_SOCKET && opt == SO_LINGER) { |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
631 |
arg = (void *)&linger; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
632 |
arglen = sizeof(linger); |
2 | 633 |
} |
634 |
||
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
635 |
if (mayNeedConversion) { |
6850
56966b0a6a0d
6989466: Miscellaneous compiler warnings in java/lang, java/util, java/io, sun/misc native code
alanb
parents:
6299
diff
changeset
|
636 |
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
|
637 |
} else { |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
638 |
n = getsockopt(fdval(env, fdo), level, opt, arg, &arglen); |
2 | 639 |
} |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
640 |
if (n < 0) { |
2 | 641 |
JNU_ThrowByNameWithLastError(env, |
642 |
JNU_JAVANETPKG "SocketException", |
|
643 |
"sun.nio.ch.Net.getIntOption"); |
|
644 |
return -1; |
|
645 |
} |
|
646 |
||
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
647 |
if (level == IPPROTO_IP && |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
648 |
(opt == IP_MULTICAST_TTL || opt == IP_MULTICAST_LOOP)) |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
649 |
{ |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
650 |
return (jint)carg; |
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 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
653 |
if (level == SOL_SOCKET && opt == SO_LINGER) |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
654 |
return linger.l_onoff ? (jint)linger.l_linger : (jint)-1; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
655 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
656 |
return (jint)result; |
2 | 657 |
} |
658 |
||
659 |
JNIEXPORT void JNICALL |
|
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
660 |
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
|
661 |
jboolean mayNeedConversion, jint level, |
f58832169add
8029607: Type of Service (TOS) cannot be set in IPv6 header
michaelm
parents:
23016
diff
changeset
|
662 |
jint opt, jint arg, jboolean isIPv6) |
2 | 663 |
{ |
664 |
int result; |
|
665 |
struct linger linger; |
|
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
666 |
u_char carg; |
2 | 667 |
void *parg; |
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
9035
diff
changeset
|
668 |
socklen_t arglen; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
9035
diff
changeset
|
669 |
int n; |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
670 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
671 |
/* Option value is an int except for a few specific cases */ |
2 | 672 |
|
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
673 |
parg = (void*)&arg; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
674 |
arglen = sizeof(arg); |
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 |
if (level == IPPROTO_IP && |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
677 |
(opt == IP_MULTICAST_TTL || opt == IP_MULTICAST_LOOP)) { |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
678 |
parg = (void*)&carg; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
679 |
arglen = sizeof(carg); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
680 |
carg = (u_char)arg; |
2 | 681 |
} |
682 |
||
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
683 |
if (level == SOL_SOCKET && opt == SO_LINGER) { |
2 | 684 |
parg = (void *)&linger; |
685 |
arglen = sizeof(linger); |
|
686 |
if (arg >= 0) { |
|
687 |
linger.l_onoff = 1; |
|
688 |
linger.l_linger = arg; |
|
689 |
} else { |
|
690 |
linger.l_onoff = 0; |
|
691 |
linger.l_linger = 0; |
|
692 |
} |
|
693 |
} |
|
694 |
||
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
695 |
if (mayNeedConversion) { |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
696 |
n = NET_SetSockOpt(fdval(env, fdo), level, opt, parg, arglen); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
697 |
} else { |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
698 |
n = setsockopt(fdval(env, fdo), level, opt, parg, arglen); |
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 |
if (n < 0) { |
2 | 701 |
JNU_ThrowByNameWithLastError(env, |
702 |
JNU_JAVANETPKG "SocketException", |
|
703 |
"sun.nio.ch.Net.setIntOption"); |
|
704 |
} |
|
25170
f58832169add
8029607: Type of Service (TOS) cannot be set in IPv6 header
michaelm
parents:
23016
diff
changeset
|
705 |
#ifdef __linux__ |
f58832169add
8029607: Type of Service (TOS) cannot be set in IPv6 header
michaelm
parents:
23016
diff
changeset
|
706 |
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
|
707 |
// set the V4 option also |
f58832169add
8029607: Type of Service (TOS) cannot be set in IPv6 header
michaelm
parents:
23016
diff
changeset
|
708 |
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
|
709 |
} |
f58832169add
8029607: Type of Service (TOS) cannot be set in IPv6 header
michaelm
parents:
23016
diff
changeset
|
710 |
#endif |
2 | 711 |
} |
712 |
||
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
713 |
JNIEXPORT jint JNICALL |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
714 |
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
|
715 |
jint group, jint interf, jint source) |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
716 |
{ |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
717 |
struct ip_mreq mreq; |
22573
8f0344f13b7f
8032451: (dc) DatagramChannel.join should support include-mode filtering on OS X
alanb
parents:
18535
diff
changeset
|
718 |
struct ip_mreq_source mreq_source; |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
719 |
int opt, n, optlen; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
720 |
void* optval; |
2 | 721 |
|
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
722 |
if (source == 0) { |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
723 |
mreq.imr_multiaddr.s_addr = htonl(group); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
724 |
mreq.imr_interface.s_addr = htonl(interf); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
725 |
opt = (join) ? IP_ADD_MEMBERSHIP : IP_DROP_MEMBERSHIP; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
726 |
optval = (void*)&mreq; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
727 |
optlen = sizeof(mreq); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
728 |
} else { |
22597
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
18535
diff
changeset
|
729 |
|
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
18535
diff
changeset
|
730 |
#ifdef _AIX |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
18535
diff
changeset
|
731 |
/* 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
|
732 |
if (isSourceFilterSupported() != JNI_TRUE){ |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
18535
diff
changeset
|
733 |
return IOS_UNAVAILABLE; |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
18535
diff
changeset
|
734 |
} |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
18535
diff
changeset
|
735 |
#endif |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
18535
diff
changeset
|
736 |
|
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
737 |
mreq_source.imr_multiaddr.s_addr = htonl(group); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
738 |
mreq_source.imr_sourceaddr.s_addr = htonl(source); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
739 |
mreq_source.imr_interface.s_addr = htonl(interf); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
740 |
opt = (join) ? IP_ADD_SOURCE_MEMBERSHIP : IP_DROP_SOURCE_MEMBERSHIP; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
741 |
optval = (void*)&mreq_source; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
742 |
optlen = sizeof(mreq_source); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
743 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
744 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
745 |
n = setsockopt(fdval(env,fdo), IPPROTO_IP, opt, optval, optlen); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
746 |
if (n < 0) { |
22597
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
18535
diff
changeset
|
747 |
if (join && (errno == ENOPROTOOPT || errno == EOPNOTSUPP)) |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
748 |
return IOS_UNAVAILABLE; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
749 |
handleSocketError(env, errno); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
750 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
751 |
return 0; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
752 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
753 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
754 |
JNIEXPORT jint JNICALL |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
755 |
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
|
756 |
jint group, jint interf, jint source) |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
757 |
{ |
22573
8f0344f13b7f
8032451: (dc) DatagramChannel.join should support include-mode filtering on OS X
alanb
parents:
18535
diff
changeset
|
758 |
#ifdef __APPLE__ |
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
9035
diff
changeset
|
759 |
/* no IPv4 exclude-mode filtering for now */ |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
9035
diff
changeset
|
760 |
return IOS_UNAVAILABLE; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
9035
diff
changeset
|
761 |
#else |
22573
8f0344f13b7f
8032451: (dc) DatagramChannel.join should support include-mode filtering on OS X
alanb
parents:
18535
diff
changeset
|
762 |
struct ip_mreq_source mreq_source; |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
763 |
int n; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
764 |
int opt = (block) ? IP_BLOCK_SOURCE : IP_UNBLOCK_SOURCE; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
765 |
|
22597
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
18535
diff
changeset
|
766 |
#ifdef _AIX |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
18535
diff
changeset
|
767 |
/* 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
|
768 |
if (isSourceFilterSupported() != JNI_TRUE){ |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
18535
diff
changeset
|
769 |
return IOS_UNAVAILABLE; |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
18535
diff
changeset
|
770 |
} |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
18535
diff
changeset
|
771 |
#endif |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
18535
diff
changeset
|
772 |
|
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
773 |
mreq_source.imr_multiaddr.s_addr = htonl(group); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
774 |
mreq_source.imr_sourceaddr.s_addr = htonl(source); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
775 |
mreq_source.imr_interface.s_addr = htonl(interf); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
776 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
777 |
n = setsockopt(fdval(env,fdo), IPPROTO_IP, opt, |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
778 |
(void*)&mreq_source, sizeof(mreq_source)); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
779 |
if (n < 0) { |
22597
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
18535
diff
changeset
|
780 |
if (block && (errno == ENOPROTOOPT || errno == EOPNOTSUPP)) |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
781 |
return IOS_UNAVAILABLE; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
782 |
handleSocketError(env, errno); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
783 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
784 |
return 0; |
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
9035
diff
changeset
|
785 |
#endif |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
786 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
787 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
788 |
JNIEXPORT jint JNICALL |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
789 |
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
|
790 |
jbyteArray group, jint index, jbyteArray source) |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
791 |
{ |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
792 |
struct ipv6_mreq mreq6; |
22573
8f0344f13b7f
8032451: (dc) DatagramChannel.join should support include-mode filtering on OS X
alanb
parents:
18535
diff
changeset
|
793 |
struct group_source_req req; |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
794 |
int opt, n, optlen; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
795 |
void* optval; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
796 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
797 |
if (source == NULL) { |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
798 |
COPY_INET6_ADDRESS(env, group, (jbyte*)&(mreq6.ipv6mr_multiaddr)); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
799 |
mreq6.ipv6mr_interface = (int)index; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
800 |
opt = (join) ? IPV6_ADD_MEMBERSHIP : IPV6_DROP_MEMBERSHIP; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
801 |
optval = (void*)&mreq6; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
802 |
optlen = sizeof(mreq6); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
803 |
} else { |
22573
8f0344f13b7f
8032451: (dc) DatagramChannel.join should support include-mode filtering on OS X
alanb
parents:
18535
diff
changeset
|
804 |
#ifdef __APPLE__ |
13363
065e0e3545a3
6633549: (dc) Include-mode filtering of IPv6 sources does not block datagrams on Linux
alanb
parents:
12047
diff
changeset
|
805 |
/* no IPv6 include-mode filtering for now */ |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
806 |
return IOS_UNAVAILABLE; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
807 |
#else |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
808 |
initGroupSourceReq(env, group, index, source, &req); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
809 |
opt = (join) ? MCAST_JOIN_SOURCE_GROUP : MCAST_LEAVE_SOURCE_GROUP; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
810 |
optval = (void*)&req; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
811 |
optlen = sizeof(req); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
812 |
#endif |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
813 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
814 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
815 |
n = setsockopt(fdval(env,fdo), IPPROTO_IPV6, opt, optval, optlen); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
816 |
if (n < 0) { |
22597
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
18535
diff
changeset
|
817 |
if (join && (errno == ENOPROTOOPT || errno == EOPNOTSUPP)) |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
818 |
return IOS_UNAVAILABLE; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
819 |
handleSocketError(env, errno); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
820 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
821 |
return 0; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
822 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
823 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
824 |
JNIEXPORT jint JNICALL |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
825 |
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
|
826 |
jbyteArray group, jint index, jbyteArray source) |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
827 |
{ |
43889
212e765112d4
8174834: nio (ch): Remove #ifdef AF_INET6 guards in native coding
clanger
parents:
43100
diff
changeset
|
828 |
#ifdef __APPLE__ |
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
9035
diff
changeset
|
829 |
/* no IPv6 exclude-mode filtering for now */ |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
9035
diff
changeset
|
830 |
return IOS_UNAVAILABLE; |
43889
212e765112d4
8174834: nio (ch): Remove #ifdef AF_INET6 guards in native coding
clanger
parents:
43100
diff
changeset
|
831 |
#else |
22573
8f0344f13b7f
8032451: (dc) DatagramChannel.join should support include-mode filtering on OS X
alanb
parents:
18535
diff
changeset
|
832 |
struct group_source_req req; |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
833 |
int n; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
834 |
int opt = (block) ? MCAST_BLOCK_SOURCE : MCAST_UNBLOCK_SOURCE; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
835 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
836 |
initGroupSourceReq(env, group, index, source, &req); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
837 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
838 |
n = setsockopt(fdval(env,fdo), IPPROTO_IPV6, opt, |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
839 |
(void*)&req, sizeof(req)); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
840 |
if (n < 0) { |
22597
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
18535
diff
changeset
|
841 |
if (block && (errno == ENOPROTOOPT || errno == EOPNOTSUPP)) |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
842 |
return IOS_UNAVAILABLE; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
843 |
handleSocketError(env, errno); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
844 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
845 |
return 0; |
4814 | 846 |
#endif |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
847 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
848 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
849 |
JNIEXPORT void JNICALL |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
850 |
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
|
851 |
{ |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
852 |
struct in_addr in; |
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
9035
diff
changeset
|
853 |
socklen_t arglen = sizeof(struct in_addr); |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
854 |
int n; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
855 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
856 |
in.s_addr = htonl(interf); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
857 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
858 |
n = setsockopt(fdval(env, fdo), IPPROTO_IP, IP_MULTICAST_IF, |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
859 |
(void*)&(in.s_addr), arglen); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
860 |
if (n < 0) { |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
861 |
handleSocketError(env, errno); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
862 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
863 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
864 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
865 |
JNIEXPORT jint JNICALL |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
866 |
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
|
867 |
{ |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
868 |
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
|
869 |
socklen_t arglen = sizeof(struct in_addr); |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
870 |
int n; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
871 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
872 |
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
|
873 |
if (n < 0) { |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
874 |
handleSocketError(env, errno); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
875 |
return -1; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
876 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
877 |
return ntohl(in.s_addr); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
878 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
879 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
880 |
JNIEXPORT void JNICALL |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
881 |
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
|
882 |
{ |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
883 |
int value = (jint)index; |
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
9035
diff
changeset
|
884 |
socklen_t arglen = sizeof(value); |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
885 |
int n; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
886 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
887 |
n = setsockopt(fdval(env, fdo), IPPROTO_IPV6, IPV6_MULTICAST_IF, |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
888 |
(void*)&(index), arglen); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
889 |
if (n < 0) { |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
890 |
handleSocketError(env, errno); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
891 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
892 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
893 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
894 |
JNIEXPORT jint JNICALL |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
895 |
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
|
896 |
{ |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
897 |
int index; |
6850
56966b0a6a0d
6989466: Miscellaneous compiler warnings in java/lang, java/util, java/io, sun/misc native code
alanb
parents:
6299
diff
changeset
|
898 |
socklen_t arglen = sizeof(index); |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
899 |
int n; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
900 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
901 |
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
|
902 |
if (n < 0) { |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
903 |
handleSocketError(env, errno); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
904 |
return -1; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
905 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
906 |
return (jint)index; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
907 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
908 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
909 |
JNIEXPORT void JNICALL |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
910 |
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
|
911 |
{ |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
912 |
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
|
913 |
(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
|
914 |
if ((shutdown(fdval(env, fdo), how) < 0) && (errno != ENOTCONN)) |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
915 |
handleSocketError(env, errno); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
895
diff
changeset
|
916 |
} |
2 | 917 |
|
14025
fbebe005a3ee
7184932: Remove the temporary Selector usage in the NIO socket adapters
robm
parents:
13363
diff
changeset
|
918 |
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
|
919 |
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
|
920 |
{ |
6f02e036630e
8217461: (ch) Add Net.available to return the number of bytes in the socket input buffer
alanb
parents:
52073
diff
changeset
|
921 |
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
|
922 |
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
|
923 |
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
|
924 |
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
|
925 |
} |
6f02e036630e
8217461: (ch) Add Net.available to return the number of bytes in the socket input buffer
alanb
parents:
52073
diff
changeset
|
926 |
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
|
927 |
} |
6f02e036630e
8217461: (ch) Add Net.available to return the number of bytes in the socket input buffer
alanb
parents:
52073
diff
changeset
|
928 |
|
6f02e036630e
8217461: (ch) Add Net.available to return the number of bytes in the socket input buffer
alanb
parents:
52073
diff
changeset
|
929 |
JNIEXPORT jint JNICALL |
14025
fbebe005a3ee
7184932: Remove the temporary Selector usage in the NIO socket adapters
robm
parents:
13363
diff
changeset
|
930 |
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
|
931 |
{ |
fbebe005a3ee
7184932: Remove the temporary Selector usage in the NIO socket adapters
robm
parents:
13363
diff
changeset
|
932 |
struct pollfd pfd; |
fbebe005a3ee
7184932: Remove the temporary Selector usage in the NIO socket adapters
robm
parents:
13363
diff
changeset
|
933 |
int rv; |
fbebe005a3ee
7184932: Remove the temporary Selector usage in the NIO socket adapters
robm
parents:
13363
diff
changeset
|
934 |
pfd.fd = fdval(env, fdo); |
fbebe005a3ee
7184932: Remove the temporary Selector usage in the NIO socket adapters
robm
parents:
13363
diff
changeset
|
935 |
pfd.events = events; |
32014
262d30f45454
8132652: Java_sun_nio_ch_Net_poll passes a long to an int
bpb
parents:
32006
diff
changeset
|
936 |
if (timeout < -1) { |
262d30f45454
8132652: Java_sun_nio_ch_Net_poll passes a long to an int
bpb
parents:
32006
diff
changeset
|
937 |
timeout = -1; |
262d30f45454
8132652: Java_sun_nio_ch_Net_poll passes a long to an int
bpb
parents:
32006
diff
changeset
|
938 |
} else if (timeout > INT_MAX) { |
262d30f45454
8132652: Java_sun_nio_ch_Net_poll passes a long to an int
bpb
parents:
32006
diff
changeset
|
939 |
timeout = INT_MAX; |
262d30f45454
8132652: Java_sun_nio_ch_Net_poll passes a long to an int
bpb
parents:
32006
diff
changeset
|
940 |
} |
262d30f45454
8132652: Java_sun_nio_ch_Net_poll passes a long to an int
bpb
parents:
32006
diff
changeset
|
941 |
rv = poll(&pfd, 1, (int)timeout); |
14025
fbebe005a3ee
7184932: Remove the temporary Selector usage in the NIO socket adapters
robm
parents:
13363
diff
changeset
|
942 |
|
fbebe005a3ee
7184932: Remove the temporary Selector usage in the NIO socket adapters
robm
parents:
13363
diff
changeset
|
943 |
if (rv >= 0) { |
fbebe005a3ee
7184932: Remove the temporary Selector usage in the NIO socket adapters
robm
parents:
13363
diff
changeset
|
944 |
return pfd.revents; |
fbebe005a3ee
7184932: Remove the temporary Selector usage in the NIO socket adapters
robm
parents:
13363
diff
changeset
|
945 |
} else if (errno == EINTR) { |
49702
09c01737ad27
8201474: (so) Socket adaptor connect(InetAddress, timeout) succeeds when connection fails
alanb
parents:
49440
diff
changeset
|
946 |
// interrupted, no events to return |
09c01737ad27
8201474: (so) Socket adaptor connect(InetAddress, timeout) succeeds when connection fails
alanb
parents:
49440
diff
changeset
|
947 |
return 0; |
18535
71b74ae0ab8a
8014377: (dc) DatagramChannel should set IP_MULTICAST_ALL=0 (lnx)
alanb
parents:
18192
diff
changeset
|
948 |
} else { |
14025
fbebe005a3ee
7184932: Remove the temporary Selector usage in the NIO socket adapters
robm
parents:
13363
diff
changeset
|
949 |
handleSocketError(env, errno); |
fbebe005a3ee
7184932: Remove the temporary Selector usage in the NIO socket adapters
robm
parents:
13363
diff
changeset
|
950 |
return IOS_THROWN; |
fbebe005a3ee
7184932: Remove the temporary Selector usage in the NIO socket adapters
robm
parents:
13363
diff
changeset
|
951 |
} |
fbebe005a3ee
7184932: Remove the temporary Selector usage in the NIO socket adapters
robm
parents:
13363
diff
changeset
|
952 |
} |
fbebe005a3ee
7184932: Remove the temporary Selector usage in the NIO socket adapters
robm
parents:
13363
diff
changeset
|
953 |
|
54246
f04e3492fd88
8221252: (sc) SocketChannel and its socket adaptor need to handle connection reset
alanb
parents:
54154
diff
changeset
|
954 |
JNIEXPORT jboolean JNICALL |
53445
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
955 |
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
|
956 |
{ |
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
957 |
jint fd = fdval(env, fdo); |
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
958 |
struct pollfd poller; |
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
959 |
int result; |
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
960 |
|
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
961 |
poller.fd = fd; |
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
962 |
poller.events = POLLOUT; |
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
963 |
poller.revents = 0; |
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
964 |
if (timeout < -1) { |
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
965 |
timeout = -1; |
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
966 |
} else if (timeout > INT_MAX) { |
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
967 |
timeout = INT_MAX; |
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
968 |
} |
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
969 |
|
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
970 |
result = poll(&poller, 1, (int)timeout); |
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
971 |
|
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
972 |
if (result > 0) { |
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
973 |
int error = 0; |
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
974 |
socklen_t n = sizeof(int); |
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
975 |
errno = 0; |
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
976 |
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
|
977 |
if (result < 0) { |
54246
f04e3492fd88
8221252: (sc) SocketChannel and its socket adaptor need to handle connection reset
alanb
parents:
54154
diff
changeset
|
978 |
handleSocketError(env, errno); |
f04e3492fd88
8221252: (sc) SocketChannel and its socket adaptor need to handle connection reset
alanb
parents:
54154
diff
changeset
|
979 |
return JNI_FALSE; |
53445
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
980 |
} else if (error) { |
54246
f04e3492fd88
8221252: (sc) SocketChannel and its socket adaptor need to handle connection reset
alanb
parents:
54154
diff
changeset
|
981 |
handleSocketError(env, error); |
f04e3492fd88
8221252: (sc) SocketChannel and its socket adaptor need to handle connection reset
alanb
parents:
54154
diff
changeset
|
982 |
return JNI_FALSE; |
53445
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
983 |
} 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
|
984 |
handleSocketError(env, ENOTCONN); |
f04e3492fd88
8221252: (sc) SocketChannel and its socket adaptor need to handle connection reset
alanb
parents:
54154
diff
changeset
|
985 |
return JNI_FALSE; |
53445
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
986 |
} |
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
987 |
// connected |
54246
f04e3492fd88
8221252: (sc) SocketChannel and its socket adaptor need to handle connection reset
alanb
parents:
54154
diff
changeset
|
988 |
return JNI_TRUE; |
f04e3492fd88
8221252: (sc) SocketChannel and its socket adaptor need to handle connection reset
alanb
parents:
54154
diff
changeset
|
989 |
} else if (result == 0 || errno == EINTR) { |
f04e3492fd88
8221252: (sc) SocketChannel and its socket adaptor need to handle connection reset
alanb
parents:
54154
diff
changeset
|
990 |
return JNI_FALSE; |
53445
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
991 |
} else { |
54246
f04e3492fd88
8221252: (sc) SocketChannel and its socket adaptor need to handle connection reset
alanb
parents:
54154
diff
changeset
|
992 |
JNU_ThrowIOExceptionWithLastError(env, "poll failed"); |
f04e3492fd88
8221252: (sc) SocketChannel and its socket adaptor need to handle connection reset
alanb
parents:
54154
diff
changeset
|
993 |
return JNI_FALSE; |
53445
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
994 |
} |
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
995 |
} |
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
996 |
|
22604
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
22597
diff
changeset
|
997 |
JNIEXPORT jshort JNICALL |
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
22597
diff
changeset
|
998 |
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
|
999 |
{ |
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
22597
diff
changeset
|
1000 |
return (jshort)POLLIN; |
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
22597
diff
changeset
|
1001 |
} |
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
22597
diff
changeset
|
1002 |
|
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
22597
diff
changeset
|
1003 |
JNIEXPORT jshort JNICALL |
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
22597
diff
changeset
|
1004 |
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
|
1005 |
{ |
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
22597
diff
changeset
|
1006 |
return (jshort)POLLOUT; |
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
22597
diff
changeset
|
1007 |
} |
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
22597
diff
changeset
|
1008 |
|
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
22597
diff
changeset
|
1009 |
JNIEXPORT jshort JNICALL |
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
22597
diff
changeset
|
1010 |
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
|
1011 |
{ |
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
22597
diff
changeset
|
1012 |
return (jshort)POLLERR; |
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
22597
diff
changeset
|
1013 |
} |
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
22597
diff
changeset
|
1014 |
|
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
22597
diff
changeset
|
1015 |
JNIEXPORT jshort JNICALL |
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
22597
diff
changeset
|
1016 |
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
|
1017 |
{ |
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
22597
diff
changeset
|
1018 |
return (jshort)POLLHUP; |
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
22597
diff
changeset
|
1019 |
} |
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
22597
diff
changeset
|
1020 |
|
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
22597
diff
changeset
|
1021 |
JNIEXPORT jshort JNICALL |
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
22597
diff
changeset
|
1022 |
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
|
1023 |
{ |
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
22597
diff
changeset
|
1024 |
return (jshort)POLLNVAL; |
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
22597
diff
changeset
|
1025 |
} |
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
22597
diff
changeset
|
1026 |
|
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
22597
diff
changeset
|
1027 |
JNIEXPORT jshort JNICALL |
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
22597
diff
changeset
|
1028 |
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
|
1029 |
{ |
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
22597
diff
changeset
|
1030 |
return (jshort)POLLOUT; |
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
22597
diff
changeset
|
1031 |
} |
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
22597
diff
changeset
|
1032 |
|
53445
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
1033 |
JNIEXPORT jint JNICALL |
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
1034 |
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
|
1035 |
{ |
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
1036 |
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
|
1037 |
return convertReturnVal(env, n, JNI_FALSE); |
c96f9aa1f3d8
8217500: (sc) Move SocketChannelImpl's remaining native methods to Net
alanb
parents:
53422
diff
changeset
|
1038 |
} |
14025
fbebe005a3ee
7184932: Remove the temporary Selector usage in the NIO socket adapters
robm
parents:
13363
diff
changeset
|
1039 |
|
2 | 1040 |
/* Declared in nio_util.h */ |
1041 |
||
52073
1c8745e31fa3
8212000: Verify exported symbols in java.base (libnet, libnio/ch)
prappo
parents:
49702
diff
changeset
|
1042 |
jint handleSocketError(JNIEnv *env, jint errorValue) |
2 | 1043 |
{ |
1044 |
char *xn; |
|
1045 |
switch (errorValue) { |
|
1046 |
case EINPROGRESS: /* Non-blocking connect */ |
|
1047 |
return 0; |
|
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
9035
diff
changeset
|
1048 |
#ifdef EPROTO |
2 | 1049 |
case EPROTO: |
1050 |
xn = JNU_JAVANETPKG "ProtocolException"; |
|
1051 |
break; |
|
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
9035
diff
changeset
|
1052 |
#endif |
2 | 1053 |
case ECONNREFUSED: |
49141
ac95c7a76132
8198928: (so) SocketChannel connect may deadlock if closed at around same time that connect fails
alanb
parents:
47216
diff
changeset
|
1054 |
case ETIMEDOUT: |
ac95c7a76132
8198928: (so) SocketChannel connect may deadlock if closed at around same time that connect fails
alanb
parents:
47216
diff
changeset
|
1055 |
case ENOTCONN: |
2 | 1056 |
xn = JNU_JAVANETPKG "ConnectException"; |
1057 |
break; |
|
49141
ac95c7a76132
8198928: (so) SocketChannel connect may deadlock if closed at around same time that connect fails
alanb
parents:
47216
diff
changeset
|
1058 |
|
2 | 1059 |
case EHOSTUNREACH: |
1060 |
xn = JNU_JAVANETPKG "NoRouteToHostException"; |
|
1061 |
break; |
|
1062 |
case EADDRINUSE: /* Fall through */ |
|
1063 |
case EADDRNOTAVAIL: |
|
54154
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53445
diff
changeset
|
1064 |
case EACCES: |
2 | 1065 |
xn = JNU_JAVANETPKG "BindException"; |
1066 |
break; |
|
1067 |
default: |
|
1068 |
xn = JNU_JAVANETPKG "SocketException"; |
|
1069 |
break; |
|
1070 |
} |
|
1071 |
errno = errorValue; |
|
1072 |
JNU_ThrowByNameWithLastError(env, xn, "NioSocketError"); |
|
1073 |
return IOS_THROWN; |
|
1074 |
} |