author | chegar |
Fri, 18 Oct 2019 21:25:01 +0100 | |
branch | datagramsocketimpl-branch |
changeset 58697 | e3ff12d14d43 |
parent 57382 | 14e01d39c01a |
permissions | -rw-r--r-- |
2 | 1 |
/* |
53419
eac105e3ec13
8217451: ExtendedSocketOptions should encapsulate support for SO_FLOW_SLA
alanb
parents:
51642
diff
changeset
|
2 |
* Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
package sun.nio.ch; |
|
27 |
||
28 |
import java.io.FileDescriptor; |
|
29 |
import java.io.IOException; |
|
48750
ffbb784a8873
8196787: (ch) Moving network channels to use j.u.c locks
alanb
parents:
47216
diff
changeset
|
30 |
import java.net.InetSocketAddress; |
ffbb784a8873
8196787: (ch) Moving network channels to use j.u.c locks
alanb
parents:
47216
diff
changeset
|
31 |
import java.net.ServerSocket; |
ffbb784a8873
8196787: (ch) Moving network channels to use j.u.c locks
alanb
parents:
47216
diff
changeset
|
32 |
import java.net.SocketAddress; |
ffbb784a8873
8196787: (ch) Moving network channels to use j.u.c locks
alanb
parents:
47216
diff
changeset
|
33 |
import java.net.SocketOption; |
54620
13b67c1420b8
8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents:
54154
diff
changeset
|
34 |
import java.net.SocketTimeoutException; |
48750
ffbb784a8873
8196787: (ch) Moving network channels to use j.u.c locks
alanb
parents:
47216
diff
changeset
|
35 |
import java.net.StandardSocketOptions; |
ffbb784a8873
8196787: (ch) Moving network channels to use j.u.c locks
alanb
parents:
47216
diff
changeset
|
36 |
import java.nio.channels.AlreadyBoundException; |
49001
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
48761
diff
changeset
|
37 |
import java.nio.channels.AsynchronousCloseException; |
48750
ffbb784a8873
8196787: (ch) Moving network channels to use j.u.c locks
alanb
parents:
47216
diff
changeset
|
38 |
import java.nio.channels.ClosedChannelException; |
54620
13b67c1420b8
8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents:
54154
diff
changeset
|
39 |
import java.nio.channels.IllegalBlockingModeException; |
48750
ffbb784a8873
8196787: (ch) Moving network channels to use j.u.c locks
alanb
parents:
47216
diff
changeset
|
40 |
import java.nio.channels.NotYetBoundException; |
ffbb784a8873
8196787: (ch) Moving network channels to use j.u.c locks
alanb
parents:
47216
diff
changeset
|
41 |
import java.nio.channels.SelectionKey; |
ffbb784a8873
8196787: (ch) Moving network channels to use j.u.c locks
alanb
parents:
47216
diff
changeset
|
42 |
import java.nio.channels.ServerSocketChannel; |
ffbb784a8873
8196787: (ch) Moving network channels to use j.u.c locks
alanb
parents:
47216
diff
changeset
|
43 |
import java.nio.channels.SocketChannel; |
ffbb784a8873
8196787: (ch) Moving network channels to use j.u.c locks
alanb
parents:
47216
diff
changeset
|
44 |
import java.nio.channels.spi.SelectorProvider; |
ffbb784a8873
8196787: (ch) Moving network channels to use j.u.c locks
alanb
parents:
47216
diff
changeset
|
45 |
import java.util.Collections; |
ffbb784a8873
8196787: (ch) Moving network channels to use j.u.c locks
alanb
parents:
47216
diff
changeset
|
46 |
import java.util.HashSet; |
49001
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
48761
diff
changeset
|
47 |
import java.util.Objects; |
48750
ffbb784a8873
8196787: (ch) Moving network channels to use j.u.c locks
alanb
parents:
47216
diff
changeset
|
48 |
import java.util.Set; |
ffbb784a8873
8196787: (ch) Moving network channels to use j.u.c locks
alanb
parents:
47216
diff
changeset
|
49 |
import java.util.concurrent.locks.ReentrantLock; |
ffbb784a8873
8196787: (ch) Moving network channels to use j.u.c locks
alanb
parents:
47216
diff
changeset
|
50 |
|
2446 | 51 |
import sun.net.NetHooks; |
50303
7164c3bb55df
8194298: Add support for per Socket configuration of TCP keepalive
vtewari
parents:
49702
diff
changeset
|
52 |
import sun.net.ext.ExtendedSocketOptions; |
2 | 53 |
|
54 |
/** |
|
55 |
* An implementation of ServerSocketChannels |
|
56 |
*/ |
|
57 |
||
58 |
class ServerSocketChannelImpl |
|
59 |
extends ServerSocketChannel |
|
60 |
implements SelChImpl |
|
61 |
{ |
|
62 |
// Used to make native close and configure calls |
|
54154
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53419
diff
changeset
|
63 |
private static final NativeDispatcher nd = new SocketDispatcher(); |
2 | 64 |
|
65 |
// Our file descriptor |
|
66 |
private final FileDescriptor fd; |
|
48761 | 67 |
private final int fdVal; |
2 | 68 |
|
49001
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
48761
diff
changeset
|
69 |
// Lock held by thread currently blocked on this channel |
48750
ffbb784a8873
8196787: (ch) Moving network channels to use j.u.c locks
alanb
parents:
47216
diff
changeset
|
70 |
private final ReentrantLock acceptLock = new ReentrantLock(); |
2 | 71 |
|
72 |
// Lock held by any thread that modifies the state fields declared below |
|
73 |
// DO NOT invoke a blocking I/O operation while holding this lock! |
|
54754
193a8f1a4f3b
8223353: (ch) Change channel close implementation to not wait for I/O threads
alanb
parents:
54620
diff
changeset
|
74 |
private final Object stateLock = new Object(); |
2 | 75 |
|
76 |
// -- The following fields are protected by stateLock |
|
77 |
||
78 |
// Channel state, increases monotonically |
|
79 |
private static final int ST_INUSE = 0; |
|
49001
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
48761
diff
changeset
|
80 |
private static final int ST_CLOSING = 1; |
54754
193a8f1a4f3b
8223353: (ch) Change channel close implementation to not wait for I/O threads
alanb
parents:
54620
diff
changeset
|
81 |
private static final int ST_CLOSED = 2; |
49001
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
48761
diff
changeset
|
82 |
private int state; |
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
48761
diff
changeset
|
83 |
|
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
48761
diff
changeset
|
84 |
// ID of native thread currently blocked in this channel, for signalling |
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
48761
diff
changeset
|
85 |
private long thread; |
2 | 86 |
|
87 |
// Binding |
|
18212
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
18192
diff
changeset
|
88 |
private InetSocketAddress localAddress; // null => unbound |
2 | 89 |
|
18192 | 90 |
// set true when exclusive binding is on and SO_REUSEADDR is emulated |
91 |
private boolean isReuseAddress; |
|
92 |
||
2 | 93 |
// Our socket adaptor, if any |
48750
ffbb784a8873
8196787: (ch) Moving network channels to use j.u.c locks
alanb
parents:
47216
diff
changeset
|
94 |
private ServerSocket socket; |
2 | 95 |
|
96 |
// -- End of fields protected by stateLock |
|
97 |
||
98 |
||
54620
13b67c1420b8
8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents:
54154
diff
changeset
|
99 |
ServerSocketChannelImpl(SelectorProvider sp) { |
2 | 100 |
super(sp); |
54154
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53419
diff
changeset
|
101 |
this.fd = Net.serverSocket(true); |
2 | 102 |
this.fdVal = IOUtil.fdVal(fd); |
103 |
} |
|
104 |
||
49001
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
48761
diff
changeset
|
105 |
ServerSocketChannelImpl(SelectorProvider sp, FileDescriptor fd, boolean bound) |
2 | 106 |
throws IOException |
107 |
{ |
|
108 |
super(sp); |
|
109 |
this.fd = fd; |
|
110 |
this.fdVal = IOUtil.fdVal(fd); |
|
49001
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
48761
diff
changeset
|
111 |
if (bound) { |
54754
193a8f1a4f3b
8223353: (ch) Change channel close implementation to not wait for I/O threads
alanb
parents:
54620
diff
changeset
|
112 |
synchronized (stateLock) { |
49001
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
48761
diff
changeset
|
113 |
localAddress = Net.localAddress(fd); |
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
48761
diff
changeset
|
114 |
} |
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
48761
diff
changeset
|
115 |
} |
2 | 116 |
} |
117 |
||
49001
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
48761
diff
changeset
|
118 |
// @throws ClosedChannelException if channel is closed |
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
48761
diff
changeset
|
119 |
private void ensureOpen() throws ClosedChannelException { |
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
48761
diff
changeset
|
120 |
if (!isOpen()) |
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
48761
diff
changeset
|
121 |
throw new ClosedChannelException(); |
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
48761
diff
changeset
|
122 |
} |
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
48761
diff
changeset
|
123 |
|
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
48761
diff
changeset
|
124 |
@Override |
2 | 125 |
public ServerSocket socket() { |
54754
193a8f1a4f3b
8223353: (ch) Change channel close implementation to not wait for I/O threads
alanb
parents:
54620
diff
changeset
|
126 |
synchronized (stateLock) { |
2 | 127 |
if (socket == null) |
128 |
socket = ServerSocketAdaptor.create(this); |
|
129 |
return socket; |
|
130 |
} |
|
131 |
} |
|
132 |
||
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
133 |
@Override |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
134 |
public SocketAddress getLocalAddress() throws IOException { |
54754
193a8f1a4f3b
8223353: (ch) Change channel close implementation to not wait for I/O threads
alanb
parents:
54620
diff
changeset
|
135 |
synchronized (stateLock) { |
49001
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
48761
diff
changeset
|
136 |
ensureOpen(); |
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
48761
diff
changeset
|
137 |
return (localAddress == null) |
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
48761
diff
changeset
|
138 |
? null |
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
48761
diff
changeset
|
139 |
: Net.getRevealedLocalAddress(localAddress); |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
140 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
141 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
142 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
143 |
@Override |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
1247
diff
changeset
|
144 |
public <T> ServerSocketChannel setOption(SocketOption<T> name, T value) |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
145 |
throws IOException |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
146 |
{ |
49001
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
48761
diff
changeset
|
147 |
Objects.requireNonNull(name); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
1247
diff
changeset
|
148 |
if (!supportedOptions().contains(name)) |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
1247
diff
changeset
|
149 |
throw new UnsupportedOperationException("'" + name + "' not supported"); |
55081
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54754
diff
changeset
|
150 |
if (!name.type().isInstance(value)) |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54754
diff
changeset
|
151 |
throw new IllegalArgumentException("Invalid value '" + value + "'"); |
dd321e3596c0
8224477: java.net socket types new-style socket option methods - spec and impl mismatch
chegar
parents:
54754
diff
changeset
|
152 |
|
54754
193a8f1a4f3b
8223353: (ch) Change channel close implementation to not wait for I/O threads
alanb
parents:
54620
diff
changeset
|
153 |
synchronized (stateLock) { |
49001
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
48761
diff
changeset
|
154 |
ensureOpen(); |
25170
f58832169add
8029607: Type of Service (TOS) cannot be set in IPv6 header
michaelm
parents:
24969
diff
changeset
|
155 |
|
49001
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
48761
diff
changeset
|
156 |
if (name == StandardSocketOptions.SO_REUSEADDR && Net.useExclusiveBind()) { |
18192 | 157 |
// SO_REUSEADDR emulated when using exclusive bind |
158 |
isReuseAddress = (Boolean)value; |
|
159 |
} else { |
|
160 |
// no options that require special handling |
|
161 |
Net.setSocketOption(fd, Net.UNSPEC, name, value); |
|
162 |
} |
|
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
163 |
return this; |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
164 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
165 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
166 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
167 |
@Override |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
168 |
@SuppressWarnings("unchecked") |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
169 |
public <T> T getOption(SocketOption<T> name) |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
170 |
throws IOException |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
171 |
{ |
49001
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
48761
diff
changeset
|
172 |
Objects.requireNonNull(name); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
1247
diff
changeset
|
173 |
if (!supportedOptions().contains(name)) |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
1247
diff
changeset
|
174 |
throw new UnsupportedOperationException("'" + name + "' not supported"); |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
175 |
|
54754
193a8f1a4f3b
8223353: (ch) Change channel close implementation to not wait for I/O threads
alanb
parents:
54620
diff
changeset
|
176 |
synchronized (stateLock) { |
49001
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
48761
diff
changeset
|
177 |
ensureOpen(); |
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
48761
diff
changeset
|
178 |
if (name == StandardSocketOptions.SO_REUSEADDR && Net.useExclusiveBind()) { |
18192 | 179 |
// SO_REUSEADDR emulated when using exclusive bind |
180 |
return (T)Boolean.valueOf(isReuseAddress); |
|
181 |
} |
|
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
182 |
// no options that require special handling |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
183 |
return (T) Net.getSocketOption(fd, Net.UNSPEC, name); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
184 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
185 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
186 |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
1247
diff
changeset
|
187 |
private static class DefaultOptionsHolder { |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
188 |
static final Set<SocketOption<?>> defaultOptions = defaultOptions(); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
189 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
190 |
private static Set<SocketOption<?>> defaultOptions() { |
49001
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
48761
diff
changeset
|
191 |
HashSet<SocketOption<?>> set = new HashSet<>(); |
9679
d98ae8bc45fc
7042979: Rename StandardSocketOption and StandardWatchEventKind
alanb
parents:
7668
diff
changeset
|
192 |
set.add(StandardSocketOptions.SO_RCVBUF); |
d98ae8bc45fc
7042979: Rename StandardSocketOption and StandardWatchEventKind
alanb
parents:
7668
diff
changeset
|
193 |
set.add(StandardSocketOptions.SO_REUSEADDR); |
36115 | 194 |
if (Net.isReusePortAvailable()) { |
195 |
set.add(StandardSocketOptions.SO_REUSEPORT); |
|
196 |
} |
|
53419
eac105e3ec13
8217451: ExtendedSocketOptions should encapsulate support for SO_FLOW_SLA
alanb
parents:
51642
diff
changeset
|
197 |
set.addAll(ExtendedSocketOptions.serverSocketOptions()); |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
198 |
return Collections.unmodifiableSet(set); |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
199 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
200 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
201 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
202 |
@Override |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
1247
diff
changeset
|
203 |
public final Set<SocketOption<?>> supportedOptions() { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
1247
diff
changeset
|
204 |
return DefaultOptionsHolder.defaultOptions; |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
205 |
} |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
206 |
|
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
207 |
@Override |
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
208 |
public ServerSocketChannel bind(SocketAddress local, int backlog) throws IOException { |
54754
193a8f1a4f3b
8223353: (ch) Change channel close implementation to not wait for I/O threads
alanb
parents:
54620
diff
changeset
|
209 |
synchronized (stateLock) { |
49290 | 210 |
ensureOpen(); |
211 |
if (localAddress != null) |
|
212 |
throw new AlreadyBoundException(); |
|
213 |
InetSocketAddress isa = (local == null) |
|
214 |
? new InetSocketAddress(0) |
|
215 |
: Net.checkAddress(local); |
|
216 |
SecurityManager sm = System.getSecurityManager(); |
|
217 |
if (sm != null) |
|
218 |
sm.checkListen(isa.getPort()); |
|
219 |
NetHooks.beforeTcpBind(fd, isa.getAddress(), isa.getPort()); |
|
220 |
Net.bind(fd, isa.getAddress(), isa.getPort()); |
|
221 |
Net.listen(fd, backlog < 1 ? 50 : backlog); |
|
222 |
localAddress = Net.localAddress(fd); |
|
2 | 223 |
} |
1152
29d6145d1097
4640544: New I/O: Complete socket-channel functionality
alanb
parents:
2
diff
changeset
|
224 |
return this; |
2 | 225 |
} |
226 |
||
49001
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
48761
diff
changeset
|
227 |
/** |
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
48761
diff
changeset
|
228 |
* Marks the beginning of an I/O operation that might block. |
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
48761
diff
changeset
|
229 |
* |
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
48761
diff
changeset
|
230 |
* @throws ClosedChannelException if the channel is closed |
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
48761
diff
changeset
|
231 |
* @throws NotYetBoundException if the channel's socket has not been bound yet |
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
48761
diff
changeset
|
232 |
*/ |
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
48761
diff
changeset
|
233 |
private void begin(boolean blocking) throws ClosedChannelException { |
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
48761
diff
changeset
|
234 |
if (blocking) |
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
48761
diff
changeset
|
235 |
begin(); // set blocker to close channel if interrupted |
54754
193a8f1a4f3b
8223353: (ch) Change channel close implementation to not wait for I/O threads
alanb
parents:
54620
diff
changeset
|
236 |
synchronized (stateLock) { |
49001
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
48761
diff
changeset
|
237 |
ensureOpen(); |
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
48761
diff
changeset
|
238 |
if (localAddress == null) |
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
48761
diff
changeset
|
239 |
throw new NotYetBoundException(); |
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
48761
diff
changeset
|
240 |
if (blocking) |
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
48761
diff
changeset
|
241 |
thread = NativeThread.current(); |
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
48761
diff
changeset
|
242 |
} |
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
48761
diff
changeset
|
243 |
} |
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
48761
diff
changeset
|
244 |
|
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
48761
diff
changeset
|
245 |
/** |
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
48761
diff
changeset
|
246 |
* Marks the end of an I/O operation that may have blocked. |
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
48761
diff
changeset
|
247 |
* |
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
48761
diff
changeset
|
248 |
* @throws AsynchronousCloseException if the channel was closed due to this |
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
48761
diff
changeset
|
249 |
* thread being interrupted on a blocking I/O operation. |
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
48761
diff
changeset
|
250 |
*/ |
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
48761
diff
changeset
|
251 |
private void end(boolean blocking, boolean completed) |
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
48761
diff
changeset
|
252 |
throws AsynchronousCloseException |
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
48761
diff
changeset
|
253 |
{ |
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
48761
diff
changeset
|
254 |
if (blocking) { |
54754
193a8f1a4f3b
8223353: (ch) Change channel close implementation to not wait for I/O threads
alanb
parents:
54620
diff
changeset
|
255 |
synchronized (stateLock) { |
49001
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
48761
diff
changeset
|
256 |
thread = 0; |
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
48761
diff
changeset
|
257 |
if (state == ST_CLOSING) { |
54754
193a8f1a4f3b
8223353: (ch) Change channel close implementation to not wait for I/O threads
alanb
parents:
54620
diff
changeset
|
258 |
tryFinishClose(); |
49001
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
48761
diff
changeset
|
259 |
} |
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
48761
diff
changeset
|
260 |
} |
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
48761
diff
changeset
|
261 |
end(completed); |
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
48761
diff
changeset
|
262 |
} |
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
48761
diff
changeset
|
263 |
} |
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
48761
diff
changeset
|
264 |
|
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
48761
diff
changeset
|
265 |
@Override |
2 | 266 |
public SocketChannel accept() throws IOException { |
54154
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53419
diff
changeset
|
267 |
int n = 0; |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53419
diff
changeset
|
268 |
FileDescriptor newfd = new FileDescriptor(); |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53419
diff
changeset
|
269 |
InetSocketAddress[] isaa = new InetSocketAddress[1]; |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53419
diff
changeset
|
270 |
|
48750
ffbb784a8873
8196787: (ch) Moving network channels to use j.u.c locks
alanb
parents:
47216
diff
changeset
|
271 |
acceptLock.lock(); |
ffbb784a8873
8196787: (ch) Moving network channels to use j.u.c locks
alanb
parents:
47216
diff
changeset
|
272 |
try { |
49001
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
48761
diff
changeset
|
273 |
boolean blocking = isBlocking(); |
2 | 274 |
try { |
49001
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
48761
diff
changeset
|
275 |
begin(blocking); |
54620
13b67c1420b8
8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents:
54154
diff
changeset
|
276 |
n = Net.accept(this.fd, newfd, isaa); |
13b67c1420b8
8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents:
54154
diff
changeset
|
277 |
if (blocking) { |
13b67c1420b8
8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents:
54154
diff
changeset
|
278 |
while (IOStatus.okayToRetry(n) && isOpen()) { |
13b67c1420b8
8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents:
54154
diff
changeset
|
279 |
park(Net.POLLIN); |
13b67c1420b8
8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents:
54154
diff
changeset
|
280 |
n = Net.accept(this.fd, newfd, isaa); |
13b67c1420b8
8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents:
54154
diff
changeset
|
281 |
} |
13b67c1420b8
8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents:
54154
diff
changeset
|
282 |
} |
2 | 283 |
} finally { |
49001
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
48761
diff
changeset
|
284 |
end(blocking, n > 0); |
2 | 285 |
assert IOStatus.check(n); |
286 |
} |
|
54154
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53419
diff
changeset
|
287 |
} finally { |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53419
diff
changeset
|
288 |
acceptLock.unlock(); |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53419
diff
changeset
|
289 |
} |
2 | 290 |
|
54620
13b67c1420b8
8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents:
54154
diff
changeset
|
291 |
if (n > 0) { |
13b67c1420b8
8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents:
54154
diff
changeset
|
292 |
return finishAccept(newfd, isaa[0]); |
13b67c1420b8
8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents:
54154
diff
changeset
|
293 |
} else { |
54154
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53419
diff
changeset
|
294 |
return null; |
54620
13b67c1420b8
8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents:
54154
diff
changeset
|
295 |
} |
13b67c1420b8
8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents:
54154
diff
changeset
|
296 |
} |
54154
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53419
diff
changeset
|
297 |
|
54620
13b67c1420b8
8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents:
54154
diff
changeset
|
298 |
/** |
13b67c1420b8
8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents:
54154
diff
changeset
|
299 |
* Accepts a new connection with a given timeout. This method requires the |
13b67c1420b8
8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents:
54154
diff
changeset
|
300 |
* channel to be configured in blocking mode. |
13b67c1420b8
8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents:
54154
diff
changeset
|
301 |
* |
13b67c1420b8
8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents:
54154
diff
changeset
|
302 |
* @apiNote This method is for use by the socket adaptor. |
13b67c1420b8
8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents:
54154
diff
changeset
|
303 |
* |
13b67c1420b8
8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents:
54154
diff
changeset
|
304 |
* @param nanos the timeout, in nanoseconds |
13b67c1420b8
8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents:
54154
diff
changeset
|
305 |
* @throws IllegalBlockingModeException if the channel is configured non-blocking |
13b67c1420b8
8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents:
54154
diff
changeset
|
306 |
* @throws SocketTimeoutException if the timeout expires |
13b67c1420b8
8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents:
54154
diff
changeset
|
307 |
*/ |
13b67c1420b8
8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents:
54154
diff
changeset
|
308 |
SocketChannel blockingAccept(long nanos) throws IOException { |
13b67c1420b8
8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents:
54154
diff
changeset
|
309 |
int n = 0; |
13b67c1420b8
8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents:
54154
diff
changeset
|
310 |
FileDescriptor newfd = new FileDescriptor(); |
13b67c1420b8
8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents:
54154
diff
changeset
|
311 |
InetSocketAddress[] isaa = new InetSocketAddress[1]; |
13b67c1420b8
8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents:
54154
diff
changeset
|
312 |
|
13b67c1420b8
8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents:
54154
diff
changeset
|
313 |
acceptLock.lock(); |
13b67c1420b8
8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents:
54154
diff
changeset
|
314 |
try { |
13b67c1420b8
8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents:
54154
diff
changeset
|
315 |
// check that channel is configured blocking |
13b67c1420b8
8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents:
54154
diff
changeset
|
316 |
if (!isBlocking()) |
13b67c1420b8
8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents:
54154
diff
changeset
|
317 |
throw new IllegalBlockingModeException(); |
13b67c1420b8
8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents:
54154
diff
changeset
|
318 |
|
13b67c1420b8
8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents:
54154
diff
changeset
|
319 |
try { |
13b67c1420b8
8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents:
54154
diff
changeset
|
320 |
begin(true); |
13b67c1420b8
8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents:
54154
diff
changeset
|
321 |
// change socket to non-blocking |
13b67c1420b8
8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents:
54154
diff
changeset
|
322 |
lockedConfigureBlocking(false); |
13b67c1420b8
8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents:
54154
diff
changeset
|
323 |
try { |
13b67c1420b8
8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents:
54154
diff
changeset
|
324 |
long startNanos = System.nanoTime(); |
13b67c1420b8
8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents:
54154
diff
changeset
|
325 |
n = Net.accept(fd, newfd, isaa); |
13b67c1420b8
8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents:
54154
diff
changeset
|
326 |
while (n == IOStatus.UNAVAILABLE && isOpen()) { |
13b67c1420b8
8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents:
54154
diff
changeset
|
327 |
long remainingNanos = nanos - (System.nanoTime() - startNanos); |
13b67c1420b8
8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents:
54154
diff
changeset
|
328 |
if (remainingNanos <= 0) { |
13b67c1420b8
8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents:
54154
diff
changeset
|
329 |
throw new SocketTimeoutException("Accept timed out"); |
13b67c1420b8
8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents:
54154
diff
changeset
|
330 |
} |
13b67c1420b8
8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents:
54154
diff
changeset
|
331 |
park(Net.POLLIN, remainingNanos); |
13b67c1420b8
8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents:
54154
diff
changeset
|
332 |
n = Net.accept(fd, newfd, isaa); |
13b67c1420b8
8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents:
54154
diff
changeset
|
333 |
} |
13b67c1420b8
8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents:
54154
diff
changeset
|
334 |
} finally { |
13b67c1420b8
8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents:
54154
diff
changeset
|
335 |
// restore socket to blocking mode |
13b67c1420b8
8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents:
54154
diff
changeset
|
336 |
lockedConfigureBlocking(true); |
13b67c1420b8
8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents:
54154
diff
changeset
|
337 |
} |
13b67c1420b8
8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents:
54154
diff
changeset
|
338 |
} finally { |
13b67c1420b8
8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents:
54154
diff
changeset
|
339 |
end(true, n > 0); |
13b67c1420b8
8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents:
54154
diff
changeset
|
340 |
} |
13b67c1420b8
8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents:
54154
diff
changeset
|
341 |
} finally { |
13b67c1420b8
8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents:
54154
diff
changeset
|
342 |
acceptLock.unlock(); |
13b67c1420b8
8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents:
54154
diff
changeset
|
343 |
} |
13b67c1420b8
8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents:
54154
diff
changeset
|
344 |
|
13b67c1420b8
8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents:
54154
diff
changeset
|
345 |
assert n > 0; |
13b67c1420b8
8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents:
54154
diff
changeset
|
346 |
return finishAccept(newfd, isaa[0]); |
13b67c1420b8
8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents:
54154
diff
changeset
|
347 |
} |
13b67c1420b8
8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents:
54154
diff
changeset
|
348 |
|
13b67c1420b8
8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents:
54154
diff
changeset
|
349 |
private SocketChannel finishAccept(FileDescriptor newfd, InetSocketAddress isa) |
13b67c1420b8
8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents:
54154
diff
changeset
|
350 |
throws IOException |
13b67c1420b8
8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents:
54154
diff
changeset
|
351 |
{ |
54154
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53419
diff
changeset
|
352 |
try { |
49001
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
48761
diff
changeset
|
353 |
// newly accepted socket is initially in blocking mode |
2 | 354 |
IOUtil.configureBlocking(newfd, true); |
49001
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
48761
diff
changeset
|
355 |
|
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
48761
diff
changeset
|
356 |
// check permitted to accept connections from the remote address |
2 | 357 |
SecurityManager sm = System.getSecurityManager(); |
358 |
if (sm != null) { |
|
54154
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53419
diff
changeset
|
359 |
sm.checkAccept(isa.getAddress().getHostAddress(), isa.getPort()); |
2 | 360 |
} |
54154
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53419
diff
changeset
|
361 |
return new SocketChannelImpl(provider(), newfd, isa); |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53419
diff
changeset
|
362 |
} catch (Exception e) { |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53419
diff
changeset
|
363 |
nd.close(newfd); |
1caf2daef7cf
8220738: (sc) Move ServerSocketChannelImpl remaining native method to Net
alanb
parents:
53419
diff
changeset
|
364 |
throw e; |
2 | 365 |
} |
366 |
} |
|
367 |
||
49001
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
48761
diff
changeset
|
368 |
@Override |
2 | 369 |
protected void implConfigureBlocking(boolean block) throws IOException { |
49001
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
48761
diff
changeset
|
370 |
acceptLock.lock(); |
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
48761
diff
changeset
|
371 |
try { |
54620
13b67c1420b8
8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents:
54154
diff
changeset
|
372 |
lockedConfigureBlocking(block); |
49001
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
48761
diff
changeset
|
373 |
} finally { |
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
48761
diff
changeset
|
374 |
acceptLock.unlock(); |
2 | 375 |
} |
376 |
} |
|
377 |
||
49001
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
48761
diff
changeset
|
378 |
/** |
54620
13b67c1420b8
8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents:
54154
diff
changeset
|
379 |
* Adjust the blocking mode while holding acceptLock. |
13b67c1420b8
8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents:
54154
diff
changeset
|
380 |
*/ |
13b67c1420b8
8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents:
54154
diff
changeset
|
381 |
private void lockedConfigureBlocking(boolean block) throws IOException { |
13b67c1420b8
8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents:
54154
diff
changeset
|
382 |
assert acceptLock.isHeldByCurrentThread(); |
54754
193a8f1a4f3b
8223353: (ch) Change channel close implementation to not wait for I/O threads
alanb
parents:
54620
diff
changeset
|
383 |
synchronized (stateLock) { |
54620
13b67c1420b8
8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents:
54154
diff
changeset
|
384 |
ensureOpen(); |
13b67c1420b8
8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents:
54154
diff
changeset
|
385 |
IOUtil.configureBlocking(fd, block); |
54754
193a8f1a4f3b
8223353: (ch) Change channel close implementation to not wait for I/O threads
alanb
parents:
54620
diff
changeset
|
386 |
} |
193a8f1a4f3b
8223353: (ch) Change channel close implementation to not wait for I/O threads
alanb
parents:
54620
diff
changeset
|
387 |
} |
193a8f1a4f3b
8223353: (ch) Change channel close implementation to not wait for I/O threads
alanb
parents:
54620
diff
changeset
|
388 |
|
193a8f1a4f3b
8223353: (ch) Change channel close implementation to not wait for I/O threads
alanb
parents:
54620
diff
changeset
|
389 |
/** |
193a8f1a4f3b
8223353: (ch) Change channel close implementation to not wait for I/O threads
alanb
parents:
54620
diff
changeset
|
390 |
* Closes the socket if there are no accept in progress and the channel is |
193a8f1a4f3b
8223353: (ch) Change channel close implementation to not wait for I/O threads
alanb
parents:
54620
diff
changeset
|
391 |
* not registered with a Selector. |
193a8f1a4f3b
8223353: (ch) Change channel close implementation to not wait for I/O threads
alanb
parents:
54620
diff
changeset
|
392 |
*/ |
193a8f1a4f3b
8223353: (ch) Change channel close implementation to not wait for I/O threads
alanb
parents:
54620
diff
changeset
|
393 |
private boolean tryClose() throws IOException { |
193a8f1a4f3b
8223353: (ch) Change channel close implementation to not wait for I/O threads
alanb
parents:
54620
diff
changeset
|
394 |
assert Thread.holdsLock(stateLock) && state == ST_CLOSING; |
193a8f1a4f3b
8223353: (ch) Change channel close implementation to not wait for I/O threads
alanb
parents:
54620
diff
changeset
|
395 |
if ((thread == 0) && !isRegistered()) { |
193a8f1a4f3b
8223353: (ch) Change channel close implementation to not wait for I/O threads
alanb
parents:
54620
diff
changeset
|
396 |
state = ST_CLOSED; |
193a8f1a4f3b
8223353: (ch) Change channel close implementation to not wait for I/O threads
alanb
parents:
54620
diff
changeset
|
397 |
nd.close(fd); |
193a8f1a4f3b
8223353: (ch) Change channel close implementation to not wait for I/O threads
alanb
parents:
54620
diff
changeset
|
398 |
return true; |
193a8f1a4f3b
8223353: (ch) Change channel close implementation to not wait for I/O threads
alanb
parents:
54620
diff
changeset
|
399 |
} else { |
193a8f1a4f3b
8223353: (ch) Change channel close implementation to not wait for I/O threads
alanb
parents:
54620
diff
changeset
|
400 |
return false; |
193a8f1a4f3b
8223353: (ch) Change channel close implementation to not wait for I/O threads
alanb
parents:
54620
diff
changeset
|
401 |
} |
193a8f1a4f3b
8223353: (ch) Change channel close implementation to not wait for I/O threads
alanb
parents:
54620
diff
changeset
|
402 |
} |
193a8f1a4f3b
8223353: (ch) Change channel close implementation to not wait for I/O threads
alanb
parents:
54620
diff
changeset
|
403 |
|
193a8f1a4f3b
8223353: (ch) Change channel close implementation to not wait for I/O threads
alanb
parents:
54620
diff
changeset
|
404 |
/** |
193a8f1a4f3b
8223353: (ch) Change channel close implementation to not wait for I/O threads
alanb
parents:
54620
diff
changeset
|
405 |
* Invokes tryClose to attempt to close the socket. |
193a8f1a4f3b
8223353: (ch) Change channel close implementation to not wait for I/O threads
alanb
parents:
54620
diff
changeset
|
406 |
* |
193a8f1a4f3b
8223353: (ch) Change channel close implementation to not wait for I/O threads
alanb
parents:
54620
diff
changeset
|
407 |
* This method is used for deferred closing by I/O and Selector operations. |
193a8f1a4f3b
8223353: (ch) Change channel close implementation to not wait for I/O threads
alanb
parents:
54620
diff
changeset
|
408 |
*/ |
193a8f1a4f3b
8223353: (ch) Change channel close implementation to not wait for I/O threads
alanb
parents:
54620
diff
changeset
|
409 |
private void tryFinishClose() { |
193a8f1a4f3b
8223353: (ch) Change channel close implementation to not wait for I/O threads
alanb
parents:
54620
diff
changeset
|
410 |
try { |
193a8f1a4f3b
8223353: (ch) Change channel close implementation to not wait for I/O threads
alanb
parents:
54620
diff
changeset
|
411 |
tryClose(); |
193a8f1a4f3b
8223353: (ch) Change channel close implementation to not wait for I/O threads
alanb
parents:
54620
diff
changeset
|
412 |
} catch (IOException ignore) { } |
193a8f1a4f3b
8223353: (ch) Change channel close implementation to not wait for I/O threads
alanb
parents:
54620
diff
changeset
|
413 |
} |
193a8f1a4f3b
8223353: (ch) Change channel close implementation to not wait for I/O threads
alanb
parents:
54620
diff
changeset
|
414 |
|
193a8f1a4f3b
8223353: (ch) Change channel close implementation to not wait for I/O threads
alanb
parents:
54620
diff
changeset
|
415 |
/** |
193a8f1a4f3b
8223353: (ch) Change channel close implementation to not wait for I/O threads
alanb
parents:
54620
diff
changeset
|
416 |
* Closes this channel when configured in blocking mode. |
193a8f1a4f3b
8223353: (ch) Change channel close implementation to not wait for I/O threads
alanb
parents:
54620
diff
changeset
|
417 |
* |
193a8f1a4f3b
8223353: (ch) Change channel close implementation to not wait for I/O threads
alanb
parents:
54620
diff
changeset
|
418 |
* If there is an accept in progress then the socket is pre-closed and the |
193a8f1a4f3b
8223353: (ch) Change channel close implementation to not wait for I/O threads
alanb
parents:
54620
diff
changeset
|
419 |
* accept thread is signalled, in which case the final close is deferred |
193a8f1a4f3b
8223353: (ch) Change channel close implementation to not wait for I/O threads
alanb
parents:
54620
diff
changeset
|
420 |
* until the accept aborts. |
193a8f1a4f3b
8223353: (ch) Change channel close implementation to not wait for I/O threads
alanb
parents:
54620
diff
changeset
|
421 |
*/ |
193a8f1a4f3b
8223353: (ch) Change channel close implementation to not wait for I/O threads
alanb
parents:
54620
diff
changeset
|
422 |
private void implCloseBlockingMode() throws IOException { |
193a8f1a4f3b
8223353: (ch) Change channel close implementation to not wait for I/O threads
alanb
parents:
54620
diff
changeset
|
423 |
synchronized (stateLock) { |
193a8f1a4f3b
8223353: (ch) Change channel close implementation to not wait for I/O threads
alanb
parents:
54620
diff
changeset
|
424 |
assert state < ST_CLOSING; |
193a8f1a4f3b
8223353: (ch) Change channel close implementation to not wait for I/O threads
alanb
parents:
54620
diff
changeset
|
425 |
state = ST_CLOSING; |
193a8f1a4f3b
8223353: (ch) Change channel close implementation to not wait for I/O threads
alanb
parents:
54620
diff
changeset
|
426 |
if (!tryClose()) { |
193a8f1a4f3b
8223353: (ch) Change channel close implementation to not wait for I/O threads
alanb
parents:
54620
diff
changeset
|
427 |
long th = thread; |
193a8f1a4f3b
8223353: (ch) Change channel close implementation to not wait for I/O threads
alanb
parents:
54620
diff
changeset
|
428 |
if (th != 0) { |
193a8f1a4f3b
8223353: (ch) Change channel close implementation to not wait for I/O threads
alanb
parents:
54620
diff
changeset
|
429 |
nd.preClose(fd); |
193a8f1a4f3b
8223353: (ch) Change channel close implementation to not wait for I/O threads
alanb
parents:
54620
diff
changeset
|
430 |
NativeThread.signal(th); |
193a8f1a4f3b
8223353: (ch) Change channel close implementation to not wait for I/O threads
alanb
parents:
54620
diff
changeset
|
431 |
} |
193a8f1a4f3b
8223353: (ch) Change channel close implementation to not wait for I/O threads
alanb
parents:
54620
diff
changeset
|
432 |
} |
193a8f1a4f3b
8223353: (ch) Change channel close implementation to not wait for I/O threads
alanb
parents:
54620
diff
changeset
|
433 |
} |
193a8f1a4f3b
8223353: (ch) Change channel close implementation to not wait for I/O threads
alanb
parents:
54620
diff
changeset
|
434 |
} |
193a8f1a4f3b
8223353: (ch) Change channel close implementation to not wait for I/O threads
alanb
parents:
54620
diff
changeset
|
435 |
|
193a8f1a4f3b
8223353: (ch) Change channel close implementation to not wait for I/O threads
alanb
parents:
54620
diff
changeset
|
436 |
/** |
193a8f1a4f3b
8223353: (ch) Change channel close implementation to not wait for I/O threads
alanb
parents:
54620
diff
changeset
|
437 |
* Closes this channel when configured in non-blocking mode. |
193a8f1a4f3b
8223353: (ch) Change channel close implementation to not wait for I/O threads
alanb
parents:
54620
diff
changeset
|
438 |
* |
193a8f1a4f3b
8223353: (ch) Change channel close implementation to not wait for I/O threads
alanb
parents:
54620
diff
changeset
|
439 |
* If the channel is registered with a Selector then the close is deferred |
193a8f1a4f3b
8223353: (ch) Change channel close implementation to not wait for I/O threads
alanb
parents:
54620
diff
changeset
|
440 |
* until the channel is flushed from all Selectors. |
193a8f1a4f3b
8223353: (ch) Change channel close implementation to not wait for I/O threads
alanb
parents:
54620
diff
changeset
|
441 |
*/ |
193a8f1a4f3b
8223353: (ch) Change channel close implementation to not wait for I/O threads
alanb
parents:
54620
diff
changeset
|
442 |
private void implCloseNonBlockingMode() throws IOException { |
193a8f1a4f3b
8223353: (ch) Change channel close implementation to not wait for I/O threads
alanb
parents:
54620
diff
changeset
|
443 |
synchronized (stateLock) { |
193a8f1a4f3b
8223353: (ch) Change channel close implementation to not wait for I/O threads
alanb
parents:
54620
diff
changeset
|
444 |
assert state < ST_CLOSING; |
193a8f1a4f3b
8223353: (ch) Change channel close implementation to not wait for I/O threads
alanb
parents:
54620
diff
changeset
|
445 |
state = ST_CLOSING; |
193a8f1a4f3b
8223353: (ch) Change channel close implementation to not wait for I/O threads
alanb
parents:
54620
diff
changeset
|
446 |
} |
193a8f1a4f3b
8223353: (ch) Change channel close implementation to not wait for I/O threads
alanb
parents:
54620
diff
changeset
|
447 |
// wait for any accept to complete before trying to close |
193a8f1a4f3b
8223353: (ch) Change channel close implementation to not wait for I/O threads
alanb
parents:
54620
diff
changeset
|
448 |
acceptLock.lock(); |
193a8f1a4f3b
8223353: (ch) Change channel close implementation to not wait for I/O threads
alanb
parents:
54620
diff
changeset
|
449 |
acceptLock.unlock(); |
193a8f1a4f3b
8223353: (ch) Change channel close implementation to not wait for I/O threads
alanb
parents:
54620
diff
changeset
|
450 |
synchronized (stateLock) { |
193a8f1a4f3b
8223353: (ch) Change channel close implementation to not wait for I/O threads
alanb
parents:
54620
diff
changeset
|
451 |
if (state == ST_CLOSING) { |
193a8f1a4f3b
8223353: (ch) Change channel close implementation to not wait for I/O threads
alanb
parents:
54620
diff
changeset
|
452 |
tryClose(); |
193a8f1a4f3b
8223353: (ch) Change channel close implementation to not wait for I/O threads
alanb
parents:
54620
diff
changeset
|
453 |
} |
54620
13b67c1420b8
8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents:
54154
diff
changeset
|
454 |
} |
13b67c1420b8
8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents:
54154
diff
changeset
|
455 |
} |
13b67c1420b8
8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents:
54154
diff
changeset
|
456 |
|
13b67c1420b8
8222774: (ch) Replace uses of stateLock and blockingLock with j.u.c. locks
alanb
parents:
54154
diff
changeset
|
457 |
/** |
49001
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
48761
diff
changeset
|
458 |
* Invoked by implCloseChannel to close the channel. |
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
48761
diff
changeset
|
459 |
*/ |
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
48761
diff
changeset
|
460 |
@Override |
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
48761
diff
changeset
|
461 |
protected void implCloseSelectableChannel() throws IOException { |
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
48761
diff
changeset
|
462 |
assert !isOpen(); |
54754
193a8f1a4f3b
8223353: (ch) Change channel close implementation to not wait for I/O threads
alanb
parents:
54620
diff
changeset
|
463 |
if (isBlocking()) { |
193a8f1a4f3b
8223353: (ch) Change channel close implementation to not wait for I/O threads
alanb
parents:
54620
diff
changeset
|
464 |
implCloseBlockingMode(); |
193a8f1a4f3b
8223353: (ch) Change channel close implementation to not wait for I/O threads
alanb
parents:
54620
diff
changeset
|
465 |
} else { |
193a8f1a4f3b
8223353: (ch) Change channel close implementation to not wait for I/O threads
alanb
parents:
54620
diff
changeset
|
466 |
implCloseNonBlockingMode(); |
49001
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
48761
diff
changeset
|
467 |
} |
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
48761
diff
changeset
|
468 |
} |
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
48761
diff
changeset
|
469 |
|
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
48761
diff
changeset
|
470 |
@Override |
54754
193a8f1a4f3b
8223353: (ch) Change channel close implementation to not wait for I/O threads
alanb
parents:
54620
diff
changeset
|
471 |
public void kill() { |
193a8f1a4f3b
8223353: (ch) Change channel close implementation to not wait for I/O threads
alanb
parents:
54620
diff
changeset
|
472 |
synchronized (stateLock) { |
193a8f1a4f3b
8223353: (ch) Change channel close implementation to not wait for I/O threads
alanb
parents:
54620
diff
changeset
|
473 |
if (state == ST_CLOSING) { |
193a8f1a4f3b
8223353: (ch) Change channel close implementation to not wait for I/O threads
alanb
parents:
54620
diff
changeset
|
474 |
tryFinishClose(); |
2 | 475 |
} |
49001
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
48761
diff
changeset
|
476 |
} |
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
48761
diff
changeset
|
477 |
} |
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
48761
diff
changeset
|
478 |
|
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
48761
diff
changeset
|
479 |
/** |
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
48761
diff
changeset
|
480 |
* Returns true if channel's socket is bound |
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
48761
diff
changeset
|
481 |
*/ |
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
48761
diff
changeset
|
482 |
boolean isBound() { |
54754
193a8f1a4f3b
8223353: (ch) Change channel close implementation to not wait for I/O threads
alanb
parents:
54620
diff
changeset
|
483 |
synchronized (stateLock) { |
49001
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
48761
diff
changeset
|
484 |
return localAddress != null; |
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
48761
diff
changeset
|
485 |
} |
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
48761
diff
changeset
|
486 |
} |
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
48761
diff
changeset
|
487 |
|
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
48761
diff
changeset
|
488 |
/** |
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
48761
diff
changeset
|
489 |
* Returns the local address, or null if not bound |
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
48761
diff
changeset
|
490 |
*/ |
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
48761
diff
changeset
|
491 |
InetSocketAddress localAddress() { |
54754
193a8f1a4f3b
8223353: (ch) Change channel close implementation to not wait for I/O threads
alanb
parents:
54620
diff
changeset
|
492 |
synchronized (stateLock) { |
49001
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
48761
diff
changeset
|
493 |
return localAddress; |
2 | 494 |
} |
495 |
} |
|
496 |
||
497 |
/** |
|
498 |
* Translates native poll revent set into a ready operation set |
|
499 |
*/ |
|
49493 | 500 |
public boolean translateReadyOps(int ops, int initialOps, SelectionKeyImpl ski) { |
501 |
int intOps = ski.nioInterestOps(); |
|
502 |
int oldOps = ski.nioReadyOps(); |
|
2 | 503 |
int newOps = initialOps; |
504 |
||
22604
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
19607
diff
changeset
|
505 |
if ((ops & Net.POLLNVAL) != 0) { |
2 | 506 |
// This should only happen if this channel is pre-closed while a |
507 |
// selection operation is in progress |
|
508 |
// ## Throw an error if this channel has not been pre-closed |
|
509 |
return false; |
|
510 |
} |
|
511 |
||
22604
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
19607
diff
changeset
|
512 |
if ((ops & (Net.POLLERR | Net.POLLHUP)) != 0) { |
2 | 513 |
newOps = intOps; |
49493 | 514 |
ski.nioReadyOps(newOps); |
2 | 515 |
return (newOps & ~oldOps) != 0; |
516 |
} |
|
517 |
||
22604
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
19607
diff
changeset
|
518 |
if (((ops & Net.POLLIN) != 0) && |
2 | 519 |
((intOps & SelectionKey.OP_ACCEPT) != 0)) |
520 |
newOps |= SelectionKey.OP_ACCEPT; |
|
521 |
||
49493 | 522 |
ski.nioReadyOps(newOps); |
2 | 523 |
return (newOps & ~oldOps) != 0; |
524 |
} |
|
525 |
||
49493 | 526 |
public boolean translateAndUpdateReadyOps(int ops, SelectionKeyImpl ski) { |
527 |
return translateReadyOps(ops, ski.nioReadyOps(), ski); |
|
2 | 528 |
} |
529 |
||
49493 | 530 |
public boolean translateAndSetReadyOps(int ops, SelectionKeyImpl ski) { |
531 |
return translateReadyOps(ops, 0, ski); |
|
2 | 532 |
} |
533 |
||
534 |
/** |
|
535 |
* Translates an interest operation set into a native poll event set |
|
536 |
*/ |
|
49493 | 537 |
public int translateInterestOps(int ops) { |
2 | 538 |
int newOps = 0; |
539 |
if ((ops & SelectionKey.OP_ACCEPT) != 0) |
|
22604
9b394795e216
8031997: PPC64: Make the various POLL constants system dependant
simonis
parents:
19607
diff
changeset
|
540 |
newOps |= Net.POLLIN; |
49493 | 541 |
return newOps; |
2 | 542 |
} |
543 |
||
544 |
public FileDescriptor getFD() { |
|
545 |
return fd; |
|
546 |
} |
|
547 |
||
548 |
public int getFDVal() { |
|
549 |
return fdVal; |
|
550 |
} |
|
551 |
||
552 |
public String toString() { |
|
24969
afa6934dd8e8
8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents:
23010
diff
changeset
|
553 |
StringBuilder sb = new StringBuilder(); |
2 | 554 |
sb.append(this.getClass().getName()); |
555 |
sb.append('['); |
|
18212
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
18192
diff
changeset
|
556 |
if (!isOpen()) { |
2 | 557 |
sb.append("closed"); |
18212
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
18192
diff
changeset
|
558 |
} else { |
54754
193a8f1a4f3b
8223353: (ch) Change channel close implementation to not wait for I/O threads
alanb
parents:
54620
diff
changeset
|
559 |
synchronized (stateLock) { |
49001
ce06058197a4
8198562: (ch) Separate blocking and non-blocking code paths (part 1)
alanb
parents:
48761
diff
changeset
|
560 |
InetSocketAddress addr = localAddress; |
18212
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
18192
diff
changeset
|
561 |
if (addr == null) { |
2 | 562 |
sb.append("unbound"); |
563 |
} else { |
|
18212
22f8c33b0690
8001318: Socket.getLocalAddress not consistent with InetAddress.getLocalHost
khazra
parents:
18192
diff
changeset
|
564 |
sb.append(Net.getRevealedLocalAddressAsString(addr)); |
2 | 565 |
} |
566 |
} |
|
567 |
} |
|
568 |
sb.append(']'); |
|
569 |
return sb.toString(); |
|
570 |
} |
|
571 |
} |